Skip to content

Instantly share code, notes, and snippets.

@andersonimes
Created April 15, 2012 04:53
Show Gist options
  • Save andersonimes/2390144 to your computer and use it in GitHub Desktop.
Save andersonimes/2390144 to your computer and use it in GitHub Desktop.
Anagram finder in C# (Mono)
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