aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/src/day2/solve.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'aoc2023/src/day2/solve.gleam')
-rw-r--r--aoc2023/src/day2/solve.gleam12
1 files changed, 6 insertions, 6 deletions
diff --git a/aoc2023/src/day2/solve.gleam b/aoc2023/src/day2/solve.gleam
index 916704c..22470ab 100644
--- a/aoc2023/src/day2/solve.gleam
+++ b/aoc2023/src/day2/solve.gleam
@@ -10,18 +10,19 @@ pub type Game {
fn parse(input: String) -> List(List(Game)) {
use line <- list.map(string.split(input, "\n"))
- let [_, rounds] = string.split(line, on: ": ")
+ let assert [_, rounds] = string.split(line, on: ": ")
use match <- list.map(string.split(rounds, on: "; "))
use acc, draw <- list.fold(
over: string.split(match, on: ", "),
from: Game(0, 0, 0),
)
- let [n_str, color] = string.split(draw, " ")
+ let assert Ok(#(n_str, color)) = string.split_once(draw, " ")
let assert Ok(n) = int.parse(n_str)
case color {
"red" -> Game(..acc, red: n)
"blue" -> Game(..acc, blue: n)
"green" -> Game(..acc, green: n)
+ _ -> panic as { "unrecognized color " <> color }
}
}
@@ -44,10 +45,9 @@ pub fn part2(input: String) {
green: int.max(green, acc.green),
)
}
- |> list.fold(
- from: 0,
- with: fn(acc, g: Game) { acc + g.red * g.blue * g.green },
- )
+ |> list.fold(from: 0, with: fn(acc, g: Game) {
+ acc + g.red * g.blue * g.green
+ })
}
pub fn main() {