rugyoga
Most Liked
lud
Yes I thought it would be slow because for part 2 I modify the free blocks list not only at the head, but lower in the linked list.
But I guess while slow, linked lists are highly optimized in Erlang.
I’d suggest you run my solution on your machine though. I know that @bjorng uses the time reported by mix test for instance. I use :timer.tc in my helper commands so it’s going to report lower times.
bjorng
It took me a long time to find an off-by-one error in part 2. The combined runtime for both parts is 0.4 seconds.
billylanchantin
lud
My solution takes 11 seconds adventofcode/lib/solutions/2024/day09.ex at main · lud/adventofcode · GitHub
I have an entry in the disk (a map) for each block. I will see if I can keep all contiguous file parts as a single map entry.
sevenseacat
No. The example ends with 402 so there’s 4 eights, 0 gap, and 2 nines.
What does your code here advent_of_code/lib/2024/day_9/Part1.ex at master · jarlah/advent_of_code · GitHub do if n2 is zero?
Your 90909 example is also wrong - it should be 000000000111111111222222222. The description says:
A disk map like
90909would represent three nine-block files in a row (with no free space between them).







