Created
August 15, 2012 04:34
-
-
Save kghose/3355901 to your computer and use it in GitHub Desktop.
pyboy4000 - your companion to the pipboy3000 for all your hacking needs.
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
#!python | |
"""pyboy4000 - your companion to the pipboy3000 for all your hacking needs. | |
Simply fireup pyboy, enter all the choice words, then, as you try a word in the | |
terminal during hacking, enter the number of correct letters for each word tried. | |
pyboy will do the thinking for you. It will tell you if it has found a match, or | |
it will suggest the next word to try. | |
The algorithm used is as follows: | |
Keep a list of candidate words. In the beginning this is the whole list. | |
When a word is tried and the number of correct letters is obtained, remove all words in the candidate list whose count of position sensitive common letters with the tested word is different from the number of correct letters. Repeat. | |
""" | |
def test_list(): | |
wl = ['dangers', 'sending', 'central', 'hunters', 'resides', 'believe', 'venture', 'pattern', 'gangers', 'mention', 'cutters', 'canteen', 'cancers', 'beliefs', 'banning', 'minigun', 'cistern'] | |
return wl | |
def enter_list(): | |
print 'Enter the choice words' | |
print 'x - to finish' | |
print 'd - to reenter the last word' | |
word_list = [] | |
while True: | |
print_list(word_list) | |
word = raw_input('Enter next choice word: ') | |
if word is 'x': | |
break; | |
if word is 'd': | |
word_list.pop() | |
else: | |
word_list.append(word) | |
return word_list | |
def print_list(word_list): | |
print '|=============================|' | |
for n,w in enumerate(word_list): | |
print ' ', n, w | |
print '|=============================|' | |
def eliminate(wl, sl, no): | |
test_word = wl[sl] | |
for w in list(wl): | |
matching = 0 | |
for l1,l2 in zip(w, test_word): #For each letter in test word | |
if l1 == l2: | |
matching += 1 | |
if matching is not no: | |
wl.remove(w) | |
return wl | |
wl = enter_list() | |
#wl = test_list() | |
print 'For each word you try, first enter the serial number of the word, and then enter how many letters are correct' | |
while True: | |
print 'Candidate words are' | |
print_list(wl) | |
sl = int(raw_input('Serial number of word tried (-1 to end): ')) | |
if sl == -1: | |
break | |
no = int(raw_input('Number of letters correct: ')) | |
wl = eliminate(wl, sl, no) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment