Advertisement
nq1s788

19 нельзя делать предыдущий код

Oct 16th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. from functools import lru_cache
  2.  
  3.  
  4. def moves(h):
  5.     x, lst = h
  6.     ##### вариант 1
  7.     moves = [1, 3, 6] #числа, которые можем прибавлять, все возможные ходы
  8.     ret_move = [] #ходы, которые мы делаем
  9.     for e in moves:
  10.         if e != lst:
  11.             ret_move.append((x + e, e))
  12.     ###### вариант 2
  13.     ret_move = [(x + e, e) for e in (1, 3, 6) if e != lst]
  14.     ######
  15.     return ret_move
  16.  
  17.  
  18. @lru_cache(None)
  19. def game(h):
  20.     if h[0] >= 41:
  21.         return 'win'
  22.     elif any(game(m) == 'win' for m in moves(h)):
  23.         return'p1'
  24.     elif all(game(m) == 'p1' for m in moves(h)):
  25.         return'v1'
  26.     elif any(game(m) == 'v1' for m in moves(h)):
  27.         return'p2'
  28.     elif all(game(m) in ['p1', 'p2'] for m in moves(h)):
  29.         return'v2'
  30.  
  31.  
  32. def p19(h):
  33.     return any(game(m) == 'p1' for m in moves(h))
  34.  
  35.  
  36. print([s for s in range(1, 41) if p19((s, -1))])
  37. print([s for s in range(1, 150) if (s % 3 != 0) and game((s, -1)) == 'p2'])
  38. 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