diff --git a/src/aoc_2024/day_1.gleam b/src/aoc_2024/day_1.gleam index 08f48fc..7acf86d 100644 --- a/src/aoc_2024/day_1.gleam +++ b/src/aoc_2024/day_1.gleam @@ -17,9 +17,7 @@ pub fn parse(input: String) -> Input { let #(xs, ys) = acc case row { [x, y] -> { - let assert Ok(xx) = int.parse(x) - let assert Ok(yy) = int.parse(y) - #([xx, ..xs], [yy, ..ys]) + #([extra.yolo_int(x), ..xs], [extra.yolo_int(y), ..ys]) } _ -> panic as "Bad input" } diff --git a/src/aoc_2024/day_2.gleam b/src/aoc_2024/day_2.gleam index 2f9a246..c879ade 100644 --- a/src/aoc_2024/day_2.gleam +++ b/src/aoc_2024/day_2.gleam @@ -9,7 +9,7 @@ pub fn parse(input: String) -> List(List(Int)) { |> list.map(fn(line) { line |> string.split(" ") - |> list.filter_map(int.parse) + |> list.map(extra.yolo_int) }) } diff --git a/src/extra.gleam b/src/extra.gleam index b2b33e2..d3c9755 100644 --- a/src/extra.gleam +++ b/src/extra.gleam @@ -1,4 +1,5 @@ import gleam/dict.{type Dict} +import gleam/int import gleam/list import gleam/option import gleam/otp/task @@ -53,3 +54,8 @@ pub fn remove_at(xs: List(a), at i: Int) -> List(a) { pub fn selections(xs: List(a)) -> List(#(a, List(a))) { list.index_map(xs, fn(x, i) { #(x, remove_at(xs, i)) }) } + +pub fn yolo_int(x: String) -> Int { + let assert Ok(n) = int.parse(x) + n +}