Stream: advent of code

Topic: 2024 Days 1


view this post on Zulip Sverre Winkelmans (Dec 12 2024 at 07:00):

I've been wanting to try out Roc for advent of code. I use the Roc template on github for aoc.

But I run in an error:

roc build 01.roc
thread '<unnamed>' panicked at crates/compiler/mono/src/ir.rs:6246:56:
called Option::unwrap() on a None value
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

If I use roc check 01.rocI get 0 errors and 0 warnings. I'm using the latest nightly and also tried with: roc_nightly-old_linux_x86_64-2024-12-11-d746e2a

My code:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
    aoc: "https://github.com/lukewilliamboswell/aoc-template/releases/download/0.2.0/tlS1ZkwSKSB87_3poSOXcwHyySe0WxWOWQbPmp7rxBw.tar.br"
}

import pf.Stdin
import pf.Stdout
import pf.Utc
import aoc.AoC {
    stdin: Stdin.readToEnd,
    stdout: Stdout.write,
    time: \{} -> Utc.now {} |> Task.map Utc.toMillisSinceEpoch,
}


main =
    AoC.solve {
        year: 2024,
        day: 1,
        title: "Historian Hysteria",
        part1,
        part2,
    }

sampleData =
    """
    3   4
    4   3
    2   5
    1   3
    3   9
    3   3
    """

asIntegers = \data ->
    dbg data
    left =
        data
            |> List.first
            |> Result.withDefault "0"
            |> Str.toI32
            |> Result.withDefault 0
    right =
        data
            |> List.last
            |> Result.withDefault "0"
            |> Str.toI32
            |> Result.withDefault 0
    dbg (left, right)

parseInput = \data ->
    data
        |> Str.splitOn "\n"
        |> dbg
        |> List.map (\line -> Str.splitOn line "   ")
        |> dbg
        |> List.map asIntegers
        |> List.walk {left : [], right: []} \t, (l,r) -> { t & left : List.append t.left l, right: List.append t.right r}


solve1 = \input ->
    left = List.sortAsc input.left
    right = List.sortAsc input.right

    List.map2 left right (\x,y -> Num.abs (Num.sub x y))
        |> List.sum


solve2 = \input ->
    input.left
        |> List.walk 0 \s,a  -> s +  (a * (Num.toI32 (List.countIf input.right \b -> a == b )))


## Implement your part1 and part1 solutions here
part1 : Str -> Result Str _
part1 = \input ->
    input
        |> parseInput
        |> solve1
        |> Num.toStr
        |> Ok


part2 : Str -> Result Str _
part2 = \input ->
    input
        |> parseInput
        |> solve2
        |> Num.toStr
        |> Ok

expect (part2 sampleData) == Ok "33"
expect (part1 sampleData) == Ok "11"

view this post on Zulip Brendan Hansknecht (Dec 12 2024 at 07:03):

does it work if you remove the dbgs? I have seen them sometimes causing this kind of issue.

view this post on Zulip Sverre Winkelmans (Dec 12 2024 at 07:05):

@Brendan Hansknecht Just tried but the problem remains.

view this post on Zulip Brendan Hansknecht (Dec 12 2024 at 07:06):

interestingly roc test runs

view this post on Zulip Brendan Hansknecht (Dec 12 2024 at 07:16):

A more minimal repro seems to be this.

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
    aoc: "https://github.com/lukewilliamboswell/aoc-template/releases/download/0.2.0/tlS1ZkwSKSB87_3poSOXcwHyySe0WxWOWQbPmp7rxBw.tar.br",
}

import pf.Stdin
import pf.Stdout
import pf.Utc
import aoc.AoC {
    stdin: Stdin.readToEnd,
    stdout: Stdout.write,
    time: \{} -> Utc.now {} |> Task.map Utc.toMillisSinceEpoch,
}

main =
    AoC.solve {
        year: 2024,
        day: 1,
        title: "Historian Hysteria",
        part1,
        part2,
    }

part1 = \_ ->
    crash "testing"

part2 = \_ ->
    crash "testing"

view this post on Zulip Brendan Hansknecht (Dec 12 2024 at 07:16):

quite confused as to why it is failing and how no one else has run into this

view this post on Zulip Sverre Winkelmans (Dec 12 2024 at 07:17):

I was able to run it before. It only stopped working when I tried for part2.

view this post on Zulip Jon Erik Kemi Warghed (Dec 12 2024 at 07:18):

Yes change the signature to Result Str Str in part1

view this post on Zulip Brendan Hansknecht (Dec 12 2024 at 07:19):

Also doesn't look to be a new regression. Still can repro on a commit from mid october

view this post on Zulip Jon Erik Kemi Warghed (Dec 12 2024 at 07:20):

https://github.com/lukewilliamboswell/aoc-template/issues/8

view this post on Zulip Sverre Winkelmans (Dec 12 2024 at 07:23):

@Jon Erik Kemi Warghed Thanks! Indeed specifing the error case instead of _ make it compile!


Last updated: Jul 06 2025 at 12:14 UTC