+/AoC

advent of code

git clone https://git.julia.blue/+/AoC

Joseph RyanDays 15-186e46de2

master
614 B21 linesraw
1points = {tuple(map(int, l.split(","))) for l in open("input")}
2total = 0
3adj = ((-1, 0, 0), (1, 0, 0), (0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1))
4neighbors = lambda p: tuple((p[0] + x, p[1] + y, p[2] + z) for x, y, z in adj)
5for p in points:
6    total += sum(n not in points for n in neighbors(p))
7print(total)
8visited = set()
9q = {(0, 0, 0)}
10total = 0
11while q:
12    p = q.pop()
13    visited.add(p)
14    for n in neighbors(p):
15        if n in visited or any(i not in range(-1, 21) for i in n):
16            continue
17        if n in points:
18            total += 1
19            continue
20        q.add(n)
21print(total)