my solutions to advent of code
aoc advent-of-code

ok now this is what i actually wanted in my head and it came out of my head instead of claude. but thank you claude for reminding of dict values still

aylac.top 8ea9c26d e5571015

verified
Changed files
+7 -14
2015
12
gleam
+7 -14
2015/12/gleam/src/main.gleam
···
items
|> list.fold(0, fn(acc, data) { acc + get_total_number(data, no_red) })
NestedDict(items) -> {
-
let has_red =
-
no_red
-
&& {
-
items
-
|> dict.values
-
|> list.any(fn(data) { data == StringValue("red") })
+
items
+
|> dict.values
+
|> list.fold_until(0, fn(acc, data) {
+
case no_red && data == StringValue("red") {
+
False -> list.Continue(acc + get_total_number(data, no_red))
+
True -> list.Stop(0)
}
-
case has_red {
-
True -> 0
-
False ->
-
items
-
|> dict.fold(0, fn(acc, _, data) {
-
acc + get_total_number(data, no_red)
-
})
-
}
+
})
}
IntValue(v) -> v
_ -> 0