Advertisement
Guest User

darts

a guest
Nov 17th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. def all_turns():
  2.     turns = []
  3.     for a in ashots:
  4.         for b in ashots:
  5.             for c in ashots:
  6.                 turns.append([a, b, c])
  7.     turns.remove([0, 0, 0]) # avoid inf. scenarios
  8.     return turns
  9.  
  10. def end_turns():
  11.     turns = []
  12.     for a in ashots:
  13.         for b in ashots:
  14.             for c in eshots:
  15.                 turns.append([a, b, c])
  16.         for b in eshots:
  17.             turns.append([a, b])
  18.     for a in eshots:
  19.         turns.append([a])
  20.     return turns
  21.  
  22. def end_shots():
  23.     shots = {50}
  24.     for i in range(1, 21):
  25.         shots.add(i)
  26.     return shots
  27.  
  28. def all_shots():
  29.     shots = {0, 25, 50}
  30.     for i in range(1, 21):
  31.         shots.add(i)
  32.         shots.add(i*2)
  33.         shots.add(i*3)
  34.     return shots
  35.  
  36. ashots = all_shots()
  37. eshots = end_shots()
  38. aturns = all_turns()
  39. eturns = end_turns()
  40. max_score = 300
  41.  
  42. def find_backtrack():
  43.     from_turn([])
  44.  
  45. def from_turn(turn):
  46.     for et in eturns:
  47.         if max_score == sum(turn) + sum(et):
  48.             print(turn)
  49.             break
  50.     for at in aturns:
  51.         if max_score > sum(turn) + sum(at):
  52.             from_turn(turn+at)
  53.  
  54. if __name__ == '__main__':
  55.     find_backtrack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement