Witsaff/Appendix
Jump to navigation
Jump to search
Simulation for the fancy example:
from collections import Counter
from fractions import Fraction
from itertools import permutations
cols = "cash", "cash", "key", "toolkey", "tool", "treasure"
valid = []
for p in permutations(cols, 6):
inv = set([p[0], p[2]])
done = cannon = beam = boss = False
while not done:
done = True
if "key" in inv and not cannon:
inv.update([p[1], p[3]])
cannon = True
done = False
if "toolkey" in inv and not beam:
inv.add(p[4])
beam = True
done = False
if "tool" in inv and not boss:
inv.add(p[5])
boss = True
done = False
if "treasure" in inv: valid.append(p)
def frac(f): return str(Fraction(f).limit_denominator())
l = len(valid)
print("Count:", l)
for i in range(6):
counter = Counter(p[i] for p in valid)
print("Row", i, "sum", sum(counter.values()))
print(*[frac(counter[k] / l) for k in cols])