aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/src/day2
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2023-12-08 09:42:11 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2023-12-08 09:42:11 -0500
commit82c3ecec3de5111b460910bafe141b3aed478676 (patch)
tree98e1cb821151cea989608b3f55e8a8642fab3da0 /aoc2023/src/day2
parentc82dee4b12a824ff73dc91f89445d4df75d3c876 (diff)
downloadgleam_aoc-82c3ecec3de5111b460910bafe141b3aed478676.tar.gz
gleam_aoc-82c3ecec3de5111b460910bafe141b3aed478676.zip
updated for new exhaustiveness checks in 0.33
Diffstat (limited to 'aoc2023/src/day2')
-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() {