Aetherus
I couldn’t find a faster solution in part 2, so I just brute-forced my way. I’m looking forward to smarter solutions.
https://github.com/Aetherus/advent-of-code/blob/master/2022/day15.livemd
Trending in Challenges
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lud
I did the same for part 2, took 12 seconds. On reddit someone suggested quad trees, I tried it and I’m down to less than 1.5 second.
On slack someone suggested an even better way (~4 ms) but I’m too lazy to try it
kwando
I didn’t find a smarter way for part 2 either, brute forcing it worked but took a while. I had some idea about calculating how much sensors overlap on a given row and then use that number to skip checking rows, but I didn’t get it to work
Aetherus
I came up with an idea that involves a little bit of linear algebra:
The problem is, there are multiple such gaps
The good news is, there are not so many such gaps. I can just try all the results util I pass the quiz
Here’s my new code:
Aetherus
Quad tree is interesting, though I’m not sure how to solve this quiz with it.
jkwchui
I solved part 1 by brute force.
For part 2, after brute-force not working on 4,000,000 x 4,000,000 (I wonder why?), I thought about “walking the edges”:
The idea is that for each pair of Sensor–Beacon, we can be sure the outlying (solution) beacon cannot be under the red line. Given that within x = 0..4M, y = 0..4M there is only one possible solution, the solution beacon would have to fall under the green line.
More specifically, it should be the point which falls under the most green lines:
So my Part 2 solution is iterating over each sensor–beacon pair to trace the points under the green line (Manhattan distance + 1), and find the most overlap. The code can be further optimized, but I was just happy it worked…
lud
Well to use quad trees at each step I checked if the four corners of a quad (a square) were in range of the same sensor. If yes then the quad is fully covered. Otherwise I would split the quad and check recursively.
At some point you end up with a quad of size 1x1 that is not covered, and that is the solution.
It is not very efficient, but at the time the solution is found there are only 33 different quads in my tree, with my input.
Aetherus
I figured I only need to do some simple filtering then I can get the true result. It takes less than 500 microseconds on my laptop.
stevensonmt
Part 2 just about broke me. Finally got what is basically a brute force method that works fast enough for me. 12-14 seconds to get the answer. I was really struggling, trying to use MapSet operations to track each row rather than a Range. Seeing @Aetherus use of
Range.disjoint/2was a huge help.Aetherus
Actually, using
Range.disjoint?/2was a mistake. Consider this situation, at somey, there are 3 ranges before merging:0..10,11..20,21..30, how many ranges should there be after merging? There should be only one range,0..30. ButRange.disjoint?/2will tell you all those ranges are disjoint to each other, so they won’t merge.stevensonmt
I think it works for this exercise b/c there is no difference between
[{0..30}]and[{0..10}, {11..20}, {21..30}]. Both indicate a situation where there is more than one item remaining. Also contrary to your method of merging ranges, I was sort of breaking the full range 0..limit up into smaller ranges.