Advertisement
nq1s788

19 две кучи (в одну добавить другую)

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