diff options
Diffstat (limited to 'lib/Extensions.cs')
-rw-r--r-- | lib/Extensions.cs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Extensions.cs b/lib/Extensions.cs new file mode 100644 index 0000000..52863d0 --- /dev/null +++ b/lib/Extensions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace aoc2019.lib +{ + public static class Extensions + { + public static IEnumerable<IEnumerable<T>> Permute<T>(this IEnumerable<T> list) + { + if (list.Count() == 1) return new[] { list }; + return list.SelectMany(t => Permute(list.Where(x => !x.Equals(t))), (v, p) => p.Prepend(v)); + } + } +} |