Skip to content

Instantly share code, notes, and snippets.

@thomaslevesque
Last active May 2, 2018 14:38
Show Gist options
  • Save thomaslevesque/d16c2141fccfb06c78f6 to your computer and use it in GitHub Desktop.
Save thomaslevesque/d16c2141fccfb06c78f6 to your computer and use it in GitHub Desktop.
// Solution for James Michael Hare's anagram challenge (http://geekswithblogs.net/BlackRabbitCoder/archive/2015/07/28/little-puzzlersndashlist-all-anagrams-for-a-word.aspx)
// Run in LinqPad, adding a reference to Microsoft.Experimental.Collections
void Main()
{
string path = @"D:\tmp\words.txt";
var dict = new MultiValueDictionary<string, string>();
foreach (var word in File.ReadLines(path))
{
dict.Add(new string(word.OrderBy(c => c).ToArray()), word);
}
string input = Console.ReadLine();
var anagrams = dict[new string(input.OrderBy(c => c).ToArray())];
anagrams.Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment