Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import string, copy
  4.  
  5. """hacksolve.py solves the time-sinking hacking minigame in Fallout 3.
  6.   Hopefully it does so in less time than doing it by hand.  This
  7.   solution is by no means guaranteed to be eloquent or efficient. TBH,
  8.   I'd be really happy if it just worked. """
  9.  
  10.  
  11. class Pass:
  12.     """Pass holds all relevant data for potential passwords"""
  13.    
  14.     def __init__(self):
  15.         self.word = ""
  16.         self.num_matches = 0
  17.        
  18. def main():
  19.    
  20.     word = "bloop"
  21.     curr_pass = Pass()
  22.     p_list = []
  23.    
  24.     print ("Enter words, enter to end")
  25.    
  26.     while word != "":
  27.         word = raw_input(">")
  28.         if (word != ""):
  29.             curr_pass.word = word
  30.         p_list.append(copy.copy(curr_pass))
  31.    
  32.     for i in range(4)
  33.         best_choice = get_best(p_list)
  34.         print ("Choose: " + best_choice.word)
  35.         num_matches = int(raw_input("How many characters were correct? " + \
  36.             "(-1 for exact match) "))
  37.         if (num_matches == -1):
  38.             print ("I'm a fucking warlock.")
  39.             exit(1)
  40.         p_list = remove_passes(p_list, best_choice, num_matches)
  41.    
  42.     print ("I die without honour")
  43.        
  44. def get_best(p_list):
  45.    
  46.     """returns the best choice"""
  47.    
  48.     max_matches = 0
  49.     best_match = Pass()
  50.    
  51.     for curr_pass in p_list:
  52.         curr_pass.num_matches = 0
  53.         for other_pass in p_list:
  54.             if curr_pass.word != other_pass.word:
  55.                 for i in range(len(curr_pass.word)):
  56.                     if curr_pass.word[i] == other_pass.word[i]:
  57.                         curr_pass.num_matches += 1
  58.                        
  59.         if curr_pass.num_matches >= max_matches:
  60.             best_match = curr_pass
  61.             max_matches = curr_pass.num_matches
  62.    
  63.     return best_match
  64.    
  65. def remove_passes(p_list, best_choice, num_matches):
  66.     """Removes potential passwords that don't work"""
  67.    
  68.     new_list = []
  69.     curr_matches = 0
  70.    
  71.     print (best_choice.word)
  72.    
  73.     for curr_pass in p_list:
  74.         curr_pass.num_matches = 0
  75.         for i in range(len(curr_pass.word)):
  76.             if curr_pass.word[i] == best_choice.word[i]:
  77.                 curr_pass.num_matches += 1
  78.        
  79.         if curr_pass.num_matches == num_matches:
  80.             new_list.append(copy.copy(curr_pass))
  81.            
  82.     return new_list
  83.    
  84. if __name__ == "__main__":
  85.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement