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

Function parse_tree

2018/src/08.py:6–12  ·  view source on GitHub ↗
(xs: list[int], i: int)

Source from the content-addressed store, hash-verified

4Tree = tuple[list[Any],list[int]] # mypy cannot handle recursive types, use 'Any' for now
5
6def parse_tree(xs: list[int], i: int) -> tuple[int,Tree]:
7 children, ndata = [], xs[i+1]
8 i += 2
9 for _ in range(xs[i-2]):
10 i, child = parse_tree(xs,i)
11 children.append(child)
12 return i+ndata, (children, xs[i:i+ndata])
13
14def metadata_sum(e: Tree) -> int:
15 return sum(e[1]) + sum(metadata_sum(c) for c in e[0])

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected