Skip to content

Instantly share code, notes, and snippets.

@Feniksovich
Last active April 26, 2022 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Feniksovich/cfbd44c7ffab35b1082e5cae0ed336a3 to your computer and use it in GitHub Desktop.
Save Feniksovich/cfbd44c7ffab35b1082e5cae0ed336a3 to your computer and use it in GitHub Desktop.
Programs for IT Unified State Exam (Game Theory)
# 1 heap
# Prohibition of repetition of the opponent's move
def f(s,p,c,m):
if s>64: return c%2==m%2
if c==m: return 0
h=[]
if p!='+1': h+=[f(s+1,'+1',c+1,m)]
if p!='+2': h+=[f(s+1,'+2',c+1,m)]
if p!='*2': h+=[f(s+1,'*2',c+1,m)]
return any(h) if (c+1)%2==m%2 else all(h)
for s in range(1, 65):
for m in range(1,10):
if f(s,0,m):
print(s, m)
break
# 1 heap
# "With a loss" condition
def f(s,c,m):
if 32<=s<64: return c%2==m%2
if s>64: return c%2!=m%2
if c==m: return 0
h=[f(s+1,c+1,m), f(s+2,c+1,m), f(s*3,c+1,m)]
return any(h) if (c+1)%2==m%2 else all(h)
for s in range(1, 65):
for m in range(1,10):
if f(s,0,m):
print(s, m)
break
# 1 heap
# Without restrictions
def f(s,c,m):
if s>64: return c%2==m%2
if c==m: return 0
h=[f(s+1,c+1,m), f(s+2,c+1,m), f(s*3,c+1,m)]
return any(h) if (c+1)%2==m%2 else all(h)
for s in range(1, 65):
for m in range(1,10):
if f(s,0,m):
print(s, m)
break
# 2 heaps
# Without restrictions
def f(a,b,c,m):
if s>64: return c%2==m%2
if c==m: return 0
h=[f(a+1,b,c+1,m), f(a,b+1,c+1,m), f(a+2,b,c+1,m), f(a,b+2,c+1,m)]
return any(h) if (c+1)%2==m%2 else all(h)
for a in range(1, 65):
for m in range(1,10):
if f(a,10,0,m):
print(s, m)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment