lud
For part 2 I transformed the map into a graph because I wanted to see it and check if there was a bottleneck point or something.
But no, so I guess the code for P1 would have worked too, the only difference is that I run all possible states 1 step ahead to the next intersection (instead of running just one), and then I keep only the 3000 longest.
https://github.com/lud/adventofcode/blob/main/lib/solutions/2023/day23.ex
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
tywhisky
https://github.com/tywhisky/advent-of-code/blob/master/2023/day_23/solution.exs
This is the optimized solution. In the initial attempt, I employed a regular DFS and made good progress in part 1. However, encountering issues in part 2 led me to refactor part 1, adopting a compressed graph approach (i.e., retaining only intersections in the graph). Despite having only one line of code differentiating part 2 from part 1, part 2 still took 30 seconds to run.
bjorng
According to Wikipedia, the longest path problem is NP-hard. Fortunately, the reduced graph (with all straight-line garden paths reduced into single vertices) is sufficiently small that it is practical to calculate the length of all possible graphs. After optimizing my solution it solves both parts in 16 seconds on my computer.
I assume that there is a divide-and-conquer approach for finding the longest path for this particular graph much faster, but I didn’t pursue it.
https://github.com/bjorng/advent-of-code-2023/blob/main/day23/lib/day23.ex
exists
Like others, parsed the given map into a graph, with vertices being the intersections (plus the start and the end), each path between two intersections being an edge whose weight is the length of the path. Then for part 1 I used Bellman-Ford with negative weights. For part 2 I got lazy to things myself, and employed libgraph’s
Pathfinding.allfunction which calculates all simple paths from the start to the end, and then just found the longest.Part 1 runs in 2.5 seconds (almost all of which is parsing the map - I suppose I do something silly there); part 2 almost 30 seconds.
code
midouest
Similar to everyone else, I built a graph for the map by finding the junctions and the edges between them. I initially thought that I would need to handle both directed and undirected edges for part 1. However, I rendered the map and the junctions with
Kino.HTMLand saw that all of the edges were directed. Funny that my code would have needed almost no changes for part 2 if I had implemented that behavior in part 1!Part 1
Part 2