Last active
May 2, 2018 14:38
-
-
Save thomaslevesque/d16c2141fccfb06c78f6 to your computer and use it in GitHub Desktop.
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
// 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