DEV Community

Discussion on: AoC Day 14: Chocolate Charts

mustafahaddara profile image
Mustafa Haddara

The other tricky part is that we don't know how many digits are added to the array each iteration, so we can't assume the target string is right at the end. We know it is near the end though, so I therefore search for the target string from 5 characters before the old end to the new end of the array.

This bit me too at first, but then I realized you only ever need to check the very end or offset by one character. This is because you can only ever add 1 or 2 digits to the end of the array!

neilgall profile image
Neil Gall

You're right. So I could have optimised a tiny bit more by starting at oldLength-4.

Anyway I quite enjoyed today's low-level one after aiming to do them all in a mostly functional style up to now. Takes me back to my years doing embedded C and Linux device drivers.