aboutsummaryrefslogtreecommitdiff
path: root/aoc2023-other/day-02
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-other/day-02
parent87e9ab25ff70e215b537939a4bc23ab101f41dbe (diff)
downloadgleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.tar.gz
gleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.zip
renaming
Diffstat (limited to 'aoc2023-other/day-02')
-rw-r--r--aoc2023-other/day-02/day-02-parser.rkt55
-rw-r--r--aoc2023-other/day-02/day-02.rkt35
2 files changed, 0 insertions, 90 deletions
diff --git a/aoc2023-other/day-02/day-02-parser.rkt b/aoc2023-other/day-02/day-02-parser.rkt
deleted file mode 100644
index 76cc24f..0000000
--- a/aoc2023-other/day-02/day-02-parser.rkt
+++ /dev/null
@@ -1,55 +0,0 @@
-#lang racket
-
-(require racket/hash
- advent-of-code
- data/applicative
- data/either
- data/monad
- megaparsack
- megaparsack/text
- threading)
-
-(struct game (id r g b))
-
-(define cube/p
- (do [n <- integer/p]
- space/p
- [c <- (or/p (string/p "red")
- (string/p "blue")
- (string/p "green"))]
- (pure (cons c n))))
-
-(define draw/p
- (do [xs <- (many/p cube/p #:min 1 #:max 3 #:sep (string/p ", "))]
- (pure (apply hash (flatten xs)))))
-
-(define all-draws/p
- (do (string/p "Game ")
- [id <- integer/p]
- (string/p ": ")
- [all-draws <- (many/p draw/p #:min 1 #:sep (string/p "; "))]
- (define maxima
- (foldl (curry hash-union #:combine max)
- (hash "red" 0 "green" 0 "blue" 0)
- all-draws))
- (pure (game id
- (hash-ref maxima "red")
- (hash-ref maxima "green")
- (hash-ref maxima "blue")))))
-
-(define game-maxima
- (~>> (open-aoc-input (find-session) 2023 2)
- port->lines
- (map (λ~>> (parse-string all-draws/p)
- from-either))))
-
-;; part 1
-(for/sum ([m (in-list game-maxima)]
- #:unless (or (> (game-r m) 12)
- (> (game-g m) 13)
- (> (game-b m) 14)))
- (game-id m))
-
-;; part 2
-(for/sum ([m (in-list game-maxima)])
- (* (game-r m) (game-g m) (game-b m)))
diff --git a/aoc2023-other/day-02/day-02.rkt b/aoc2023-other/day-02/day-02.rkt
deleted file mode 100644
index 973d20c..0000000
--- a/aoc2023-other/day-02/day-02.rkt
+++ /dev/null
@@ -1,35 +0,0 @@
-#lang racket
-
-(require advent-of-code)
-
-(struct roll (id red green blue))
-
-(define all-games
- (for/list ([raw-game (in-list (port->lines (open-aoc-input (find-session) 2023 2)))]
- #:do [(define game (string-trim raw-game "Game "))
- (match-define (list id trials) (string-split game ": "))])
- (for/list ([trial (in-list (string-split trials "; "))])
- (for/fold ([acc (roll (string->number id) 0 0 0)])
- ([color (in-list (string-split trial ", "))])
- (match (string-split color)
- [(list (app string->number n) "red") (struct-copy roll acc [red n])]
- [(list (app string->number n) "green") (struct-copy roll acc [green n])]
- [(list (app string->number n) "blue") (struct-copy roll acc [blue n])])))))
-
-;; part 1
-(for/sum ([game (in-list all-games)]
- #:when (andmap (λ (g) (and ((roll-red g) . <= . 12)
- ((roll-green g) . <= . 13)
- ((roll-blue g) . <= . 14)))
- game))
- (roll-id (first game)))
-
-;; part 2
-(for/sum ([game (in-list all-games)])
- (define max-cubes
- (for/fold ([acc (roll #f 0 0 0)]) ([r (in-list game)])
- (roll #f
- (max (roll-red acc) (roll-red r))
- (max (roll-green acc) (roll-green r))
- (max (roll-blue acc) (roll-blue r)))))
- (* (roll-red max-cubes) (roll-green max-cubes) (roll-blue max-cubes)))