Advertisement
nq1s788

19 с условием на делимость на 3

Mar 16th, 2024
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. from functools import lru_cache
  2.  
  3.  
  4. def moves(h):
  5.     a = h
  6.     answ = []
  7.     if (a + 1) % 3 != 0:
  8.         answ.append(a + 1)
  9.     if (a + 2) % 3 != 0:
  10.         answ.append(a + 2)
  11.     if (a * 2) % 3 != 0:
  12.         answ.append(a * 2)
  13.     return answ
  14.  
  15.  
  16. @lru_cache(None)
  17. def game (h):
  18.     if h >= 151:
  19.         return 'win'
  20.     elif any(game(m) == 'win' for m in moves(h)):
  21.         return'p1'
  22.     elif all (game(m) == 'p1' for m in moves(h)):
  23.         return'v1'
  24.     elif any(game(m) == 'v1' for m in moves(h)):
  25.         return'p2'
  26.     elif all(game(m) in ['p1', 'p2'] for m in moves(h)):
  27.         return'v2'
  28.  
  29.  
  30. def p19(h):
  31.     return any(game(m) == 'p1' for m in moves(h))
  32.  
  33.  
  34. print([s for s in range(1, 150) if (s % 3 != 0) and game(s) == 'v1'])
  35. print([s for s in range(1, 150) if (s % 3 != 0) and game(s) == 'p2'])
  36. 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