Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Стартовая позиция [4, S]; 1 <= S <= 40
- # >= 45 win
- from functools import lru_cache
- def moves(heap):
- a, b = heap[0], heap[1]
- return [[a + 1, b], [a, b + 1], [a * 3, b], [a, b * 3]]
- def translate(heap: list) -> str:
- return ",".join(map(str, heap))
- def reverse(k: str) -> list:
- return k.split(",")
- parties = {}
- @lru_cache(None)
- def game(h, history):
- if sum(h) >= 45:
- parties[history[0]].append(history)
- return
- for m in moves(h):
- new_history = history + [translate(m)]
- game(m, new_history)
- # start = [5, 4]
- # game(start, [translate(start)])
- for s in range(1, 41):
- start = [4, s]
- parties[translate(start)] = []
- game(start, [translate(start)])
- # Анализируем партии
- for start in parties.keys():
- games = parties[start]
- print(games)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement