Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- def moves(h):
- x, lst = h
- ##### вариант 1
- moves = [1, 3, 6] #числа, которые можем прибавлять, все возможные ходы
- ret_move = [] #ходы, которые мы делаем
- for e in moves:
- if e != lst:
- ret_move.append((x + e, e))
- ###### вариант 2
- ret_move = [(x + e, e) for e in (1, 3, 6) if e != lst]
- ######
- return ret_move
- @lru_cache(None)
- def game(h):
- if h[0] >= 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([s for s in range(1, 41) if p19((s, -1))])
- print([s for s in range(1, 150) if (s % 3 != 0) and game((s, -1)) == 'p2'])
- print([s for s in range(1, 150) if (s % 3 != 0) and game((s, -1)) == 'v2'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement