18 lines
474 B
Racket
18 lines
474 B
Racket
|
#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)))
|
||
|
|