AoC 2023, Day 4, Scratchcards
Today’s puzzle is called Scratchcards.
Part 1
I am going to start by creating a type called card to store the information in.
I need to be able to parse the card text, This could be done more elegant, but I’m going to split the string up, and assume there is no problem in the input data.
I can test this on the first row.
Which returns:
I now need to score a card, let me first get the number of winning numbers in my numbers.
I will test this.
Which returns:
I will test this.
Which returns:
I am happy this far, lets pipe it all together and see what we get.
13
is the correct answer for the sample data.
My final answer is also correct, so I earn another gold star.
Part 2
In part two we need to keep track of how many times a card is copies.
I am going to create a very basic record type that will keep the number of matching numbers on a card, and how many copies of this card we have.
I am also creating some functions that will help me track the number of copies we have of each card. In F# items in an array can be changed 1, so I am using that to update the count as we go down all the cards.
I now pipe this together and see what we get.
30
is the value I am expecting with the sample data.
My answer with the complete data is also correct, and I get another star.
-
Changing things is not normally the functional way to do something, but it is the way that makes sense to me in this situation. ↩︎