Day 4: Scratchcards

AdventuRust - AoC 2023

This is Day 4 of Advent of Code 2023! If you would like to solve the problems before looking at the solution, you can find them here.

In part 1 of Day 4, we're working with strings of numbers, each line has three parts: a card ID, winning numbers in the scratchcard, and our numbers in the scratchcard. This is more of a parsing problem - we need to parse the two sets of numbers and find their intersection. The scoring is defined as one point for the first card and doubled for every card after that, which is essentially 2*(n-1) for n matching numbers as long as n>0 or 0 otherwise. The sum of the scores for each of these cards is our answer. Click here to jump to the part 2 discussion.

For part 2 of Day 4, the count of winning numbers actually tells you how many additional copies of the next scratchcard you get. It sounds a lot more complex than actually ended up being - the main component for part is actually just the loop shown in lines 64-47. What it does is this - for each card n, we're adding "copies of n" copies to each card in the range (n+1..n+winning_entries_in_n). The sum of the values for all the cards gives you the final answer.

That's all folks! If you made it this far, enjoy some AI art generated by u/dimpopo using the prompt for this puzzle.