using System.Collections.Generic;
using System.Linq;

namespace QC.QSPR;

public class Permutation
{
	public static IEnumerable<IEnumerable<T>> Permute<T>(IEnumerable<T> list)
	{
		if (list.Count() == 1)
		{
			List<IEnumerable<T>> list2 = new List<IEnumerable<T>>();
			list2.Add(list);
			return list2;
		}
		return list.Select((T VALUE1, int i) => from VALUE2 in Permute(list.Where((T VALUE2, int j) => j != i))
			select new List<T> { VALUE1 }.Union(VALUE2)).SelectMany((IEnumerable<IEnumerable<T>> VALUE3) => VALUE3);
	}
}
