Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- def moves(x):
- a = [x - 1]
- if x % 2 == 0:
- a.append(x // 2)
- if x % 3 == 0:
- a.append((x // 3) * 2)
- return a
- @lru_cache(None)
- def game(h):
- if h < 10:
- 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(10, 1000) if game(s) == 'V1']) #ваня выиграл первым ходом
- print([s for s in range(10, 1000) if game(s) == 'P2']) #петя вторым ходом
- print([s for s in range(10, 1000) if game(s) == 'V2'])
Advertisement
Add Comment
Please, Sign In to add comment