Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. # Стартовая позиция [4, S]; 1 <= S <= 40
  2. # >= 45 win
  3. from functools import lru_cache
  4.  
  5.  
  6. def moves(heap):
  7.     a, b = heap[0], heap[1]
  8.     return [[a + 1, b], [a, b + 1], [a * 3, b], [a, b * 3]]
  9.  
  10.  
  11. def translate(heap: list) -> str:
  12.     return ",".join(map(str, heap))
  13.  
  14.  
  15. def reverse(k: str) -> list:
  16.     return k.split(",")
  17.  
  18.  
  19. parties = {}
  20.  
  21.  
  22. @lru_cache(None)
  23. def game(h, history):
  24.     if sum(h) >= 45:
  25.         parties[history[0]].append(history)
  26.         return
  27.  
  28.     for m in moves(h):
  29.         new_history = history + [translate(m)]
  30.         game(m, new_history)
  31.  
  32.  
  33. # start = [5, 4]
  34. # game(start, [translate(start)])
  35. for s in range(1, 41):
  36.     start = [4, s]
  37.     parties[translate(start)] = []
  38.     game(start, [translate(start)])
  39.  
  40. # Анализируем партии
  41. for start in parties.keys():
  42.     games = parties[start]
  43.     print(games)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement