Here's my Part 1, I should be right to tackle Part 2 later... but figured I share what I have to far :smiley:
https://github.com/lukewilliamboswell/aoc/blob/main/2024/09.roc
TIMING:
READING INPUT: <1ms
SOLVING PART 1: 4ms
Here is my part1: https://github.com/ostcar/aoc2024/blob/main/day09.roc
After reading the assignment for Part2, I can say, that my solution for part1 is to clever and can not be used at all for Part2. I have to do Part2 later and remember, not to be clever :face_exhaling:
so are we sure the only way to iterate N times in Roc is via a List.walk
or recursion at the moment yes? no loops whatsoever? :sweat_smile:
for loops are planned #ideas > `for` and `var` @ 💬
So Part 2 is finally done. I am not so happy with it and it took too long to write. There are probably better solutions:
On an optimized build:
part1 in 4.347ms
part2 in 1.52s
Well I give up. Can't pass part 2 even if the example checks out. Plus the mental gymnastic today was exhausting. Can't win em all. https://github.com/thenikso/advent-of-code-2024-roc/blob/main/09.roc
Nope! attempted a new solution inspired by Oskar and got it https://github.com/thenikso/advent-of-code-2024-roc/blob/main/09bis.roc
Day 09 part 1: (Ok ...) [1428ms]
Day 09 part 2: (Ok ...) [11559ms]
would not recommend :sweat_smile:
I had a very frustrating time today too. It's really a problem that feels tailor made for a mutable imperative approach. (Nothing wrong with that ... but it runs against the grain of an immutable functional language). On an optimized build, Part 1 in 3 ms and Part 2 in 634 ms. But it's just very naive: a dreary recursive version of an imperative program endlessly walking a list, and pretending it's mutable, more or less.
Header
https://gist.github.com/PaulStanley/4a48ddb3e8e9c05b050b3cb032222e69
No spoilers!
Hiding any spoilers, here's my day 9: https://github.com/Enkidatron/advent-of-code-2024/blob/main/day9.roc
(I'm not using the aoc framework package because I'm doing this to learn Roc and I don't want to use the framework until I understand what it's doing. My Roc is probably not idiomatic for the same reason. )
Part 2 thoughts
The complaints and perf issues here make me feel like I should solve it or at least investigate if the perf issues are roc primitive related or algorithmic
Performance information: using roc dev day9.roc
, my part 1 is consistently 16ms and part 2 is 1580-1650ms.
(I have learned enough to duplicate how the aoc framework was doing the timing)
You also can get performance using an optimised build with --optimize
I usually do
$ roc build --optimize app.roc
$ ./app.roc < input.txt
But you can also do
$ roc --optimize app.roc < input.txt`
Luke Boswell said:
I usually do
$ roc build --optimize app.roc $ ./app.roc < input.txt
But you can also do
$ roc --optimize app.roc < input.txt`
I don' understand way, but in my cases, the first one is much faster. For example for this day:
$ roc --optimize day09.roc
part1 in 36.136ms
part2 in 12.133s
$ roc build --optimize day09.roc && ./day09
part1 in 3.892ms
part2 in 928.913ms
did we ever fix roc ...
ignoring the optimize
flag?
My guess is no based on the comment above
Also, I'm almost done with my own implementation before I'll look at perf of others. I have part two working for the example, but a bug with the full run...
Here is my implementation: https://gist.github.com/bhansconnect/0c457a377473f9c80237d26751fa7fe7
I probably should have started with a more naive solution instead of a more optimized one...
I'm sure there is still room for improvement, but hard to tell exactly what without better debug info.
$ /tmp/aoc-2024/day8/main
Part 1: ... -> 2ms
Part 2: ... -> 8ms
EDIT: manage to cut off 2-3ms from part 2 by avoid a List.range
and using a recursive walk instead. So now at 5-6ms
Later today I'll start looking at the other solution to try and figure out if any roc perf sharp edges are leading to major perf drops. Not sure how much of this is implicit to certain solution vs due to roc cloning way too much or similar.
fix for roc --optimize day09.roc
: https://github.com/roc-lang/roc/pull/7326
Claude is struggling with this one...
Makes sense
It was eventually able to solve part 1 in one shot:
SOLVING PART 1: 288ms
Main prompt additions for this one :
- Roc does not use `head :: tail`, use `[head, .. as tail]` instead. Make sure you do not forget the `as`!
- Roc does not have currying.
- You can not pattern match directly on booleans. Avoid using Bool.true and Bool.false in general, it is better to use descriptive tags, for example `HasNoExtraLine` and `HasExtraLine`.
- Roc does not allow shadowing.
I'm giving up on part 2 :sob:
It's definitely a good benchmark to try to improve the prompt for in the future.
prompt-aoc-9-part2.txt
Luke Boswell said:
I usually do
$ roc build --optimize app.roc $ ./app.roc < input.txt
Thanks! The optimized day9 takes about 8ms and 650ms, which feels like an impressive speed up to me, a roc beginner. The compiler is definitely smarter than I am at making that code run fast.
This was definitely one where the optimizer did it's thing
Using Roc Run:
Part 1: 6401092019345 [26000ns]
Part 2: 6431472344710 [1000ns]
Using optimized build:
Part 1: 6401092019345 [1000ns]
Part 2: 6431472344710 [0ns]
https://github.com/gamebox/aoc-2024/tree/main/day9
It also is NOT a problem for functional languages :-)
Your timing is broken
Context is the last two messages in day 8 of aoc
It's due to some sort of roc bug with !
on task
I’ll fix it and remeasure
Is it only for optimized builds?
Either way I’ll check it out after work
For both I think
I think we desugar in a way that reorders things wrong
Last updated: Jul 06 2025 at 12:14 UTC