Created
April 15, 2012 04:53
-
-
Save andersonimes/2390144 to your computer and use it in GitHub Desktop.
Anagram finder in C# (Mono)
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
public static void Main (string[] args) | |
{ | |
var words = System.IO.File.ReadAllLines("/usr/share/dict/words"); | |
var anagramLookup = words.ToLookup(MakeAnagramKey); | |
var anagrams = anagramLookup[MakeAnagramKey("pots")]; | |
Console.WriteLine(string.Join(Environment.NewLine, anagrams.ToArray())); | |
} | |
static string MakeAnagramKey (string w) | |
{ | |
return new string(w.OrderBy(c => c).ToArray()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment