########################################################### # Run the following code at https://sagecell.sagemath.org/ ########################################################### ########################################################### # PARAMETERS ########################################################### N = 113 # total regular cards E = 37 # cards with evo only EH = 2 # cards with both evo and hero forms H = 2 # cards with hero only C = 8 # champions K = 8 # deck size MAX_EVOS = 2 # max evos in a deck MAX_HERO_SLOTS = 2 # max hero-slot cards (heroes + champs) in a deck TOWER_MULTIPLIER = 4 # tower troop factor ########################################################### # T(e1, e2, h1, h2, h3) # # e1 = # of E cards used as evo # e2 = # of EH cards used as evo # h1 = # of EH cards used as hero # h2 = # of H-only cards used as hero # h3 = # of champions # # Constraints (enforced by loop ranges, but this is the logic): # - e1 + e2 <= MAX_EVOS (evo slots) # - h1 + h2 + h3 <= MAX_HERO_SLOTS (hero slots) # - e2 + h1 <= EH (can't use more EH cards than exist) # - 0 <= e1 <= E, 0 <= e2 <= EH, etc. ########################################################### def T(e1, e2, h1, h2, h3): # Choose specific cards for each role choose_E_evos = binomial(E, e1) choose_EH_evos = binomial(EH, e2) choose_EH_heroes = binomial(EH - e2, h1) choose_H_heroes = binomial(H, h2) choose_champions = binomial(C, h3) # Remaining slots in the 8-card deck must be regular-form cards special_count = e1 + e2 + h1 + h2 + h3 remaining_slots = K - special_count # Available regular-form cards: # total regular N minus those already used in a non-regular form regular_available = N - e1 - e2 - h1 - h2 choose_regulars = binomial(regular_available, remaining_slots) return (choose_E_evos * choose_EH_evos * choose_EH_heroes * choose_H_heroes * choose_champions * choose_regulars) ########################################################### # SUM OVER ALL VALID (e1, e2, h1, h2, h3) # # Loop bounds: # # - e1: 0 .. min(E, MAX_EVOS) # - e2: 0 .. min(EH, MAX_EVOS - e1) # - h1: 0 .. min(EH - e2, MAX_HERO_SLOTS) # - h2: 0 .. min(H, MAX_HERO_SLOTS - h1) # - h3: 0 .. min(C, MAX_HERO_SLOTS - h1 - h2) # # These ensure: # e1 + e2 <= MAX_EVOS # h1 + h2 + h3 <= MAX_HERO_SLOTS # e2 + h1 <= EH (since h1 <= EH - e2) ########################################################### total = 0 for e1 in range(0, min(E, MAX_EVOS) + 1): for e2 in range(0, min(EH, MAX_EVOS - e1) + 1): # EH cards left: EH - e2 max_h1 = min(EH - e2, MAX_HERO_SLOTS) for h1 in range(0, max_h1 + 1): max_h2 = min(H, MAX_HERO_SLOTS - h1) for h2 in range(0, max_h2 + 1): max_h3 = min(C, MAX_HERO_SLOTS - h1 - h2) for h3 in range(0, max_h3 + 1): total += T(e1, e2, h1, h2, h3) result = TOWER_MULTIPLIER * total result