Skip to content

Instantly share code, notes, and snippets.

@yousefamar
Created September 22, 2014 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yousefamar/2fc2b3884d104f745eb3 to your computer and use it in GitHub Desktop.
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
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