Skip to content

Conversation

@Pencilcaseman
Copy link
Contributor

@Pencilcaseman Pencilcaseman commented Dec 18, 2025

Both part 1 and part 2 require the input to be sorted, but currently they're sorted independently and in a different order.

Transposing part 1 to work with an input sorted by y first to match part 2 allows you to sort the tiles only once and avoid a couple copies.

Also, using u32s in place of u64s where possible makes things a touch faster.

Overall, this makes the solution ~15% faster on my machine (M2 Max)

Does it make more sense to refactor part 2 to work with x-ordered tiles?
EDIT: Part 2 is twice as fast with the x-ordered (transposed) processing order due to the structure of the input, so sorting by (y, x) instead of (x, y) makes sense.

@maneatingape maneatingape merged commit 1f713c7 into maneatingape:main Dec 18, 2025
3 checks passed
@maneatingape
Copy link
Owner

Nice improvement! I get a ~20% speedup (49µs => 40µs).

@Pencilcaseman
Copy link
Contributor Author

Thanks! I had to cheat and take a look at your solution to solve this one, so I'm glad I could help somehow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants