MCPcopy Create free account
hub / github.com/AxlLind/AdventOfCode / simulate

Function simulate

2018/src/15.py:53–69  ·  view source on GitHub ↗
(dmg: dict[str,int], m: list[list[tuple[str,int]]], nelves: int | None = None)

Source from the content-addressed store, hash-verified

51 return counts['E'],counts['G']
52
53def 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')
72def main(indata: str) -> tuple[int,int]:

Callers 1

mainFunction · 0.70

Calls 2

count_leftFunction · 0.85
stepFunction · 0.70

Tested by

no test coverage detected