Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import string, copy
- """hacksolve.py solves the time-sinking hacking minigame in Fallout 3.
- Hopefully it does so in less time than doing it by hand. This
- solution is by no means guaranteed to be eloquent or efficient. TBH,
- I'd be really happy if it just worked. """
- class Pass:
- """Pass holds all relevant data for potential passwords"""
- def __init__(self):
- self.word = ""
- self.num_matches = 0
- def main():
- word = "bloop"
- curr_pass = Pass()
- p_list = []
- print ("Enter words, enter to end")
- while word != "":
- word = raw_input(">")
- if (word != ""):
- curr_pass.word = word
- p_list.append(copy.copy(curr_pass))
- for i in range(4):
- best_choice = get_best(p_list)
- print ("Choose: " + best_choice.word)
- num_matches = int(raw_input("How many characters were correct? " + \
- "(-1 for exact match) "))
- if (num_matches == -1):
- print ("I'm a fucking warlock.")
- exit(1)
- p_list = remove_passes(p_list, best_choice, num_matches)
- print ("I die without honour")
- def get_best(p_list):
- """returns the best choice"""
- max_matches = 0
- best_match = Pass()
- for curr_pass in p_list:
- curr_pass.num_matches = 0
- for other_pass in p_list:
- if curr_pass.word != other_pass.word:
- for i in range(len(curr_pass.word)):
- if curr_pass.word[i] == other_pass.word[i]:
- curr_pass.num_matches += 1
- if curr_pass.num_matches >= max_matches:
- best_match = curr_pass
- max_matches = curr_pass.num_matches
- return best_match
- def remove_passes(p_list, best_choice, num_matches):
- """Removes potential passwords that don't work"""
- new_list = []
- curr_matches = 0
- print (best_choice.word)
- for curr_pass in p_list:
- curr_pass.num_matches = 0
- for i in range(len(curr_pass.word)):
- if curr_pass.word[i] == best_choice.word[i]:
- curr_pass.num_matches += 1
- if curr_pass.num_matches == num_matches:
- new_list.append(copy.copy(curr_pass))
- return new_list
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement