Advertisement
nq1s788

одна куча

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