AdventOfCode2023/14
2023-12-14 21:41:20 +01:00
..
day14.rs fix when cycle_remainder is 0 2023-12-14 21:41:20 +01:00
README.md day14: rust 2023-12-14 17:37:54 +01:00

Day 14

🎁🎁🎁🎁🎁🎁🎁🎁🎁🎁🎁🎁🎁🎁

Today's language: Rust

Lines of code: 85

Execution time: 0,172 s

This solution uses a single function for the tilting procedure. Different tilting directions are achieved by "remapping" x and y through captures.

For task 2, a cycle is searched by comparing the rocks after each nwse-tilt with all previous results. After finding two equal states, only (1.000.000.000 - cycle_start) % cycle_length cycles have to be performed to get the correct result. This approach requires making copies of the 2D array in a loop, which involves expensive heap allocations. It is still pretty fast.

rustc day14.rs
./day14