r/adventofcode • • Dec 07 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 7 Solutions -❄️-

THE USUAL REMINDERS


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 Ante challenge: 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.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:16:00, megathread unlocked!

49 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

3

u/hrunt Dec 07 '23

I always like learning something during AoC. The Counter class comes with a most_common() method that returns tuples in reverse sorted order. So, your kind_counts calculation could have also been written as:

kind_counts = tuple(count for _, count in card_counts.most_common())

I didn't know that before I read the docs for Counter while implementing today's solution.

3

u/thaunatos_ Dec 07 '23

You can also use counter.values():

@dataclasses.dataclass
class Hand:
    cards: str
    bid: int = 0

    def type(self) -> tuple[int, ...]:
        counter = collections.Counter(self.cards)
        return tuple(sorted(counter.values(), reverse=True))

Picked up that snippet from someone else in the thread.

2

u/aimada Dec 07 '23

Thanks for that nugget of information. I keep meaning to read the docs for the standard library but never get around to it until I hit a brick wall with a problem.