Last active
December 21, 2015 02:38
-
-
Save zmagg/6235901 to your computer and use it in GitHub Desktop.
hacker school mini improvised contest for the fastest solution to find what words are the longest anagrams of each other (single words, please, no phrases) in the sowpods scrabble dictionary.
This file contains hidden or 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
f = open("sowpods.txt", "r") | |
canonized_words = {} | |
word1 = "" | |
word2 = "" | |
max_len = 0 | |
for line in f: | |
if len(line) > max_len: | |
sorted_word = ''.join(sorted(line)) | |
if sorted_word in canonized_words: | |
found_word = canonized_words[sorted_word] | |
word1 = line | |
word2 = found_word | |
max_len = len(word1) | |
else: | |
canonized_words[sorted_word] = line | |
print word1 + ", " + word2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool! Now I wanna look at the problem :-}
Real is the clock time spent solving the problem (actual time passed between start and finish)
User is the processor time spent in user mode (not in the kernel) -- if your process runs on more than one CPU at once this can actually be greater than real time.
Sys is the CPU time spent in the application not in user mode -- also can be greater than real if running on more than one CPU -- examples of this are time spent in syscalls, or when in the kernel doing work on behalf of the process.