Skip to content

Instantly share code, notes, and snippets.

@jakab922
Last active March 1, 2016 09:44
Show Gist options
  • Save jakab922/add260cffcab24369acb to your computer and use it in GitHub Desktop.
Save jakab922/add260cffcab24369acb to your computer and use it in GitHub Desktop.
from collections import defaultdict
from copy import deepcopy
daphne = defaultdict(set)
rdaphne = {}
maxx = defaultdict(set)
rmaxx = {}
mindy = defaultdict(set)
rmindy = {}
sam = defaultdict(set)
rsam = {}
for i in xrange(1, 6):
for j in xrange(i, 6):
val = (i, j)
daphne[abs(i - j)].add(val)
rdaphne[val] = abs(i - j)
maxx[max(i, j)].add(val)
rmaxx[val] = max(i, j)
mindy[min(i, j)].add(val)
rmindy[val] = min(i, j)
sam[i + j].add(val)
rsam[val] = i + j
players = [daphne, maxx, mindy, sam]
rplayers = [rdaphne, rmaxx, rmindy, rsam]
scores = [0 for _ in xrange(4)]
for i in xrange(1, 6):
for j in xrange(i, 6):
val = (i, j)
cplayers = deepcopy(players)
while True:
found = False
for k in xrange(4):
cp = cplayers[k]
rp = rplayers[k]
l = len(cp[rp[val]])
if l == 1:
print "The winner for %s is %s" % (val, k)
scores[k] += 1 if i == j else 2
found = True
break
else:
to_remove = []
for key in cp.keys():
if len(cp[key]) == 1:
to_remove.append([el for el in cp[key]][0])
for l in xrange(4):
for el in to_remove:
cplayers[l][rplayers[l][el]].remove(el)
if found:
break
print "scores: %s" % (scores,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment