Stream: advent of code

Topic: 2023 Day 1


view this post on Zulip Luke Boswell (Dec 01 2023 at 06:49):

Here is my solution for day 1.

why it took me so long

view this post on Zulip Anton (Dec 01 2023 at 10:19):

Looks clean :star:

view this post on Zulip Johan Lindskogen (Dec 01 2023 at 10:57):

Here is mine! https://github.com/lindskogen/advent-of-code-2023/blob/main/day01/main.roc

I struggled a lot with part 2 and eventually looked at the subreddit to find this dead-simple solution.

Now I need to re-read yours again, @Luke Boswell until I understand it!

view this post on Zulip Luke Boswell (Dec 01 2023 at 11:00):

Nice, I've never seen List.findFirst before, looks really useful for this problem.

view this post on Zulip joshi (Dec 01 2023 at 11:54):

Tried Roc for advent of code and immediately hit a compiler/runtime bug in part 2, where it mutates some shared memory I think in combination with tail recursion? :cry: That's what I get for thinking I don't need to know all the List.walk invocations :big_smile:

Otherwise, I'm pretty happy with that: https://gitlab.com/arkandos/aoc/-/blob/2023/solutions/day1.roc?ref_type=heads
It's not the fastest solution, but it turned out pretty concise I think (also maybe I abuse backpassing to much? but it's so cool!)

view this post on Zulip joshi (Dec 01 2023 at 11:55):

reproduction

view this post on Zulip Oskar Hahn (Dec 01 2023 at 12:13):

Here is mine: https://github.com/ostcar/aoc2023/blob/main/days/day01.roc

For me, it was the first time to actually write some roc code. So it was a lot of reading in the builtin documentation.

Some Questions

view this post on Zulip John Murray (Dec 01 2023 at 14:36):

Heres mine! https://github.com/JRMurr/AdventOfCode2023/blob/main/roc/D01/Day.roc

I struggled a lot with part 2 and eventually looked at the subreddit to find this dead-simple solution.

"optimal way"

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 15:00):

https://gitlab.com/AsbjornOlling/aoc2023
Here is mine... I spent longer with this than I will ever admit.
Mostly just getting familiar with roc stuff, I suppose. The algorithm I came up with worked as soon as I could figure out what symbols to type in what order :sweat_smile:

It's way more verbose than it needs to be, but hey.
Now I'm gonna go look over it and try and make it small and pretty and readable.

Also this was the first time I wrote more than 5 lines of roc code.

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 15:04):

Roc feels pretty comfy so far. I got some weird errors along the way, but eh once I reformulated myself a bit and double-checked my types, stuff started working again.
I struggled a bit getting dbg to work - turns out I just needed to update basic-cli to 0.7.0

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 15:14):

joshi said:

Tried Roc for advent of code and immediately hit a compiler/runtime bug in part 2, where it mutates some shared memory I think in combination with tail recursion? :cry: That's what I get for thinking I don't need to know all the List.walk invocations :big_smile:

Any chance you have or can make a repro? That seems like a pretty major bug that I'm sure many people here would love to look into.

view this post on Zulip Anton (Dec 01 2023 at 15:18):

Repro is here

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 15:32):

Oh, I'm blind sometimes...

view this post on Zulip Elias Mulhall (Dec 01 2023 at 16:15):

@Oskar Hahn https://roc.zulipchat.com/#narrow/stream/231634-beginners/topic/string.20manipulation.20questions/near/405394581

view this post on Zulip Pearce Keesling (Dec 01 2023 at 17:42):

https://github.com/keeslinp/AoC2023/blob/main/day1.roc

Sounds like I'm not the only one

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 18:52):

https://github.com/bhansconnect/roc-aoc-2023/blob/main/day1.roc

view this post on Zulip joshi (Dec 01 2023 at 18:55):

I also made an issue now here: https://github.com/roc-lang/roc/issues/6139 :smile:

view this post on Zulip Oskar Hahn (Dec 01 2023 at 19:01):

Brendan Hansknecht said:

https://github.com/bhansconnect/roc-aoc-2023/blob/main/day1.roc

I tested some of the solutions in my platform to test for speed. Yours is the first one, where part2 is faster then part1 :grinning_face_with_smiling_eyes:

Part1 in 17.635ms:
XXX

Part2 in 10.552ms:
XXX

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 19:10):

haha nice! That makes senses looking at the code. Though I guess I could speed up part 1 by copying code from part2

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 20:05):

For those working on AOC, please add your repos to the roc-lang topic on github.

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 20:05):

