2025(04): fix part 1
That was harder than it should have been.
This commit is contained in:
@ -32,15 +32,18 @@ def count_neighbours(tp_map):
|
||||
for x, y in np.ndindex(tp_map.shape):
|
||||
if not tp_map[x,y]:
|
||||
continue
|
||||
L_x, L_y = tp_map.shape
|
||||
dX, dY = X.copy() + x, Y.copy() + y
|
||||
legal_idx = (dX >= 0)*(dX < X.shape[0])*(dY >= 0)*(dY < Y.shape[1])
|
||||
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()
|
||||
print(neighbour_counts)
|
||||
max_rolls = 4
|
||||
print(neighbour_counts < max_rolls)
|
||||
return (neighbour_counts < max_rolls).sum()
|
||||
return (neighbour_counts[tp_map] < max_rolls).sum()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_map = read_map("testinput")
|
||||
print(test_map)
|
||||
print(count_neighbours(test_map))
|
||||
# print(test_map)
|
||||
assert count_neighbours(test_map) == 13
|
||||
# TODO: Compare the output map.
|
||||
|
||||
real_map = read_map("input")
|
||||
print(count_neighbours(real_map))
|
||||
Reference in New Issue
Block a user