Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- def moves(h):
- move = []
- for k in range(2, h + 1):
- if h % k == 0:
- move.append(h + h // k)
- return move
- @lru_cache(None)
- def game(h):
- if h >= 41:
- return 'win'
- elif any(game(m) == 'win' for m in moves(h)):
- return'p1'
- elif all(game(m) == '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(len([s for s in range(1, 41) if p19(s)]))
- print([s for s in range(1, 150) if (s % 3 != 0) and game(s) == 'p2'])
- print([s for s in range(1, 150) if (s % 3 != 0) and game(s) == 'v2'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement