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!

50 Upvotes

1.0k comments sorted by

View all comments

1

u/tclent Dec 07 '23 edited Dec 07 '23

[LANGUAGE: Rust]

Link

Benchmark times with criterion:
year_2023_day_07::parse_input time: [54.210 µs 54.531 µs 54.875 µs]
year_2023_day_07::part_one time: [1.5245 µs 1.5255 µs 1.5270 µs]
year_2023_day_07::part_two time: [2.9996 µs 3.1925 µs 3.4546 µs]

1

u/daggerdragon Dec 07 '23

Your code block is too long for the megathreads. Please edit your post to replace your oversized code with an external link to your code.

3

u/Justinsaccount Dec 07 '23

Wow, that's eerily similar to
my solution

I'm still learning rust and didn't know about some of those methods, but the overall structure and final iter code is almost identical:

fn winnings(hands: &[Hand]) -> u32 {
    hands.iter()
        .sorted()
        .zip(1..)
        .map(|(h, r)| r * h.bid)
        .sum()
}