···
26
-
fn handle_calc(data: Nested, no_red) {
26
+
fn get_total_number(data: Nested, no_red no_red) {
28
-
NestedList(items) -> get_total_number_list(items, no_red)
29
-
NestedDict(items) -> get_total_number_dict(items, no_red)
28
+
NestedList(items) ->
30
+
|> list.fold(0, fn(acc, data) { acc + get_total_number(data, no_red) })
31
+
NestedDict(items) -> {
32
+
let has_red = case no_red {
35
+
|> dict.fold(False, fn(state, _, data) {
37
+
StringValue("red") -> True
47
+
|> dict.fold(0, fn(acc, _, data) {
48
+
acc + get_total_number(data, no_red)
35
-
fn get_total_number_dict(data: Dict(String, Nested), no_red) {
36
-
let has_red = case no_red {
39
-
|> dict.fold(False, fn(state, _, data) {
41
-
StringValue("red") -> True
51
-
|> dict.fold(0, fn(acc, _, data) { acc + handle_calc(data, no_red) })
55
-
fn get_total_number_list(data: List(Nested), no_red no_red) {
57
-
|> list.fold(0, fn(acc, data) { acc + handle_calc(data, no_red) })
read(from: "../input.json")
···
|> json.parse(int_anywhere_decoder())
67
-
get_total_number_list([input], no_red: False)
64
+
get_total_number(input, no_red: False)
71
-
get_total_number_list([input], no_red: True)
68
+
get_total_number(input, no_red: True)