(dmg: dict[str,int], m: list[list[tuple[str,int]]], nelves: int | None = None)
| 51 | return counts['E'],counts['G'] |
| 52 | |
| 53 | def simulate(dmg: dict[str,int], m: list[list[tuple[str,int]]], nelves: int | None = None) -> tuple[str,int]: |
| 54 | m, rounds = deepcopy(m), 0 |
| 55 | while True: |
| 56 | step(m,dmg) |
| 57 | e,g = count_left(m) |
| 58 | if e == 0 or g == 0: |
| 59 | break |
| 60 | if nelves and e < nelves: |
| 61 | return 'G', -1 |
| 62 | rounds += 1 |
| 63 | |
| 64 | winner, score = "", 0 |
| 65 | for r,c in product(range(len(m)),range(len(m[0]))): |
| 66 | if m[r][c][0] in "GE": |
| 67 | winner = m[r][c][0] |
| 68 | score += m[r][c][1] |
| 69 | return winner, score*rounds |
| 70 | |
| 71 | @aoc.main('15') |
| 72 | def main(indata: str) -> tuple[int,int]: |
no test coverage detected