about summary refs log tree commit diff
path: root/lib/Extensions.cs
blob: 52863d00293abe3947bd5e40db7fed187c3aeac7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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));
        }
    }
}