2025(04): fix part 1
That was harder than it should have been.
This commit is contained in:
@ -47,3 +47,136 @@ In this example, there are _`13`_ rolls of paper that can be accessed by a forkl
|
||||
|
||||
|
||||
Consider your complete diagram of the paper roll locations. _How many rolls of paper can be accessed by a forklift?_
|
||||
|
||||
### Part Two
|
||||
|
||||
Now, the Elves just need help accessing as much of the paper as they can.
|
||||
|
||||
Once a roll of paper can be accessed by a forklift, it can be _removed_. Once a roll of paper is removed, the forklifts might be able to access _more_ rolls of paper, which they might also be able to remove. How many total rolls of paper could the Elves remove if they keep repeating this process?
|
||||
|
||||
Starting with the same example as above, here is one way you could remove as many rolls of paper as possible, using highlighted _`@`_ to indicate that a roll of paper is about to be removed, and using `x` to indicate that a roll of paper was just removed:
|
||||
|
||||
Initial state:
|
||||
..@@.@@@@.
|
||||
@@@.@.@.@@
|
||||
@@@@@.@.@@
|
||||
@.@@@@..@.
|
||||
@@.@@@@.@@
|
||||
.@@@@@@@.@
|
||||
.@.@.@.@@@
|
||||
@.@@@.@@@@
|
||||
.@@@@@@@@.
|
||||
@.@.@@@.@.
|
||||
|
||||
Remove 13 rolls of paper:
|
||||
..xx.xx@x.
|
||||
x@@.@.@.@@
|
||||
@@@@@.x.@@
|
||||
@.@@@@..@.
|
||||
x@.@@@@.@x
|
||||
.@@@@@@@.@
|
||||
.@.@.@.@@@
|
||||
x.@@@.@@@@
|
||||
.@@@@@@@@.
|
||||
x.x.@@@.x.
|
||||
|
||||
Remove 12 rolls of paper:
|
||||
.......x..
|
||||
.@@.x.x.@x
|
||||
x@@@@...@@
|
||||
x.@@@@..x.
|
||||
.@.@@@@.x.
|
||||
.x@@@@@@.x
|
||||
.x.@.@.@@@
|
||||
..@@@.@@@@
|
||||
.x@@@@@@@.
|
||||
....@@@...
|
||||
|
||||
Remove 7 rolls of paper:
|
||||
..........
|
||||
.x@.....x.
|
||||
.@@@@...xx
|
||||
..@@@@....
|
||||
.x.@@@@...
|
||||
..@@@@@@..
|
||||
...@.@.@@x
|
||||
..@@@.@@@@
|
||||
..x@@@@@@.
|
||||
....@@@...
|
||||
|
||||
Remove 5 rolls of paper:
|
||||
..........
|
||||
..x.......
|
||||
.x@@@.....
|
||||
..@@@@....
|
||||
...@@@@...
|
||||
..x@@@@@..
|
||||
...@.@.@@.
|
||||
..x@@.@@@x
|
||||
...@@@@@@.
|
||||
....@@@...
|
||||
|
||||
Remove 2 rolls of paper:
|
||||
..........
|
||||
..........
|
||||
..x@@.....
|
||||
..@@@@....
|
||||
...@@@@...
|
||||
...@@@@@..
|
||||
...@.@.@@.
|
||||
...@@.@@@.
|
||||
...@@@@@x.
|
||||
....@@@...
|
||||
|
||||
Remove 1 roll of paper:
|
||||
..........
|
||||
..........
|
||||
...@@.....
|
||||
..x@@@....
|
||||
...@@@@...
|
||||
...@@@@@..
|
||||
...@.@.@@.
|
||||
...@@.@@@.
|
||||
...@@@@@..
|
||||
....@@@...
|
||||
|
||||
Remove 1 roll of paper:
|
||||
..........
|
||||
..........
|
||||
...x@.....
|
||||
...@@@....
|
||||
...@@@@...
|
||||
...@@@@@..
|
||||
...@.@.@@.
|
||||
...@@.@@@.
|
||||
...@@@@@..
|
||||
....@@@...
|
||||
|
||||
Remove 1 roll of paper:
|
||||
..........
|
||||
..........
|
||||
....x.....
|
||||
...@@@....
|
||||
...@@@@...
|
||||
...@@@@@..
|
||||
...@.@.@@.
|
||||
...@@.@@@.
|
||||
...@@@@@..
|
||||
....@@@...
|
||||
|
||||
Remove 1 roll of paper:
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
...x@@....
|
||||
...@@@@...
|
||||
...@@@@@..
|
||||
...@.@.@@.
|
||||
...@@.@@@.
|
||||
...@@@@@..
|
||||
....@@@...
|
||||
|
||||
|
||||
Stop once no more rolls of paper are accessible by a forklift. In this example, a total of _`43`_ rolls of paper can be removed.
|
||||
|
||||
Start with your original diagram. _How many rolls of paper in total can be removed by the Elves and their forklifts?_
|
||||
|
||||
@ -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))
|
||||
10
2025/04/testoutput
Normal file
10
2025/04/testoutput
Normal file
@ -0,0 +1,10 @@
|
||||
..xx.xx@x.
|
||||
x@@.@.@.@@
|
||||
@@@@@.x.@@
|
||||
@.@@@@..@.
|
||||
x@.@@@@.@x
|
||||
.@@@@@@@.@
|
||||
.@.@.@.@@@
|
||||
x.@@@.@@@@
|
||||
.@@@@@@@@.
|
||||
x.x.@@@.x.
|
||||
Reference in New Issue
Block a user