Advertisement
kirilchik

Untitled

Apr 11th, 2022
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. from functools import lru_cache
  2.  
  3.  
  4. def moves(s):
  5.     a, b = s[0], s[1]
  6.     return (a - 1, b), (a // 2, b), (a, b - 1), (a, b // 2)
  7.  
  8.  
  9. @lru_cache(None)
  10. def f(s, depth):
  11.     if depth >= 100:
  12.         return None
  13.     if sum(s) <= 20:
  14.         return 'win'
  15.     if any(f(x, depth + 1) == 'win' for x in moves(s)):
  16.         return 'p1'
  17.     if all(f(x, depth + 1) == 'p1' for x in moves(s)):
  18.         return 'v1'
  19.     if any(f(x, depth + 1) == 'v1' for x in moves(s)):
  20.         return 'p2'
  21.     if all(f(x, depth + 1) == 'p2' or f(x, depth + 1) == 'p1' for x in moves(s)):
  22.         return 'v2'
  23.  
  24.  
  25. for i in range(10, 100):
  26.     print(i, f((10, i), 0))
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement