using System.Diagnostics; namespace aoc2019; public static class Extensions { public static IEnumerable> Permute(this IEnumerable list) { if (list.Count() == 1) return new[] { list }; return list.SelectMany(t => Permute(list.Where(x => !x!.Equals(t))), (v, p) => p.Prepend(v)); } public static IEnumerable Chunk(this string str, int chunkSize) { for (var i = 0; i < str.Length; i += chunkSize) yield return str.Substring(i, chunkSize); } public static string ToDelimitedString(this IEnumerable enumerable, string delimiter = "") { return string.Join(delimiter, enumerable); } public static IEnumerable Repeat(this IEnumerable sequence, int? count = null) { while (count == null || count-- > 0) foreach (var item in sequence) yield return item; } /// /// increased accuracy for stopwatch based on frequency. /// /// blog /// details here /// /// /// /// public static double ScaleMilliseconds(this Stopwatch stopwatch) { return 1_000 * stopwatch.ElapsedTicks / (double)Stopwatch.Frequency; } }