Nothing special today, it was easier than expected...
# advent-of-code
k
Nothing special today, it was easier than expected when I first saw the input simple smile
j
I like the use of TreeSet to keep the carts sorted
Now that I think about it, does it keep them sorted? Or just initially? Because it wouldn't know when the x and y properties were changed to resort, would it?
k
Is doesn't keep them sorted, at the start of each tick all carts are added to the set, than polled out one by one.
I think it's still faster as it doesn't actually have to sort anything, it just creates a binary tree.
And it's all premature optimization as there are only like 20 carts.
j
Ah, but the assignment states:
Carts all move at the same speed; they take turns moving a single step at a time. They do this based on their current location: carts on the top row move first (acting from left to right), then carts on the second row move (again from left to right), then carts on the third row, and so on. Once each cart has moved one step, the process repeats; each of these loops is called a tick.
So you should re-sort the carts after each tick - you got lucky with your input! I didn't read this properly at first, and my answer wasn't accepted because of it
k
I do re-sort them after each tick.
Before each tick actually.
j
Ah, right, now I see the
addAll
, sorry!