Skip to main content

Day 14: Chocolate Charts

· One min read

This problem was similar to the Marble Game on day 9, so I started with a solution similar to the one I used for that problem, using a linked list and having the two elves as linked list nodes that can move along the list. It worked fine for the first part of the problem, but started running pretty slow for the second part of the problem.

For the second part of the problem, I ended up reverting to a simple string building technique and keeping the two elves as indexes on that string. This works because each recipe has a score of only a single character. Even with this string solution, I had to add another string containing only the last couple of recipe scores inserted to reduce the checking time against the given input. Even with this, my code takes about 7 minutes to find the solution. I might come back to this one to try and optimize it a bit more.