Advertisement
nq1s788

19-20-21 две кучи

Jan 19th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. #19 20 21 https://inf-ege.sdamgia.ru/test?id=17275341
  2. from functools import lru_cache
  3.  
  4.  
  5. def moves(h):
  6.     x, y = h
  7.     return (x + 1, y), (x, y + 1), (x * 2, y), (x, y * 2)
  8.  
  9.  
  10. @lru_cache(None)
  11. def game(h):
  12.     if sum(h) >= 86:
  13.         return 'WIN'
  14.     elif any(game(m) == 'WIN' for m in moves(h)):
  15.         return 'P1'
  16.     elif all(game(m) in ['P1'] for m in moves(h)):
  17.         return 'V1'
  18.     elif any(game(m) == 'V1' for m in moves(h)):
  19.         return 'P2'
  20.     elif all(game(m) in ['P1', 'P2'] for m in moves(h)):
  21.         return 'V2'
  22.  
  23.  
  24. def p19(h):
  25.     return any(game(m) == 'P1' for m in moves(h))
  26.  
  27.  
  28. print([s for s in range(1, 72) if p19((14, s))]) #ваня выиграл первым ходом
  29. print([s for s in range(1, 72) if game((14, s)) == 'P2']) #петя вторым ходом
  30. print([s for s in range(1, 72) if game((14, s)) == 'V2'])
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement