Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- def moves(h):
- x, y = h
- return (x + 1, y), (x, y + 1), (x + y, y), (x, y + x)
- @lru_cache(None)
- def game(h):
- if sum(h) >= 100:
- return 'WIN'
- elif any(game(m) == 'WIN' for m in moves(h)):
- return 'P1'
- elif all(game(m) in ['P1'] for m in moves(h)):
- return 'V1'
- elif any(game(m) == 'V1' for m in moves(h)):
- return 'P2'
- elif all(game(m) in ['P1', 'P2'] for m in moves(h)):
- return 'V2'
- def p19(h):
- return any(game(m) == 'P1' for m in moves(h))
- print([s for s in range(1, 100) if p19((s, 20))]) #ваня выиграл первым ходом
- print([s for s in range(1, 100) if game((s, 20)) == 'P2']) #петя вторым ходом
- print([s for s in range(1, 100) if game((s, 20)) == 'V2'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement