2022-12-18 - Boiling Boulders
(original .ipynb)
puzzle_input_str = open("./puzzle_input/day18.txt").read()
test_input_str = open("./test_input/day18.txt").read()
def neighbours(x, y, z):
directions = (
( 1, 0, 0),
(-1, 0, 0),
( 0, 1, 0),
( 0, -1, 0),
( 0, 0, 1),
( 0, 0, -1),
)
for dx, dy, dz in directions:
yield (x+dx, y+dy, z+dz)
def parse_cube(line):
return tuple(int(c) for c in line.split(","))
def part_one(input_str):
all_cubes = [parse_cube(line) for line in input_str.splitlines()]
total = 0
for x,y,z in all_cubes:
sides = 6
for neighbour in neighbours(x, y, z):
if neighbour in all_cubes:
sides -= 1
total += sides
return total
# print(part_one("1,1,1\n2,1,1"))
assert 64 == part_one(test_input_str)
print("part one:", part_one(puzzle_input_str))
part one: 4244
def
def part_two(input_str):
all_cubes = [parse_cube(line) for line in input_str.splitlines()]
total = 0
potential_bubbles = set()
for x,y,z in all_cubes:
for neighbour in neighbours(x, y, z):
if neighbour not in all_cubes:
potential_bubbles.add(neighbour)
print(len(potential_bubbles))
bubbles = 0
for x,y,z in potential_bubbles:
is_bubble = True
for neighbour in neighbours(x, y, z):
is_bubble = is_bubble and neighbour in all_cubes
if is_bubble:
bubbles += 1
print(input_str)
print(len(input_str.splitlines()))
return 0
# print(part_one("1,1,1\n2,1,1"))
#print(part_one(test_input_str))
print("part two:", part_two(puzzle_input_str))
2004
part two: 0