r/adventofcode • • 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

38 comments sorted by

View all comments

Show parent comment

1

u/wherrera10 Dec 07 '23

I sorted the counts and took 2 times the largest plus the second largest count as a discriminant (results in a number between 3 and 10). A full house is 8, three of a kind 7 that way.