maennchen
Ok, that was a rough one today.
I haven’t found a way to improve the algorithm further. Part 1 runs in .5 seconds, Part 2 in ~ 5 minutes.
https://github.com/maennchen/advent-of-code/blob/main/2022/16/1_depressurize.exs
https://github.com/maennchen/advent-of-code/blob/main/2022/16/2_depressurize_with_elephant.exs
I went the way of precalculating all possible paths between non-zero flow rate valves using :digraph.get_short_path/3. Then I recursively calculate the best step. That works find for 1 actor / 30 iterations. For 2 actors / 26 iterations, that is however still a bit much.
Does anybody have a prettier solution?
Trending in Challenges
Other Trending Topics
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
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
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kwando
This one was annoying to get right..


Part 1 is more or less instant, part 2 is super duper slow. Would probably work to memoize some computations, but I just let it run embarrassingly long instead, ~30min
https://github.com/kwando/AoC2022/blob/main/16/day16.livemd
lud
I have this solution that runs in 5 or 10 seconds according on how much you want to cheat.
Here I have the correct solution in 5 seconds with keeping the
50_000best paths but ymmv.Oh and I did not refactor so it is ugly
https://github.com/lud/adventofcode/blob/main/lib/solutions/2022/day_16.ex
stevensonmt
n/m I’m calculating the pressure relief accumulator wrong.
stevensonmt
For part 2, has anyone figured out a way to have the two workers asynchronously search for valves to open? I thought if I cached the state of the valves and the pressure relieved at each minute in an ETS table I could just run the solution to part 1 with
[1,2] |> Task.async_stream(fn _ -> do_part1(graph, time) end)but I keep getting an incorrect and inconsistent result:When Solve.part_2 finishes the last call is to destroy the ETS table so artifact from previous runs is not the cause of the variance. I’m assuming it’s a race?
stevensonmt
Okay, I finally got a version that completes in a reasonable time for part 2 (albeit still pretty slow). I refactored everything to reduce the amount of code even though this version is slower for part 1 than my original version (or at least it seems that way, did not benchmark it). I am not too proud to admit I had to read a LOT of solutions from others over in the big reddit thread to get a sense of how to approach this. I ended up almost just translating a solution from rust into elixir, which you can probably tell by the use of arrays and bitwise tricks.
My supposition that this was a concurrency problem was way off. It was more a complementary sets problem and probably even better a dynamic programming problem (even though my solution is not really DP).
Anyway, this one pretty much ruined me and I’m probably done for the year. Sad to not get as far as last year though still happy to have learned a lot.
https://github.com/stevensonmt/advent_of_code/blob/2022/2022/day16/lib/day16.ex
tfwright
This one stumped me. I understood right away it was a path finding exercise, but the detail I can’t wrap my head around is “skipping” valves, as in minute 3-4 in the example. Is the idea that you have to add edges, not just from each valve to its neighbors, but each valve to every other valve, with some sort of cost multiple to account for distance?
stevensonmt
I think the general idea for the path-finding is to only consider paths from valuable valves to other valuable valves. I haven’t seen anything more clever than just depth first searching from each possible initial path to a valuable valve and returning the optimal full path. In my solution that’s this bit:
tfwright
Skipping the zero flow nodes is an easy bit of optimization, but I think the problem with my algo was that it was not looking ahead to see if best next segment leads to the best path overall (so in testing it goes to straight to JJ instead of DD as expected). Still not sure how your func is handling that.
Mine:
stevensonmt
My function is checking from AA to each target valve. Then from each target to each remaining target recursively until all targets have been reached or time is up, taking the max value for each full path.
tfwright
Yeah my function isn’t actually searching all paths. Still getting the hang of recursive search functions I guess