r/adventofcode • u/Afkadrian • Dec 07 '23
Spoilers [2023 Day 7] An interesting algorithm
I found out that if we find the count of the card that appears the most times and subtract the amount of different cards, the result is unique for each type of hand.
In other words... max_count - different_cards is a discriminant.
For a Rust implementation, check the from_cards function in my repo.
Has anyone else found this pattern?
46
Upvotes
View all comments
Show parent comment
1
u/duckyluuk Dec 07 '23
I made a sorted list of how often unique cards showed up in the hand and then you can use that as your sort index (at least in python, not sure if sorting works like that in all languages) because
[5] > [4, 1] > [3, 2] > [3,1,1] > [2,2,1] > [2,1,1,1] > [1,1,1,1,1]skip jokers while finding the counts, then add the joker count to the first index and sorting works the same as above