Skip to content

Commit

Permalink
yolo_int
Browse files Browse the repository at this point in the history
  • Loading branch information
Janiczek committed Dec 2, 2024
1 parent ac5092d commit bbbc8d8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/aoc_2024/day_1.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion src/aoc_2024/day_2.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
6 changes: 6 additions & 0 deletions src/extra.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gleam/dict.{type Dict}
import gleam/int
import gleam/list
import gleam/option
import gleam/otp/task
Expand Down Expand Up @@ -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
}

0 comments on commit bbbc8d8

Please sign in to comment.