antoine-duchenet
Everything went smoothly today.
Nothing to change to solve part 2 because I already used memoization for part 1 (it looked like an AoC exercise where it would be useful
).
Here are the main parts :
defp blink([_], 0), do: 1
defp blink([0], steps), do: blink([1], steps - 1)
defp blink([h], steps) do
Performance.memoize({h, steps}, fn ->
case should_split?(h) do
{true, split_params} -> split_params |> split() |> blink(steps - 1)
_ -> blink([h * 2024], steps - 1)
end
end)
end
defp blink([h | tail], steps) do
blink([h], steps) + blink(tail, steps)
end
Part 2 takes ~100ms ~70ms to run.
A virtual part 3 with 1000 blinks instead of 75 takes “only” ~5475ms to run.
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)
Flo0807
My solution using ETS. It takes 56.94 ms for Part 2 with a clean cache.
Aetherus
I used libgraph yet again!
The graph building part:
The problem solving part:
mexicat
Once I had coffee and realized that order doesn’t matter I just used plain old
Maps:https://github.com/mexicat/aoc-2024/blob/main/lib/aoc/day_11.ex
Part 1 runs in ~700μs, part 2 runs in ~40ms.
Aetherus
I was stupid. I don’t need a graph.
jarlah
this goes for part and part2, uses same code
https://github.com/jarlah/advent_of_code/blob/master/lib/2024/day_11/Part1.ex#L10
1-2 seconds for part2 (or less with release …)
PS! i hate repeating code blocks like expanding tuples and building them up again, so i have gotten REALLY fond of lambdas … the beauty of is that you must use all lambda parameters . unless you get compile error …
btw when it comes to 40ms or whatever for run times, do people run the solutions in a non test environment or release or something? because im running mix test with doctests .. so maybe could shave off a second or two just for that
EDIT:
_build/prod/rel/advent_of_code_2024/bin/advent_of_code_2024 eval “:timer.tc(fn → AOC2024.Day11.Part2.Solution.solution(AOC2024.Day11.Input.input()) end) |> then(&Kernel.elem(&1, 0) / 1_000) |> IO.inspect()”
299.952
300ms for 75
1382.429 ms for 150
19452.847 ms for 1000
think i need to look at the o notation for this algo
EDIT: its not increasing linearly, i can say that for sure .. O(n^2) maybe .. perplexity suggested O(stones * max_value * log(max_value)) .. i rewrote it from O(n * m * log(m))
sevenseacat
For run time checking, I use benchee. Each of my AOC modules has functions called
part1_verifyandpart2_verifythat run the full solution without arguments, and those are what I benchmark.https://github.com/sevenseacat/advent_of_code/blob/main/lib/advent/day.ex#L18-L50
As for today’s solution, I remembered seeing something veeeeeery similar before so used the same technique here. Order doesn’t matter - only the count of each stone matters as they’re all totally independent of each other.
https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2024/day11.ex
lud
A slow (1 sec) solution before optimization using only a lists of
{value, count}for each type of stone.Edit:
Optimization with memoization and using a map instead of an ordered list (44ms on average)
lud
I love how the text insists on the stones being on a perfectly straight line.
heinsaris
Here is my solution for Day 11 using a Map to keep of the frequencies for each stone at every level. I kept everything as strings except when I needed to multiply or remove the leading zeros.
Part two solves in 0.2 seconds (using Livebook v0.14.4 on a 13" MBP 2018 with a2.3Ghz Intel i5 processor and 16Gb RAM).
All remarks and or suggestions for improvement are welcome!
sevenseacat
Oh yes, and even when stones are replaced, they always stay in the same order! Makes you think that order is important