frozen set
This commit is contained in:
@@ -53,6 +53,7 @@ def p1():
|
||||
|
||||
|
||||
globalgame = 0
|
||||
mdepth = 0
|
||||
def p2():
|
||||
inp = get_input(pw)
|
||||
players = []
|
||||
@@ -67,12 +68,15 @@ def p2():
|
||||
print(players)
|
||||
final = False
|
||||
wins = [0, 0]
|
||||
def play(players):
|
||||
def play(players, depth=0):
|
||||
global globalgame
|
||||
global mdepth
|
||||
mdepth = max(mdepth, depth)
|
||||
globalgame += 1
|
||||
history = set()
|
||||
while all(filter(lambda x: len(x) > 0, players)):
|
||||
hv = ','.join(map(str, players[0])) + ':' + ','.join(map(str, players[1]))
|
||||
hv = frozenset([frozenset(players[0]), frozenset(players[1])])
|
||||
# ','.join(map(str, players[0])) + ':' + ','.join(map(str, players[1]))
|
||||
if hv in history:
|
||||
return 0
|
||||
else:
|
||||
@@ -80,7 +84,7 @@ def p2():
|
||||
i = (players[0].pop(0), players[1].pop(0))
|
||||
if i[0] <= len(players[0]) and i[1] <= len(players[1]):
|
||||
players2 = [players[0][:i[0]], players[1][:i[1]]]
|
||||
won = play(players2)
|
||||
won = play(players2, depth + 1)
|
||||
if won == 1:
|
||||
won = 0
|
||||
else:
|
||||
@@ -99,7 +103,7 @@ def p2():
|
||||
return 1
|
||||
if(len(players[1]) == 0):
|
||||
return 0
|
||||
won = play(players)
|
||||
won = play(players, 1)
|
||||
|
||||
|
||||
if len(players[0]) == 0:
|
||||
@@ -112,7 +116,7 @@ def p2():
|
||||
#print(i,x)
|
||||
su += i*x
|
||||
|
||||
print(su, f'(played games {globalgame})')
|
||||
print(su, f'(played games {globalgame}/{mdepth})')
|
||||
return 0
|
||||
|
||||
result1 = None
|
||||
|
||||
Reference in New Issue
Block a user