I got both stars from day 24. But in the end, I can not say, that it is my solution: https://github.com/ostcar/aoc2023/blob/main/days/day24.roc
I spend a lot of time with day 24 and made so many detours. What I did was so dorky, that I don't use the spoiler tag. Nothing of it was necessary for day 24.
For the day, you have to work with fractional numbers. So first, I tried Dec. But Dec is not fully implemented yet. I don't remember which operation I was missing. Maybe it was sqrt.
Next, I tried F64. But you can not compare them. I understand the decision. But it it very hard to work with them. For example, it is hard to write a test. The following test is a type error:
expect
f = 5.1 |> Num.toF64
f == 5.1
Maybe a approx equal for Frac would be helpful.
Next, I tried I tried to use a rational type with some helper functions.
Rational a := (Int a, Int a)
implements [
Eq { isEq: qEq },
]
qEq = \@Rational (a, b), @Rational (c, d) ->
a * d == c * b
qAdd = \@Rational (a, b), @Rational (c, d) ->
@Rational (a * d + b * c, b * d)
|> qNormalize
This worked at the beginning. But it was very hard to make any calculations. For a type like Rational
, it would be helpful to define infix function or overload operators.
For example, here is a calculation, I had to do.
# t1 = (a.x - a.y * b.x / b.y ) / (1 - b.x / b.y)
t1 = qDiv (qSub a.x (qDiv (qMul a.y b.x) b.y)) (qSub (qFromInt 1) (qDiv b.x b.y))
I started with Rational I64
, but the input has very high numbers. So I had to switch to I128. It seems, that there is a problem with I128 and the surgical linker. The returned message is:
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread 'main' panicked at 'Undefined Symbol in relocation, (+5d72, Relocation { kind: PltRelative, encoding: Generic, size: +20, target: Symbol(SymbolIndex(+65)), addend: +fffffffffffffffc, implicit_addend: false }): Ok(Symbol { name: "__modti3", address: +0, size: +0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: Elf { st_info: +10, st_other: +0 } })', crates/linker/src/elf.rs:1486:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Using the legacy-linker fixed this for part1. But for part2 the numbers got even bigger and I could not use Rational I128
anymore. Since I don't want (and probably are not able) to implement a IBigNumber
,I used F64 in the end and it worked.
For the actual problem for part2, I spend many hours to make the calculation, but I was not able to solve the equations. In the end, I looked at other solutions and used the calculation from someone else.
Thanks for solving so many advent of code problems in Roc @Oskar Hahn!
I wish we could make faster progress on solving bugs but we have a bunch that are very difficult and time consuming to solve.
yeah I believe you now hold the record for most Advent of Code problems solved in Roc! :smiley:
Thanks. I am still missing 4 stars. Roc is so much fun. I is great to see it evolve. I hope, I find a hobby project I can do with roc until AoC 2024.
I hope you do too! And we'll be here to support, as always :smiley:
Last updated: Jul 06 2025 at 12:14 UTC