r/adventofcode • • Dec 15 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 15 Solutions -πŸŽ„-

THE USUAL REMINDERS


--- Day 15: Beacon Exclusion Zone ---


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:27:14, megathread unlocked!

48 Upvotes

760 comments sorted by

View all comments

1

u/udoprog Dec 15 '22 edited Dec 16 '22

Rust

Well, after too many false leads here it is. Still suspiciously free from allocations. I said that yesterday was the slowest one that I've implemented so far but I take it back. Today is the day:

info: warming up (100ms)...
info: running benches (400ms)...
count: 2, min: 266.0307ms, max: 266.3403ms, avg: 266.1855ms
25th: 266.0307ms, 50th: 266.3403ms, 95th: 266.3403ms, 99th: 266.3403ms

Still pretty happy with the timings, I'll be considering potential optimizations over the day so we'll see what's what (Maybe each row +/- 2 can help when calculating distances). I'm happy with how the implementation turned out though.

Repo Link.

EDIT: To briefly describe the implementation: For each line, construct a sorted set of spans which are covered by beacons, these are iterated over to find a gap which is our x.

1

u/daggerdragon Dec 15 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable on old.reddit and many mobile clients; it's all on one line and gets cut off at the edge of the screen because it is not horizontally scrollable.

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box.

1

u/IAmAHat_AMAA Dec 15 '22

What kind of machine are you running your benches on? Because I frankly found them completely unbelievable when merely computing the spans (not even doing anything with them!) took 3.5s on my machine (i5-1240p) so I ran yours locally and got

info: warming up (100ms)...
info: running benches (400ms)...
count: 1, min: 16.6052092s, max: 16.6052092s, avg: 16.6052092s
25th: 16.6052092s, 50th: 16.6052092s, 95th: 16.6052092s, 99th: 16.6052092s

1

u/udoprog Dec 15 '22

My CPU is an i9-9900K

Are you running in release mode?

In debug I get this cargo run -p y2022 --bin d15 -- --bench:

count: 1, min: 7.5585477s, max: 7.5585477s, avg: 7.5585477s
25th: 7.5585477s, 50th: 7.5585477s, 95th: 7.5585477s, 99th: 7.5585477s

Release cargo run --release -p y2022 --bin d15 -- --bench:

count: 3, min: 195.666ms, max: 196.0041ms, avg: 195.780633ms
25th: 195.666ms, 50th: 195.6718ms, 95th: 196.0041ms, 99th: 196.0041ms