Helps us track how close we are to 200 repos, which is one option for the requirement to get github syntax highlighting

view this post on Zulip joshi (Dec 01 2023 at 21:04):

Gotta move to github then!

view this post on Zulip Jason Hobbs (Dec 01 2023 at 21:22):

TIL you can import txt files as a variable!

I'll also add to Github topics before AOC is done.

Here's My Day 1

view this post on Zulip Axel (Dec 01 2023 at 22:18):

Looks like most of us worked based of the same example :sweat_smile:
Here is my solution that looks very similar to everyone else's

view this post on Zulip Elias Mulhall (Dec 01 2023 at 22:58):

Don't worry, I deliberately did something convoluted and it turned out even worse than I thought it would!
https://gist.github.com/mulias/9b963ac61fd25426b8b519633ffcd40e

Bad decisions

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 23:01):

Yeah, I thought the same for the gotcha

view this post on Zulip Luke Boswell (Dec 01 2023 at 23:03):

@Axel I like your digitParser : Parser (List U8) (Result Nat Str) that looks like a nice way to do that

view this post on Zulip Axel (Dec 01 2023 at 23:05):

I was looking for a Maybe type and when I didn't find one this is what I ended up using :see_no_evil:

view this post on Zulip Elias Mulhall (Dec 01 2023 at 23:12):

@Axel I just looked at yours and we actually did the same thing, but I like your version more :laughing:

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 23:14):

https://github.com/roc-lang/roc/blob/main/FAQ.md#why-doesnt-roc-have-a-maybe-or-option-or-optional-type-or-null-or-nil-or-undefined

view this post on Zulip Ayaz Hafiz (Dec 01 2023 at 23:31):

My solution

view this post on Zulip Isaac Van Doren (Dec 01 2023 at 23:47):

https://github.com/isaacvando/aoc/blob/main/2023/day1.roc

view this post on Zulip Isaac Van Doren (Dec 01 2023 at 23:51):

John Murray said:

Heres mine! https://github.com/JRMurr/AdventOfCode2023/blob/main/roc/D01/Day.roc

I struggled a lot with part 2 and eventually looked at the subreddit to find this dead-simple solution.

That trick is so slick :star_struck:

view this post on Zulip Jean Niklas L'orange (Dec 02 2023 at 00:31):

As a currier, I ended up really confused when e.g. solveWith : List (Str, Nat) -> List Str -> Nat said that it expected end of file at the second arrow. Not sure if there's a ticket for that, but I suppose there's some parser error handling that needs to be handled or something?

Also, because the Roc tutorial for Stdin data is on basic-cli 0.5.0 and latest basic-cli is 0.7.0, my initial "copypaste-but-update-to-latest-version" failed, as Stdin.line finally got fixed to return End instead of crashing on EOF (?). Which is what I wanted anyway, but heh, as a very new person to the language that got a bit confusing.

Day 1, part 1 and 2

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 00:33):

Would need to be written as: solveWith : List (Str, Nat) -> (List Str -> Nat) (if you want explicit currying)

view this post on Zulip Brendan Hansknecht (Dec 02 2023 at 00:33):

Probably we can generate a better error message for that case

view this post on Zulip Spencer Alger (Dec 02 2023 at 03:45):

First anything I've written in Roc. Started from your solution for part 1 @Luke Boswell and took off from there. Would love feedback.

https://github.com/spalger/advent-of-code/blob/main/roc/2023/day1/main.roc

view this post on Zulip Pearce Keesling (Dec 02 2023 at 18:35):

I don't know if it is just personal preference, but there is an infix == operator if you don't want to do Bool.isEq everywhere

view this post on Zulip Luke Boswell (Dec 02 2023 at 20:06):

So you can do expect first numOrWord (Str.toUtf8 "123") == Match 1

view this post on Zulip [REDACTED] (Dec 02 2023 at 20:37):

oops wrong convo

view this post on Zulip Ryan Bates (Dec 04 2023 at 17:56):

A little late to the party, but here's my solution for day 1.
https://github.com/ryanb/advent-2023-roc/blob/main/day01/main.roc

view this post on Zulip Jonas Schell (Jan 20 2024 at 00:35):

Looks like I'm late to the party too! But I had fun anyway!
Part 1 | Part 2

Result part 1:  55002
It took 3ms to run day 1 part 1.
Result part 2:  55093
It took 4ms to run day 1 part 2.

view this post on Zulip Luke Boswell (Jan 20 2024 at 01:08):

Nice!


Last updated: Jul 06 2025 at 12:14 UTC