Created
September 22, 2014 19:55
-
-
Save yousefamar/2fc2b3884d104f745eb3 to your computer and use it in GitHub Desktop.
A short script, written for a HackThisSite.org programming mission, that takes 10 scrambled inputs, searches for anagrams for them in a text file, and outputs them
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
import os | |
import sys | |
words = [] | |
answers = ['']*10 | |
print "Enter 10 scrambled terms." | |
for i in range(10): | |
words.append(raw_input().strip()) | |
with open("wordlist.txt") as f: | |
flines = f.readlines() | |
for line in flines: | |
line = line.strip() | |
for i,word in enumerate(words): | |
match = True | |
tempWord = word[:] | |
for c in line: | |
if not c in tempWord: | |
match = False | |
break | |
tempWord = tempWord.replace(c, "", 1) | |
tempLine = line[:] | |
for c in word: | |
if not c in tempLine: | |
match = False | |
break | |
tempLine = tempLine.replace(c, "", 1) | |
if match: | |
answers[i] = line | |
for ans in answers: | |
sys.stdout.write(ans+',') | |
raw_input("\nPress enter to quit...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment