Advertisement
maxim_shlyahtin

updated_game_theory

Nov 26th, 2021
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. from functools import lru_cache
  2.  
  3. con = 41
  4.  
  5.  
  6. def moves(h):
  7.     return h + 1, h + 5, h * 3
  8.  
  9.  
  10. @lru_cache(None)
  11. def ans(h):
  12.     if h >= con:
  13.         return "end"
  14.     elif any(ans(x) == "end" for x in moves(h)):
  15.         return 'П1'
  16.     elif all(ans(x) == 'П1' for x in moves(h)):
  17.         return "В1"
  18.     elif any(ans(x) == 'В1' for x in moves(h)):
  19.         return 'П2'
  20.     elif all(ans(x) == 'П2' or ans(x) == 'П1' for x in moves(h)):
  21.         return "В2"
  22.  
  23.  
  24. print('Задача 19')
  25.  
  26. for s in range(1, 41):
  27.     if ans(s) == 'В1':
  28.         print(s, ans(s))
  29.  
  30. print('Задача 20')
  31.  
  32. for s in range(1, 41):
  33.     if ans(s) == 'П2':
  34.         print(s, ans(s))
  35.  
  36. print('Задача 21')
  37.  
  38. for s in range(1, 41):
  39.     if ans(s) == 'В2':
  40.         print(s, ans(s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement