AdventOfCode2023/src/SOLUTUION

3 lines
968 B
Plaintext
Raw Normal View History

This one was super fun - I really enjoyed it. I defined two enumerated types: one ordered lowest to highest for the card ranks, and another ranked lowest to highest for the hand ranks. The real meat of the code is in function that evaluates the rank of a hand: I used a hash map to build a histogram of each hand, then used the card counts to determine what kind of hand I had for Part 1. I then fed this into a comparison function that compared the ranking of two hands to determine less, equal, or greater, and then fed that to the standard sort function to rank the entire vector of hands and their associated bids. It was then trivial to iterate over the sorted vector to multiply the ranking of each hand with its bid and add it to the sum.
Part 2 was slightly harder, just reworked the card ranking to make the wildcard the lowest ranked card, then reworked the logic in the hand ranking function to take into account the presence of any wild cards in the hand.