Created
January 4, 2012 23:36
-
-
Save simoneb/1562857 to your computer and use it in GitHub Desktop.
Anagrams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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