aoc2021/rkt/02.1.rkt
2021-12-03 02:20:27 +07:00

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)))