bjorng
Erlang Core Team
This was surprisingly easy.
After a quick attempt to use digraph, I implemented by own straightforward algorithm to find the groups. To my surprise, I didn’t need to do any optimizations to solve both parts. The combined runtime for solving both parts was 2.5 seconds.
I then added an optimization to keep track of the size of largest set seen so far and quickly discard any sets smaller than that number before checking for connectedness.
That reduced the runtime to 0.2 seconds.
https://github.com/bjorng/advent-of-code/blob/main/2024/day23/lib/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 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
antoine-duchenet
Pretty similar solution here (at least for part 2), even without further optimizations (I use simple lists and maps) it solves part 2 sub 500ms:
@bjorng I see this in your code:
Is there any reason you do not use the third argument of
Enum.group_by/3to transform the values ?bjorng
Not really. I just didn’t think of doing that.
rvnash
Another fairly easy day. Decided to do part1 and part2 by just getting all valid networks first, and filter them later. It was taking about 8 seconds. Then added a filter function to pick out only the valid combinations on the fly, and that helped.
https://github.com/rvnash/aoc2024/blob/main/lib/d23.ex#L63
Then, taking advantage of the knowledge I gained yesterday about Atom being the fastest type of key for a Map, converted the computer names to atoms and got 3X faster. Final results are ~110ms for both parts on my M1 Mac.
lud
I got it easily too but my solution was to build all possible networks of 3, then try to add the compatible candidates to get networks of 4, then 5, etc..
It takes 1.5 second with optimizations.
I’m trying to understand your code @bjorng but it seems that you do only one pass, there is no loop. The flat_map_reduce seems to iterate over a predefined list, which is puzzling me.
bjorng
The
flat_map_reduceiterates over the map of all connections for each computer. For the example it looks this:For each computer, all possible sets that the computer is part of is constructed. There will be a lot of duplicate sets in the combined list, but
Enum.uniqgets rid of them. That approach was my first stab at solving the problem. All I aimed for was a correct solution that I then could optimize. It surprised me that it was that fast. For once, a pleasant surprise!lud
Alright ok so:
I would not have think this was the fast way haha
Thank you
liamcmitchell
Another one that took a long time to reason about and even longer to get working around xmas distractions.
My part 2 runs in 100ms on my 2013 MBP so I’ve prob done something different.
For each node I sort all linked nodes by the number of times they are linked to each other. Then reduce the sorted list into the largest set by adding each node if it links to all existing nodes in the set.
https://github.com/liamcmitchell/advent-of-code/blob/6227b6dd61e22568ad110332b85d8ec03561ebad/2024/23/1.exs#L45-L68
rvnash
Nice. I wondered if building up the sets rather than staring w/ all combinations and filtering them down would work faster.
ken-kost
Can somebody help me figure out why my naive attempt is wrong.
I create a map where key is each computer and value is a map set of other computers connected to that computer.
Then for each element of value for a key value pair I get the values by using that value as key, and I filter under condition
key in other_values and other_value in valueswhich would mean they are connected; or so I thought.For test example I get same result as instructed:
and the filter/count returns
7.But for real input it’s wrong. I would like to now why is my approach wrong. I’m missing something but I can’t figure out what.
glomph
Ignore me I didn’t read carefully