aboutsummaryrefslogtreecommitdiff
path: root/advent-of-code/2023/02
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-02-25 20:11:54 +0800
committerMistivia <i@mistivia.com>2024-02-25 20:11:54 +0800
commit515ecbf5a20a8e432a998b0a543bedcb1bd64cf4 (patch)
tree6353c603a8cf0276553f420205f8d1c730a318ce /advent-of-code/2023/02
parente191b610c11326b587cf0b01fd6fc37b8d07bb19 (diff)
reorg code
Diffstat (limited to 'advent-of-code/2023/02')
-rw-r--r--advent-of-code/2023/02/1.rkt52
-rw-r--r--advent-of-code/2023/02/2.rkt44
2 files changed, 0 insertions, 96 deletions
diff --git a/advent-of-code/2023/02/1.rkt b/advent-of-code/2023/02/1.rkt
deleted file mode 100644
index 500e916..0000000
--- a/advent-of-code/2023/02/1.rkt
+++ /dev/null
@@ -1,52 +0,0 @@
-#lang racket
-
-(require "../../lib/utils.rkt")
-
-(define fp (open-input-file "input"))
-
-(define lines (get-lines fp))
-
-(define (extract-game line)
- (define game-str (cadr (string-split line ":")))
- (define sets-str (string-split game-str ";"))
- (set! sets-str (map string-trim sets-str))
- (map extract-set sets-str))
-
-(define (extract-set str)
- (define r 0)
- (define g 0)
- (define b 0)
- (define balls (string-split str ","))
- (set! balls
- (map (λ (s)
- (define pair (map string-trim (string-split s " ")))
- (list (string->number (car pair)) (cadr pair)))
- balls))
- (let loop ((balls balls))
- (if (null? balls)
- '()
- (let ()
- (define ball (car balls))
- (define number (car ball))
- (define color (cadr ball))
- (cond ((string=? "red" color) (set! r number))
- ((string=? "green" color) (set! g number))
- ((string=? "blue" color) (set! b number)))
- (loop (cdr balls)))))
- (list r g b))
-
-(define (possible? game)
- (if (null? game)
- #t
- (let ()
- (define head (car game))
- (if (or (> (car head) 12) ; r
- (> (cadr head) 13) ; g
- (> (caddr head) 14)) ; b
- #f
- (possible? (cdr game))))))
-
-(apply + (map cadr
- (filter (λ (game)
- (possible? (car game)))
- (enumerate (map extract-game lines)))))
diff --git a/advent-of-code/2023/02/2.rkt b/advent-of-code/2023/02/2.rkt
deleted file mode 100644
index 7da2cd2..0000000
--- a/advent-of-code/2023/02/2.rkt
+++ /dev/null
@@ -1,44 +0,0 @@
-#lang racket
-
-(require "../../lib/utils.rkt")
-
-(define fp (open-input-file "input"))
-
-(define lines (get-lines fp))
-
-(define (extract-game line)
- (define game-str (cadr (string-split line ":")))
- (define sets-str (string-split game-str ";"))
- (set! sets-str (map string-trim sets-str))
- (map extract-set sets-str))
-
-(define (extract-set str)
- (define r 0)
- (define g 0)
- (define b 0)
- (define balls (string-split str ","))
- (set! balls
- (map (λ (s)
- (define pair (map string-trim (string-split s " ")))
- (list (string->number (car pair)) (cadr pair)))
- balls))
- (let loop ((balls balls))
- (if (null? balls)
- '()
- (let ()
- (define ball (car balls))
- (define number (car ball))
- (define color (cadr ball))
- (cond ((string=? "red" color) (set! r number))
- ((string=? "green" color) (set! g number))
- ((string=? "blue" color) (set! b number)))
- (loop (cdr balls)))))
- (list r g b))
-
-(define (power game)
- (define rs (map car game))
- (define gs (map cadr game))
- (define bs (map caddr game))
- (* (apply max rs) (apply max gs) (apply max bs)))
-
-(apply + (map power (map extract-game lines)))