Skip to content

Instantly share code, notes, and snippets.

@simoneb
Created January 4, 2012 23:36
Show Gist options
  • Save simoneb/1562857 to your computer and use it in GitHub Desktop.
Save simoneb/1562857 to your computer and use it in GitHub Desktop.
Anagrams
IEnumerable<string> Anagrams(IEnumerable<char> input)
{
foreach (var c in input)
{
var except = input.Except(new[]{c});
if(except.Any())
foreach (var element in Anagrams(except))
yield return c.ToString() + element;
else
yield return c.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment