5 ms·
Seems to me that people made part 2 harder than it us. Just define an array containing the digits: "one", "two", and so forth. Then check for substring matches,
by bradley13 3y ago
Seems to me that people made part 2 harder than it us. Just define an array containing the digits: "one", "two", and so forth. Then check for substring matches, position by position. Maybe not elegant, but effective.
- Vingdoloras 3y agoI just placed digits in the middle of the words instead of replacing them. This way I didn't "break" any overlapping words, and the order of digits is still the same.
- bauble 3y agoI think the issue is that they tried to separate the input into a list of tokens, like ["5", "nine"], and work from there, which doesn't work on something like "oneight".
- Maxion 3y agoIt's funny how all of us used the `oneight` as the edge case to test our code on...
- jes5199 3y agoI used "eightwo"
- kemyke 3y agoBut a simple replace if you do it like this .Replace("one", "on1e") or .Replace("eight", "eig8ht") Not elegant but still do the job.
- xdavidliu 3y agoI didn't have that issue at all; I just looped through the 20 different tokens and found first and last instances of all of them, and compared the very first and very last of all instances. https://github.com/xdavidliu/advent-of-code/blob/main/2023/day02.cpp https://github.com/xdavidliu/advent-of-code/blob/main/2023/d...