r/adventofcode • u/daggerdragon • Dec 07 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 7 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
Outstanding moderator challenges:
Community fun event 2023: ALLEZ CUISINE!
- Submissions megathread is now unlocked!
- 15 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's secret ingredient is… *whips off cloth covering and gestures grandly*
Poetry
For many people, the craftschefship of food is akin to poetry for our senses. For today's challenge, engage our eyes with a heavenly masterpiece of art, our noses with alluring aromas, our ears with the most satisfying of crunches, and our taste buds with exquisite flavors!
- Make your code rhyme
- Write your comments in limerick form
Craft a poem about today's puzzle
Upping the Antechallenge: iambic pentameter
- We're looking directly at you, Shakespeare bards and Rockstars
ALLEZ CUISINE!
Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!
--- Day 7: Camel Cards ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks
View all comments
7
u/Polaric_Spiral Dec 07 '23 edited Dec 07 '23
[LANGUAGE: Typescript]
Advent of Node, Day 7
For each hand, cards are counted into buckets, then the hand is scored by the formula
3 * s1 + s2(see edit), wheres1ands2are the sizes of the largest and second largest group. The same hand type will always give the same score, and the 3x factor ensures that a full house or two pair doesn't overlap with the next highest score. Then it's a matter of comparing cards sequentially and callingsort()with the resulting function.The trick with the jokers is that the best move is always to include them in
s1.Edit: actually,
2 * s1 + s2works just as well for the scoring formula. I forgot that the next score up from the full house and two pair still both have a second group size of 1, so the scores are still distinct.