nq1s788

камни с проверкой на делимость

Jan 21st, 2026
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. from functools import lru_cache
  2.  
  3.  
  4. def moves(x):
  5.     a = [x - 1]
  6.     if x % 2 == 0:
  7.         a.append(x // 2)
  8.     if x % 3 == 0:
  9.         a.append((x // 3) * 2)
  10.     return a
  11.  
  12.  
  13. @lru_cache(None)
  14. def game(h):
  15.     if h < 10:
  16.         return 'WIN'
  17.     elif any(game(m) == 'WIN' for m in moves(h)):
  18.         return 'P1'
  19.     elif all(game(m) in ['P1'] for m in moves(h)):
  20.         return 'V1'
  21.     elif any(game(m) == 'V1' for m in moves(h)):
  22.         return 'P2'
  23.     elif all(game(m) in ['P1', 'P2'] for m in moves(h)):
  24.         return 'V2'
  25.  
  26.  
  27. def p19(h):
  28.     return any(game(m) == 'P1' for m in moves(h))
  29.  
  30.  
  31. print([s for s in range(10, 1000) if game(s) == 'V1']) #ваня выиграл первым ходом
  32. print([s for s in range(10, 1000) if game(s) == 'P2']) #петя вторым ходом
  33. print([s for s in range(10, 1000) if game(s) == 'V2'])
  34.  
Advertisement
Add Comment
Please, Sign In to add comment