Skip to content

Instantly share code, notes, and snippets.

@mozz100
Last active January 24, 2023 22:18
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 mozz100/213e205e290e18484a5eafacf5d896db to your computer and use it in GitHub Desktop.
Save mozz100/213e205e290e18484a5eafacf5d896db to your computer and use it in GitHub Desktop.
Compute coefficients for FA Cup probability trees. See https://www.rmorrison.net/mnemozzyne/2023/01/24/optimising-the-fa-cup/
"""
Compute coefficients for FA Cup probability trees.
See https://www.rmorrison.net/mnemozzyne/2023/01/24/optimising-the-fa-cup/
"""
from typing import List
from dataclasses import dataclass
@dataclass
class Fixture:
hosts: str
visitors: str
history: str
@dataclass
class Round:
fixtures: List[Fixture]
def __str__(self):
all_journeys = "".join([f.history for f in self.fixtures])
coefficients = [f"{all_journeys.count(c)}{c}" for c in "hax"]
return "(" + " + ".join([c for c in coefficients]) + f") / {len(self.fixtures)}"
rounds = [Round(fixtures=[Fixture(hosts="h", visitors="a", history="h")])]
for r in range(0, 5):
new_round = Round(fixtures=[])
prev_round = rounds[r]
for f in prev_round.fixtures:
new_round.fixtures.append(Fixture(f.hosts, "x", f.history + f.hosts))
new_round.fixtures.append(Fixture("x", f.hosts, f.history + "x"))
new_round.fixtures.append(Fixture(f.visitors, "x", f.history + f.visitors))
new_round.fixtures.append(Fixture("x", f.visitors, f.history + "x"))
rounds.append(new_round)
print(new_round)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment