Stream: advent of code

Topic: 2023 Day 5


view this post on Zulip Fabian Schmalzried (Dec 05 2023 at 09:41):

Here is my day 5, but part 2 is way to slow. I'm still waiting for the output, but i get the feeling I will have to optimize...

view this post on Zulip joshi (Dec 05 2023 at 11:31):

Uh boy, this was quite something...
I feel like "AoC is easier on workdays" might not quite be true :joy:

My part 2 takes 10 minutes to run, but this was still faster than me trying to come up and implement a smarter solution, so I guess I'm done?

the smarter idea

https://gitlab.com/arkandos/aoc/-/blob/2023/solutions/day5.roc?ref_type=heads

view this post on Zulip Fabian Schmalzried (Dec 05 2023 at 12:09):

Here is my new day 5. It's super fast now, but could use some cleanup.

How I did speed it up

view this post on Zulip Johan Lindskogen (Dec 05 2023 at 13:41):

Day 5! Runs in about 7 minutes :D https://github.com/lindskogen/advent-of-code-2023/blob/main/day05/main.roc

view this post on Zulip Oskar Hahn (Dec 05 2023 at 18:43):

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

Part1 in 2.422ms:
XXX

Part2 in 98.236ms:
XXX

It is nice, that roc partly compiles. I implemented the type signatures and put them together like

expect
  part1 exampleInput == "result"

part1 = \input ->
  input
  |> doSomething
  |> somethingElse

doSomething : Input -> Output
somethingElse : OtherInput -> OtherOutput

Then I called roc test day05.roc and the compiler told my what to do next :)

The feature I missed today was to rename a deconstructed value. For example

[first, .. as rest ] = mylist

or

RecordOne : {first : Str, second : Str}
RecordTwo : {first : Str, second : Str}

myFunc : RecordOne, RecordTwo -> Str
myFunc = \{first as first1, second as second1}, {first as first2, second as second2} ->
  ...

The as keyword works in pattern matching. Would it be possible, that it would also work in the deconstructing a datastructure?

view this post on Zulip Brendan Hansknecht (Dec 05 2023 at 19:13):

Super lazy and just brute force walking everything: https://github.com/bhansconnect/roc-aoc-2023/blob/main/day5.roc

Probably a smarter way to do things

view this post on Zulip Pearce Keesling (Dec 05 2023 at 19:54):

I'm really glad I'm not the only lazy soul who just waited 8 minutes for part 2 to run.
https://github.com/keeslinp/AoC2023/blob/main/day5.roc

I finally took the time to grok the parser lib and I think I've got the hang of it.
I know there was some discussion around short-circuit conditionals a while back and I just ran into a sharp edge related to that. I had to do

            if location >= source then
                if location - source <= size then
                    Bool.true
                else
                    Bool.false
            else
                Bool.false

because
location >= source && location - source <= size caused underflow :disappointed: .

view this post on Zulip Axel (Dec 05 2023 at 21:18):

Also in camp brute force here with my solution. :see_no_evil:

view this post on Zulip Asbjørn Olling (Dec 05 2023 at 21:23):

I think I solved part 1.. but I hit a compiler bug once I wrote the final line to my solution :cry:

https://gitlab.com/AsbjornOlling/aoc2023/-/blob/main/05/main.roc

I even tested everything with expects as I built it, going bottom-up, and all the components work perfectly by themselves, so I'm pretty convinced that my solution works. It's just that my one line of top-level call panics the compiler.

RUST_BACKTRACE=full

I'm not sure what to do. I guess I'll try rewriting it in a different way, and hope to avoid the crash condition - but (what seems to be) the offending line is just a straightforward List.map call, so it's gonna be a bit obtuse.

view this post on Zulip Brendan Hansknecht (Dec 05 2023 at 21:30):

List.walk building a chain of closures.

view this post on Zulip Asbjørn Olling (Dec 05 2023 at 21:30):

lol yes :rolling_on_the_floor_laughing:

view this post on Zulip Brendan Hansknecht (Dec 05 2023 at 21:30):

That probably is somehow the root cause of the crash

view this post on Zulip Brendan Hansknecht (Dec 05 2023 at 21:31):

Lambda sets sadly have some bugs and you are probably hitting one...but that's just a guess

view this post on Zulip Asbjørn Olling (Dec 05 2023 at 21:31):

funkily enough, I do that twice in my program, but the other instance worked

view this post on Zulip Asbjørn Olling (Dec 05 2023 at 21:32):

Ha just before beginning todays aoc, I was listening to the Software Unscripted episode with Casey Muratori,
and rtfeldman mentioned exactly that lambda sets are often the cause :sweat_smile:

view this post on Zulip Asbjørn Olling (Dec 05 2023 at 22:14):

heyy I rewrote it into something that works

view this post on Zulip Asbjørn Olling (Dec 05 2023 at 22:14):

..and then I found out that I had understood the task wrong :sweat_smile: typical

view this post on Zulip Asbjørn Olling (Dec 05 2023 at 22:19):

luckily it was just a matter of using the wrong order of (outrange, inrange, len)

view this post on Zulip Jason Hobbs (Dec 06 2023 at 03:25):

I managed to solve Part 1, but not Part 2...

Part 1

view this post on Zulip Jason Hobbs (Dec 06 2023 at 03:25):

I think my Part 2 would work if my computer had a trillion more resources:

My Part 2 - Success on example input only

view this post on Zulip Ayaz Hafiz (Dec 06 2023 at 04:11):

Also brute forced this one because efficiency is boring https://gist.github.com/ayazhafiz/9adbb083f965bcad18c2b5754b00b51b

view this post on Zulip Ryan Bates (Dec 06 2023 at 07:41):

Here's my solution for both parts.
https://github.com/ryanb/advent-2023-roc/blob/main/day05/main.roc

Part 2 Spoiler

view this post on Zulip LoipesMas (Dec 06 2023 at 21:35):

My solution: https://github.com/LoipesMas/roc-aoc2023/blob/main/5/main.roc
For part 2, after the obvious attempt was obviously too slow, I had a stupid unique idea to flip the problem backwards: instead of going from seed to location, I went with locations going from 0, converting them to seeds and checking if the seed is in provided range. It's O(n) where n is your result ;]
With --optimized it's not even that bad! Only ~12 seconds to find location 15_880_236. Around a minute for an unoptimized build

view this post on Zulip timotree (Dec 09 2023 at 20:44):

My solution: https://github.com/timotree3/aoc2023/blob/main/roc/day5.roc
Takes less than a few ms on my machine.

Approach

view this post on Zulip Jonas Schell (Feb 14 2024 at 18:15):

My solutions for day 5: https://github.com/Ocupe/advent-of-code-2023/tree/main/day_05

My solution for part 2 took around 13 hours to finish :snail:
How do they say: Make it work, then make it fast. I guess I'm okay with just getting the first thing done - especially after I already got the second star :P


Last updated: Jul 06 2025 at 12:14 UTC