Skip to content

Instantly share code, notes, and snippets.

@jacobgardner
Created March 25, 2015 23:04
Show Gist options
  • Save jacobgardner/a0df5b73565f83da9e7d to your computer and use it in GitHub Desktop.
Save jacobgardner/a0df5b73565f83da9e7d to your computer and use it in GitHub Desktop.
die!
from collections import namedtuple
die = [
[1, 1, 2, 3, 4, 5],
[1, 1, 2, 3, 4, 5],
[1, 1, 2, 3, 4, 5],
[1, 1, 2, 3, 4, 5],
[1, 1, 2, 3, 4, 5],
]
def all_combos_list(lols, indices=[]):
index = len(indices)
if index < len(lols):
for i in range(len(lols[index])):
yield from all_combos_list(lols, indices + [i])
else:
yield [lst[idx] for lst, idx in zip(lols, indices)]
def all_combos(lols):
if isinstance(lols, dict):
sorted_keys = sorted(lols.keys())
tup = namedtuple('Combo', sorted_keys)
flattened = [lols[key] for key in sorted_keys]
for lst in all_combos_list(flattened):
yield tup(*lst)
else:
yield from all_combos_list(lols)
wins = 0
losses = 0
lulz = 0
for combo in all_combos(die):
if len(set(combo)) == 5:
# No winnar.
lulz += 1
continue
if combo.count(1) > 2:
# gg ez mid
wins += 1
elif combo.count(1) < 2:
# noob team
losses += 1
else:
# close game
assert combo.count(1) == 2
for i in range(2, 6):
if combo.count(i) == 2:
# tie (2 cases will win. 1 will fail)
# neither.append(combo)
wins += 2/3
losses += 1/3
break
elif combo.count(i) == 3:
losses += 1
break
else: # nobreak (No tie occurred)
wins += 1
print(wins / (wins + losses))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment