r/adventofcode • • Dec 12 '23

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

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

Today's theme ingredient is… *whips off cloth covering and gestures grandly*

How It's Made

Horrify us by showing us how the sausage is made!

  • Stream yourself!
  • Show us the nitty-gritty of your code, environment/IDE, tools, test cases, literal hardware guts…
  • Tell us how, in great detail, you think the elves ended up in this year's predicament

A word of caution from Dr. Hattori: "You might want to stay away from the ice cream machines..."

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 12: Hot Springs ---


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:22:57, megathread unlocked!

46 Upvotes

580 comments sorted by

View all comments

2

u/philippe_cholet Dec 12 '23 edited Dec 12 '23

[LANGUAGE: Rust]

My rusty-aoc repo & today' solution here.

I thought I was gonna (temporarily) give up and write a meme (don't refresh the stats page when you are blocked, it does NOT help). 35 minutes to solve part 1 but 5h52 for part 2 (lunch break deduced). And it's not fast: 4.7 seconds for the example and input. I intended to solve all 25 puzzles under 1 second by Xmas, it's surely gone now.

The idea is "divide-and-conquer". From the numbers, I look all places the middle one could take then I have two smaller tasks. Until I have one number and a list of records that can match.

I thought we were gonna have it simple enough until friday and the week-end but no.

EDIT: 0.75 second with rayon.

EDIT 2: 0.48 second with hashmap cache, not rayon. Adopted!

2

u/tialaramex Dec 12 '23

By the way, I'm pretty sure you're using Vec::reserve wrong. The parameter is how many more things you think you might put in the Vec, it already considers its own capacity records when deciding if there's enough room, so you probably just want to reserve(4+4*len) or whatever.

You can't significantly hurt perf with erroneous reserve() calls, whereas reserve_exact() will cause performance problems if used incorrectly - so it doesn't matter much.

1

u/philippe_cholet Dec 12 '23

Indeed, good catch! It won't hurt perf much but I appreciate the correction very much, thanks. It's the second time I use reserve and the second time I make the mistake.