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

Function part2

2018/src/23.py:9–16  ·  view source on GitHub ↗
(bots: list[list[int]])

Source from the content-addressed store, hash-verified

7 return sum(abs(x1-x) + abs(y1-y) + abs(z1-z) <= r for x1,y1,z1,_ in bots)
8
9def part2(bots: list[list[int]]) -> int:
10 def abs(x):
11 return If(x >= 0,x,-x)
12 x,y,z,opt = Int("x"), Int("y"), Int("z"), Optimize()
13 opt.maximize(sum(If(abs(x-x1) + abs(y-y1) + abs(z-z1) <= r, 1, 0) for x1,y1,z1,r in bots))
14 opt.minimize(abs(x) + abs(y) + abs(z))
15 opt.check()
16 return opt.model().eval(abs(x) + abs(y) + abs(z))
17
18@aoc.main('23')
19def main(indata: str) -> tuple[int,int]:

Callers 1

mainFunction · 0.70

Calls 1

absFunction · 0.85

Tested by

no test coverage detected