Skip to content

Instantly share code, notes, and snippets.

@fujieda
Created February 11, 2019 07:49
Show Gist options
  • Select an option

  • Save fujieda/560061ab9fb2b7df8524a5da33c76021 to your computer and use it in GitHub Desktop.

Select an option

Save fujieda/560061ab9fb2b7df8524a5da33c76021 to your computer and use it in GitHub Desktop.
// https://fujieda.mit-license.org/
static IEnumerable<IEnumerable<T>> Permutation<T>(T[] items)
{
return items.Length == 1
? new[] {items}
: items.SelectMany(item =>
Permutation(items.Where(x => !x.Equals(item)).ToArray())
.Select(perms => new[] {item}.Concat(perms)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment