day 2 racket
This commit is contained in:
parent
4a331229a2
commit
3955e35520
17
rkt/02.1.rkt
Normal file
17
rkt/02.1.rkt
Normal file
|
@ -0,0 +1,17 @@
|
|||
#lang racket
|
||||
|
||||
(let-values ([(x y)
|
||||
(with-input-from-file "../input/02"
|
||||
(lambda ()
|
||||
(for/fold ([x 0]
|
||||
[y 0])
|
||||
([line (in-lines)])
|
||||
(let ([s (string-split line)])
|
||||
(let ([op (car s)]
|
||||
[num (string->number (car (cdr s)))])
|
||||
(match op
|
||||
["up" (values x (- y num))]
|
||||
["down" (values x (+ y num))]
|
||||
["forward" (values (+ x num) y)]))))))
|
||||
]) (values (cons x y) (* x y)))
|
||||
|
18
rkt/02.2.rkt
Normal file
18
rkt/02.2.rkt
Normal file
|
@ -0,0 +1,18 @@
|
|||
#lang racket
|
||||
|
||||
(let-values ([(_ x y)
|
||||
(with-input-from-file "../input/02"
|
||||
(lambda ()
|
||||
(for/fold ([aim 0]
|
||||
[x 0]
|
||||
[y 0])
|
||||
([line (in-lines)])
|
||||
(let ([s (string-split line)])
|
||||
(let ([op (car s)]
|
||||
[num (string->number (car (cdr s)))])
|
||||
(match op
|
||||
["up" (values (- aim num) x y)]
|
||||
["down" (values (+ aim num) x y)]
|
||||
["forward" (values aim (+ x num) (+ y (* aim num)))]))))))
|
||||
]) (values (cons x y) (* x y)))
|
||||
|
Loading…
Reference in a new issue