Skip to content

Instantly share code, notes, and snippets.

@loisaidasam
Created December 3, 2012 19:47
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 loisaidasam/4197457 to your computer and use it in GitHub Desktop.
Save loisaidasam/4197457 to your computer and use it in GitHub Desktop.
JUMBLE solver
'''Script for solving those pesky newspaper jumbles
Sample usage:
$ python jumble_solver.py SWARLP
sprawl
'''
import random
import sys
def jumble(word):
used = []
while len(used) != len(word):
pos = random.randint(0, len(word)-1)
if pos not in used:
used.append(pos)
result = ''
for i in used:
result += word[i]
return result
def solve(word):
fp = open('/usr/share/dict/words', 'r')
words = fp.read()
fp.close()
words = words.split("\n")
word = word.lower()
while True:
j = jumble(word)
if j in words:
return j
def main():
word = sys.argv[1]
print solve(word)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment