Here's my solution :smiley:
https://github.com/lukewilliamboswell/aoc/blob/2024/2024/01.roc
TIMING:
READING INPUT: <1ms
SOLVING PART 1: <1ms
SOLVING PART 2: 1ms
And here is mine: https://github.com/ostcar/aoc2024/blob/main/day01.roc
I like your diffing impl
https://github.com/isaacvando/aoc/blob/main/2024/1.roc :evergreen_tree:
Probably not the most elegant but it works :smile: https://github.com/RobinCamarasa/Advent-of-code/blob/master/2024/day01/RobinCamarasa/main.roc
Got it done too, after a few hours of submitting PRs and debugging things :joy:
https://github.com/faldor20/aoc-template/blob/purity-inference/examples/2024/01.roc
am i allowed to post non-roc code :smile:
Here my solution: https://github.com/Hardy7cc/aoc/blob/main/2024/01.roc
But watch out I don't understand why the part2 "Ok String" return is crashing. For AoC it is working good enough with returning an "Err", after all I got expected results.
drew said:
am i allowed to post non-roc code :)
So long as it's not in a language that makes me want to weep with boredom :sweat_smile:
Should we post AoC-inspired bugs / compiler improvement ideas here or in #bugs ?
My late entry: https://github.com/r-bar/advent24
Probably in #bugs. Though please be careful not to leak AOC solutions directly in #bugs. Make sure they are behind a link and directly labelled as AOC. Or even better, make a repro that doesn't spoil AOC.
my GOSH doing day 1 is reminding me how much I love coding in Roc
Here's mine https://github.com/ghigt/advent-of-code/blob/main/2024/roc/01.roc
Feedback on the feeling on writing Roc code:
dbg
is very helpful but the output is a bit confusing at first(These are my small frustrations, thank you for all the work, it's a much better experience than the previous years!)
Any extra detail on the dbg
comment? Anything that would make it more friendly?
I used it inside a pipeline and it was a bit hard to parse the output because it contained all the pipeline as variable name before =
.
✗ roc test 01.roc
[01.roc:53] map.0
|> List.map \n ->
map.1
|> List.keepIf \nn -> nn == n
|> List.len
|> Num.toI32
|> Num.mul n = [9, 4, 0, 0, 9, 9]
0 failed and 2 passed in 529 ms.
It may be only me and my use case but I would have prefered only the line of file for a more concise and simpler output (even more when it's inside a loop). I may be wrong and don't see all the use cases it allows though.
It took me hours to get it running :sweat_smile:. Sharing the code would be even more embarrassing :big_smile: , but hey, it was super delightful using Roc, I learned a lot and can’t wait for day 02. :heart_kiss:
here's day 1 in gleam :stuck_out_tongue: but i'll probably do tomorrow in roc
https://github.com/drewolson/aoc-gleam/blob/main/src/aoc/year2024/day01.gleam
here's my day 1 roc https://github.com/drewolson/aoc-roc/blob/main/Aoc/Year2024/Day01.roc
Ghislain said:
- A bit frustrated about the editing experience (using Zed) with too much "reload workspace" because of a broken parser
Hey, I agree that's a pain, but I think I finally fixed all the language server crashes in this pr:
https://github.com/roc-lang/roc/pull/7288
Hopefully it'll be merged very soon and you will be sorted :)
yep that’ll be awesome if it merges
@johannes @drew I his is merged! Hopefully you can update and day 2 will be way better!
Thank you Eli for fixing that
awesome! hopefully a new release is cut soon!
looking forward to using it
:partying_face:
https://gitlab.com/JanCVanB/aoc-2024/-/blob/main/day-01/part-1/main.roc
https://gitlab.com/JanCVanB/aoc-2024/-/blob/main/day-01/part-2/main.roc
This is my first time using expect
. :loudspeaker: Roc has better TDD flow than I've ever felt in other languages. I haven't used other newer or FP-centric languages, though.
The only things I tripped over were some awful error messages when getting my first main
set up, like these:
Screenshot from 2024-12-01 11-14-07.png
Screenshot from 2024-12-01 11-17-07.png
What's wrong with that fiest message? Looks ok to me
"Something is off with the body of this suffixed statement" instead of something like "Please assign the return value of this valid mid-function expression to a variable"
(dismissed by adding foo =
in front of that line or adding |> foo
on the next line)
posted in https://roc.zulipchat.com/#narrow/channel/463736-bugs/topic/Lame.20error.20message.20-.20.22Something.20is.20off.22/near/485566360
(deleted)
awesome! hopefully a new release is cut soon!
done :)
with the new release, i no longer have LSP errors on my files, but the LSP seems to now do nothing on these files. no hovers, no autocompletion, etc
Can you see if there any useful messages in the logs?
looking
i see a lot of this:
[ERROR][2024-12-02 07:42:55] .../lean/stderr.lua:80 "rpc" "/Users/drew/.local/bin/roc_language_server" "stderr" "thread 'tokio-runt ime-worker' panicked at crates/language_server/src/analysis.rs:301:71:\ncalled `Option::unwrap()` on a `None` value\nnote: run with ` RUST_BACKTRACE=1` environment variable to display a backtrace\n"
analysis.rs:301 is also involved here, can you add your code to that issue? That way we can make sure a future fix works for both cases.
done
So if the compiler is crashing there will be no errors until whatever is crashing the compiler is fixed. But that also looks like a different issue which I can definitely fix
As in, you make a code change to no longer make your code crash the compiler
i'm in neovim, :LspInfo
shows the LSP still running
so it seems attached to the buffer
but i'm getting no interactive behavior
interactivity does indeed work in main.roc
anecdotally, it seems to work on singly-nested modules but not doubly-nested
scratch that, i don't know why it sometimes works
things still work in the Aoc/Runner.roc
file for me
but no other nested files
ah, wait, it also works on the Aoc/Runner/*.roc
files. i am at a loss as to why
@drew if you send me a link to your repo I'll try to reproduce and fix this tomorrow:)
https://github.com/drewolson/aoc-roc
okayyy, This is much harder than an unwrap. I think you'll find if you run roc check
against the files that are causing the lsp to not work, they will also crash. I'd be extremely surprised if this is new as of my latest changes to the language server
Using the debug build I was able to get some more info. It's related to not have dependencies resolved by the time we expect them to be. The weird thing is that the dependencies are form List.roc which has no dependencies.
I let claude do all the work, it is getting impressively good at Roc :mind_blown:
Literally the only things I had to fix:
Str.split
to Str.splitOn
claude-solution.roc
prompt.txt
For the prompt I just gave it three examples from AoC last year and a list of commonly used Roc functions.
Anton said:
I let claude do all the work, it is getting impressively good at Roc :m
The way you pass in all the function signatures in the context reminds me of that Mirror language that was doing the rounds on hackernews a couple weeks ago. Pretty cool it got so close.
https://github.com/alsm/aoc-roc/blob/master/2024/01.roc
Literally the first thing I've written in roc so if anyone has any time to look at it and give any hints on things I could improve or should do differently I'd appreciate it, but either way happy just to make it work :D
... reminds me of that Mirror language ...
Interesting!
Al S-M said:
https://github.com/alsm/aoc-roc/blob/master/2024/01.roc
Literally the first thing I've written in roc so if anyone has any time to look at it and give any hints on things I could improve or should do differently I'd appreciate it, but either way happy just to make it work :D
Hi! I'll gladly do a quick review for you:
IIRC as a convenience, you can use |> List.map .first
instead of |> List.map (\x -> x.first)
. Kinda like how you can replace List.map2 left right (\a, b -> Num.absDiff a b)
with List.map2 left right Num.absDiff
To my taste, this line is getting quiet long, breaking it up would make it more readable
Ok (Num.toStr (List.map nums (\x -> x.first * Result.withDefault (Dict.get similarity x.first) 0) |> List.sum))
If you've just began learning Roc, you shouldn't really worry about this, but and interesting thing about consider:
nums
|> List.map (\x -> x.second)
|> Set.fromList
|> Set.toList
|> List.map (\x -> (x, List.countIf nums (\y -> y.second == x)))
this snippet transforms the nums list a bunch of times. Now, I don't know what happens to the list under the hood, when you turn it into a set and back, so let's ignore that part. It's likely makes my advice on optimization irrelevant in this case, but in general, if you transform a list a bunch, it's a good idea to find a solution where you don't have to reuse the original list later on. If you can do that, the reference count of the list will stay 1, so it can be mutated in place (we call it opportunistic mutation), instead of coppied.
If you've used rust or a language with move semantics, that is the style the roc optimizer likes! But ofc, it can be a lot of hassle.
Congrats on your first Roc code! I didn't even know Num.absDiff
was a thing :big_smile:
Separately:
Here is my solution: https://github.com/HajagosNorbert/advent-of-code-2024/blob/a4b36172966dd519e107d3a395cb5cc6efdc41d5/Day1.roc
Posting cuz part2 solution can be interesting. Using 1 Dict to store the left and right occurences in a tuple, then walking the dict to sum up the key*value.0*value.1
.
Last updated: Jul 06 2025 at 12:14 UTC