cblavier
Hi, there ![]()
Today, I felt it was way more challenging! I went through part2 thanks to Agent based memoization (without memoization the execution time was
, after it was 3ms
)
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)
Rainer
Yes, morge challenging today, so I didn’t come up with a solution for part 2 yet
Couldn’t decide how I wanna solve it, and then run out of time before work…
Anyway: Heres my part 1 in Erlang:
LostKobrakai
Thanks for mentioning that. I had part 2 working for the examples, but the full input timed out. Then I rebuild it using
:digraphand recursively weighted the edges from the end. This again timed out for the puzzle input but not the examples. Turns out keeping track of the already checked vertexes made the test resolve in 0.1 sec.https://github.com/LostKobrakai/aoc2020/commit/0617012fccbf1446e867cd40f7022a797254c9ba
michaelvigor
I think for part 2 it must be easy to write a solution that never completes. I too have written a function which works for the test input but then never returns for the full input. Time to learn about “Agent based memoization”
cblavier
Sure it’s easy, the full input leads to a combinatorial explosion.
I let my first un-memoized solution running for more than hour, it never completed.
For memoization, you can do it different ways:
milli
For memoization you can use the process dictionary: Process.put & Process.get
camilleryr
You can actually calculate the answer for part two without the need to run any of the possibilities - if you sort your input and reduce that to a list of the number of consecutive digits in a row ( [1, 2, 3, 6] → [3, 1] or [1, 3, 4, 5, 8] → [1, 3, 1]), you can then calculate the number of permutations each ‘block’ will cause and then just find the product of the list
https://github.com/camilleryr/advent20/blob/main/lib/day_10.ex
LostKobrakai
That interesting. I tried something similar by reducing over the list finding certain combinations, where I would know the number of permutations in advance. But i couldn’t really think of a way of handling those combinations while not duplicating/missing other ones “one step futher” into the list.
adamu
Phew. This was tough, glad to see I’m not the only one that was struggling!
I realised that the combinations basically form a graph, where each node inherits the number of combinations from its parents. Wrote up my reasoning in my notes.
Here’s my part 2. It completes in 68 microseconds on my machine. I think it’s pretty obtuse without the explanation
.
listis the input as a list of integers.camilleryr
my permutation calculation would have broken if I needed to calculate the permutations for a longer block of consecutive numbers, apparently it needs to be tribonacci numbers…
mexicat
My solution. Nothing special for p2, just some recursion and
Agentfor memoization.