2025(04): solve part 2, change to function to what they should have been in 1
This commit is contained in:
@ -36,14 +36,18 @@ def count_neighbours(tp_map):
|
|||||||
dX, dY = X.copy() + x, Y.copy() + y
|
dX, dY = X.copy() + x, Y.copy() + y
|
||||||
legal_idx = (dX >= 0)*(dX < L_x)*(dY >= 0)*(dY < L_y)*((dX != x)|(dY != y))
|
legal_idx = (dX >= 0)*(dX < L_x)*(dY >= 0)*(dY < L_y)*((dX != x)|(dY != y))
|
||||||
neighbour_counts[x, y] = (tp_map[dX[legal_idx], dY[legal_idx]]).sum()
|
neighbour_counts[x, y] = (tp_map[dX[legal_idx], dY[legal_idx]]).sum()
|
||||||
|
return neighbour_counts
|
||||||
|
|
||||||
|
def count_extractable(tp_map):
|
||||||
|
neighbour_counts = count_neighbours(tp_map)
|
||||||
max_rolls = 4
|
max_rolls = 4
|
||||||
return (neighbour_counts[tp_map] < max_rolls).sum()
|
return (neighbour_counts[tp_map] < max_rolls).sum()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_map = read_map("testinput")
|
test_map = read_map("testinput")
|
||||||
# print(test_map)
|
# print(test_map)
|
||||||
assert count_neighbours(test_map) == 13
|
assert count_extractable(test_map) == 13
|
||||||
# TODO: Compare the output map.
|
# TODO: Compare the output map.
|
||||||
|
|
||||||
real_map = read_map("input")
|
real_map = read_map("input")
|
||||||
print(count_neighbours(real_map))
|
print(count_extractable(real_map))
|
||||||
24
2025/04/part2.py
Normal file
24
2025/04/part2.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import numpy as np
|
||||||
|
from part1 import read_map, print_map, count_neighbours, count_extractable
|
||||||
|
|
||||||
|
def remove_iteratively(tp_map):
|
||||||
|
max_rolls = 4
|
||||||
|
rolls_removed_counts = []
|
||||||
|
rolls_removed_count = 1_000_000
|
||||||
|
while rolls_removed_count > 0:
|
||||||
|
neighbour_counts = count_neighbours(tp_map)
|
||||||
|
rolls_to_remove = (neighbour_counts < max_rolls)*tp_map
|
||||||
|
rolls_removed_count = rolls_to_remove.sum()
|
||||||
|
rolls_removed_counts.append(rolls_removed_count)
|
||||||
|
tp_map[rolls_to_remove] = False
|
||||||
|
return sum(rolls_removed_counts)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_map = read_map("testinput")
|
||||||
|
# print(test_map)
|
||||||
|
assert count_extractable(test_map) == 13
|
||||||
|
assert remove_iteratively(test_map.copy()) == 43
|
||||||
|
# TODO: Compare the output maps.
|
||||||
|
|
||||||
|
real_map = read_map("input")
|
||||||
|
print(remove_iteratively(real_map.copy()))
|
||||||
Reference in New Issue
Block a user