Advertisement
Joporezka1

Untitled

Apr 9th, 2021
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from functools import lru_cache
  2.  
  3. def moves(heap):
  4.     a,b= heap
  5.     return (a+1,b),(a*3,b),(a,b+1),(a,b*3)
  6.  
  7. @lru_cache(None)
  8. def game(heap):
  9.     if sum(heap)>=75:
  10.         return 'WIN'
  11.     if any(game(m)=='WIN' for m in moves(heap)):
  12.         return 'S1'
  13.     if all(game(m) == 'S1' for m in moves(heap)):
  14.         return 'P1'
  15.     if any(game(m) == 'P1' for m in moves(heap)):
  16.         return 'S2'
  17.     if all(game(m) == 'S2' or game(m)=='S1' for m in moves(heap)):
  18.         return 'p2'
  19.  
  20. for s in range(1,67):
  21.     print(s,game((7,s)))
  22.  
  23. '''f = open('24_3.txt')
  24. s = f.readline()
  25. max = 0
  26. flag = 0
  27. global_count = 0
  28. for i in range(len(s)):
  29.    if s[i]=='(':
  30.        global_count=1
  31.        flag = 1
  32.    elif flag and (s[i]=='+' or s[i]=='*'):
  33.        global_count+=1
  34.    elif flag and s[i]=='(':
  35.        global_count=1
  36.        flag=1
  37.    elif flag and s[i]==')':
  38.        global_count+=1
  39.        flag = 0
  40.        if global_count>max:
  41.            max = global_count
  42.        global_count=0
  43.  
  44. print(max)'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement