aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/src/day2
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2024-02-02 17:05:12 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2024-02-02 17:05:12 -0500
commit48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9 (patch)
treef59a13e0b5e80ab925220b4488c6e36b1bec660a /aoc2023/src/day2
parent87e9ab25ff70e215b537939a4bc23ab101f41dbe (diff)
downloadgleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.tar.gz
gleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.zip
renaming
Diffstat (limited to 'aoc2023/src/day2')
-rw-r--r--aoc2023/src/day2/.gitignore1
-rw-r--r--aoc2023/src/day2/solve.gleam67
2 files changed, 0 insertions, 68 deletions
diff --git a/aoc2023/src/day2/.gitignore b/aoc2023/src/day2/.gitignore
deleted file mode 100644
index ae40cea..0000000
--- a/aoc2023/src/day2/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-input.txt \ No newline at end of file
diff --git a/aoc2023/src/day2/solve.gleam b/aoc2023/src/day2/solve.gleam
deleted file mode 100644
index 38e62d7..0000000
--- a/aoc2023/src/day2/solve.gleam
+++ /dev/null
@@ -1,67 +0,0 @@
-import adglent.{First, Second}
-import gleam/io
-import gleam/int
-import gleam/string
-import gleam/list
-
-pub type Game {
- Game(red: Int, blue: Int, green: Int)
-}
-
-fn parse(input: String) -> List(List(Game)) {
- use line <- list.map(string.split(input, "\n"))
- 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 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"
- }
-}
-
-pub fn part1(input: String) {
- use acc, game, i <- list.index_fold(parse(input), 0)
- case list.any(game, fn(m) { m.red > 12 || m.green > 13 || m.blue > 14 }) {
- False -> acc + i + 1
- True -> acc
- }
-}
-
-pub fn part2(input: String) {
- {
- use game <- list.map(parse(input))
- use acc, match <- list.fold(game, Game(0, 0, 0))
- let Game(red: red, green: green, blue: blue) = match
- Game(
- red: int.max(red, acc.red),
- blue: int.max(blue, acc.blue),
- green: int.max(green, acc.green),
- )
- }
- |> list.fold(
- from: 0,
- with: fn(acc, g: Game) { acc + g.red * g.blue * g.green },
- )
-}
-
-pub fn main() {
- let assert Ok(part) = adglent.get_part()
- let assert Ok(input) = adglent.get_input("2")
- case part {
- First ->
- part1(input)
- |> adglent.inspect
- |> io.println
- Second ->
- part2(input)
- |> adglent.inspect
- |> io.println
- }
-}