Skip to content
Froxcey edited this page Dec 4, 2023 · 3 revisions

Day 4 is... Easy again?

This one is not very challenging, but discussing implementation details is still valuable. Hopefully, you have the point of each card stored somewhere, as we will need that information. To tackle this, we can initialize a mutable array with a size equal to the number of cards, with each element having a value of one. This array represents the current numbers of cards, and the initial value of one signifies having one of each card at the start. Next, we iterate through each card. For every card, we add the number of copies of that card (stored in the mutable array) to the next several elements of the mutable array (equal to the number of points on the current card). Also, within the loop, we can access the copies of the current card, allowing us to accumulate them towards the final score. After iterating through every element, we will have the answer. You can view our example implementation in zig.

Clone this wiki locally