day 2: cheese
This commit is contained in:
parent
dc612a29a4
commit
591590eb05
52
2.rkt
52
2.rkt
|
@ -5,49 +5,23 @@
|
||||||
;; solution for day 2
|
;; solution for day 2
|
||||||
|
|
||||||
(define (part1 input)
|
(define (part1 input)
|
||||||
(for/sum ([x (in-list input)])
|
(for/sum ([line (in-list input)])
|
||||||
(match-define (list x1 x2) x)
|
(+ 1 (second line)
|
||||||
(+ (match x2
|
(~> (- (second line) 2 (first line))
|
||||||
["X" 1]
|
(modulo 3)
|
||||||
["Y" 2]
|
(* 3)))))
|
||||||
["Z" 3])
|
|
||||||
(match* (x1 x2)
|
|
||||||
[("A" "X") 3]
|
|
||||||
[("A" "Y") 6]
|
|
||||||
[("A" "Z") 0]
|
|
||||||
[("B" "X") 0]
|
|
||||||
[("B" "Y") 3]
|
|
||||||
[("B" "Z") 6]
|
|
||||||
[("C" "X") 6]
|
|
||||||
[("C" "Y") 0]
|
|
||||||
[("C" "Z") 3]))))
|
|
||||||
|
|
||||||
|
|
||||||
(define (part2 input)
|
(define (part2 input)
|
||||||
(for/sum ([x (in-list input)])
|
(for/sum ([line (in-list input)])
|
||||||
(match-define (list x1 x2) x)
|
(+ (* (second line) 3)
|
||||||
(+ (match x2
|
(~> (+ (second line) (first line) 2)
|
||||||
["X" 0]
|
(modulo 3)
|
||||||
["Y" 3]
|
(add1)))))
|
||||||
["Z" 6])
|
|
||||||
(match* (x1 x2)
|
|
||||||
[("A" "X") 3]
|
|
||||||
[("A" "Y") 1]
|
|
||||||
[("A" "Z") 2]
|
|
||||||
[("B" "X") 1]
|
|
||||||
[("B" "Y") 2]
|
|
||||||
[("B" "Z") 3]
|
|
||||||
[("C" "X") 2]
|
|
||||||
[("C" "Y") 3]
|
|
||||||
[("C" "Z") 1]))))
|
|
||||||
|
|
||||||
(define (parse fname)
|
(define (parse fname)
|
||||||
(for/list ([x (in-list (file->lines fname))])
|
(for/list ([line (in-list (file->lines fname))])
|
||||||
(string-split x " ")))
|
(map #{hash-ref (hash "A" 0 "B" 1 "C" 2 "X" 0 "Y" 1 "Z" 2) %}
|
||||||
|
(string-split line " "))))
|
||||||
(module+ test
|
|
||||||
(require rackunit)
|
|
||||||
(displayln "no tests :("))
|
|
||||||
|
|
||||||
(module+ main
|
(module+ main
|
||||||
(define input (parse "inputs/2"))
|
(define input (parse "inputs/2"))
|
||||||
|
|
Loading…
Reference in New Issue