Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

31 lines
795B

  1. from functools import lru_cache
  2. from itertools import product, cycle, count
  3. @lru_cache(maxsize=None)
  4. def play(p1, p2, s1=0, s2=0):
  5. if s2 >= 21: return 0, 1
  6. w1, w2 = 0, 0
  7. for die in d3:
  8. pN = (p1 + die) % 10 or 10
  9. n2, n1 = play(p2, pN, s2, s1 + pN)
  10. w1, w2 = (w1 + n1), (w2 + n2)
  11. return w1, w2
  12. text = open(0).read()
  13. d3 = [sum(rolls) for rolls in product(range(1, 4), repeat=3)]
  14. p1, p2 = [int(ln[-1]) for ln in text.splitlines()]
  15. state = {0: (0, p1), 1: (0, p2)}
  16. d100 = cycle(range(1,101))
  17. for i in count():
  18. score, pos = state[i % 2]
  19. pos = (pos + next(d100) + next(d100) + next(d100)) % 10 or 10
  20. state[i % 2] = (score + pos, pos)
  21. if score + pos >= 1000:
  22. break
  23. print((i + 1) * 3 * min(state.values())[0])
  24. print(max(play(p1, p2)))