diff options
author | HJ <thechairman@thechairman.info> | 2023-12-09 01:25:46 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2023-12-09 01:25:46 -0500 |
commit | 7c69adbce6f3ab1075039e23c9c04ebd61ec0761 (patch) | |
tree | 38b84fb29bc09bdbaa32e4b601cc9affde38a28c /aoc2023/src/day2/solve.gleam | |
parent | 2f570466b75ca76636a692006bec59cbb3a038cf (diff) | |
parent | df2f2fd140f188dfb5df68b44e397a8855e79f02 (diff) | |
download | gleam_aoc-7c69adbce6f3ab1075039e23c9c04ebd61ec0761.tar.gz gleam_aoc-7c69adbce6f3ab1075039e23c9c04ebd61ec0761.zip |
Merge branch 'main' of https://github.com/hunkyjimpjorps/AdventOfCode
Diffstat (limited to 'aoc2023/src/day2/solve.gleam')
-rw-r--r-- | aoc2023/src/day2/solve.gleam | 12 |
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() { |