Created
November 24, 2015 02:50
-
-
Save imbstack/5250e106f971c5888513 to your computer and use it in GitHub Desktop.
wordsearch solver
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
#!/usr/bin/env python3 | |
def find(puzzle, dir): | |
count = 0 | |
for line in puzzle: | |
for word in words: | |
if word in line: | |
count += 1 | |
print(dir, word) | |
return count | |
if __name__ == '__main__': | |
wordlist = '/usr/share/dict/words' | |
words = [x.lower().strip() for x in open(wordlist, 'r').readlines() if len(x) > 3] | |
lr_puzzle = [x.lower().strip().replace(' ', '') for x in open('./puzzle.txt', 'r').readlines()] | |
rl_puzzle = [x[::-1] for x in lr_puzzle] | |
ud_puzzle = [''.join(x) for x in zip(*lr_puzzle)] | |
du_puzzle = [x[::-1] for x in ud_puzzle] | |
total = 0 | |
total += find(lr_puzzle, '→') | |
total += find(rl_puzzle, '←') | |
total += find(ud_puzzle, '↓') | |
total += find(du_puzzle, '↑') | |
print(total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment