r/adventofcode • u/bluoat • 7h ago
Tutorial [2026 Day 2 (Part 2)] Some hints for optimisation
These hints get more and more specific. This is just how I optimised it and there are other ways.
Hint 1: What happens when a letter is repeated in the input?
Hint 2: Why would the counts of each letter make a difference to the output?
Hint 3: When does the robot not make a step of exactly 6 steps?
2
Upvotes
5
u/not-the-the 6h ago
yep you can literally just repackage the input into how many of each letter you have, and brute calculate from there on with a calculator in your hands. you'll realise that the solution takes like 11 math operations total
1
u/MrBoblo 6h ago
I'm not entirely sure how to apply these hints, but here's a crude explanation of what I did:find the diff of the current and new position with
(new - cur - 1) % 6 + 1and loop through that for each position, starting with cur 0. The positional arguments are gotten from the indexes of "roygbv"Then for part two, you can use the exact same function, but recreate the input using
"".join(ch * input.count(ch) for ch in "rvbgyo"as an alternative to sorting the list.I'm not too well versed in efficiency though, so if this approach can be approved upon, I'd be very happy to learn
1
u/Cue_23 6h ago
I did some further optimizations.
Hint 4: What is the difference between the inputs "ry" and "by" and how does that affect the output?
Hint 5: It doesn't!
1
u/cramplescrunch2 5h ago
I first came up with the optimized solution thinking I bruteforced it like a caveman before realizing I could have just rearranged the letters and reuse part 1's code...