Advertisement
Korotkodul

N21_6647

Jun 17th, 2023
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. def f(x,y,k):
  2.     bef = k - 1
  3.     if max(x,y) >= 50:
  4.         if bef == 3:
  5.             return 1
  6.         else: #bef < 3
  7.             return 0
  8.     elif bef == 3: #max(x,y) < 50
  9.         return 0
  10.     A = f(x + 3, y, k + 1)
  11.     B = f(2 * x, y, k + 1)
  12.     C = f(x, y + 3, k + 1)
  13.     D = f(x, 2 * y, k + 1)
  14.     if k % 2 == 1:
  15.         return A or B or C or D
  16.     else:
  17.         return A and B and C and D
  18.  
  19.  
  20. def g(x,y,k):
  21.     bef = k - 1
  22.     if max(x, y) >= 50:
  23.         if bef == 1 or bef == 3:
  24.             return 1
  25.         else:
  26.             return 0
  27.     A = g(x + 3, y, k + 1)
  28.     B = g(x * 2, y, k + 1)
  29.     C = g(x, y + 3, k + 1)
  30.     D = g(x, y * 2, k + 1)
  31.     if k % 2 == 1:
  32.         return A or B or C or D
  33.     else:
  34.         return A and B and C and D
  35.  
  36. for s in range(27, 0, -1):
  37.     print("s ", s)
  38.     ok = 1
  39.     #1st moves Ivan
  40.     if not f(22, s, 1):
  41.         ok = 0
  42.  
  43.     #1st moves Peter
  44.     #checking that Ivan cant win in 1 move
  45.     v = [(22, s + 3), (22, s * 2)]
  46.     for p in v:
  47.         if p[1] * 2 >= 50:
  48.             ok = 0
  49.     #A = g(22 + 3, s, 1)
  50.     #B = g(22 * 2, s, 1)
  51.     C = g(22, s + 3, 1)
  52.     D = g(22, s * 2, 1)
  53.     E = C and D
  54.     if not E:
  55.         ok = 0
  56.     if ok:
  57.         print(s)
  58.         break
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement