adventofcode-2021/02-solution-02.rkt

18 lines
639 B
Racket

#lang racket
(define strings (file->lines "02-input-01.txt"))
(define depth 0)
(define distance 0)
(define aim 0)
(for ([string strings])
(let* ([split (string-split string)]
[command (first split)]
[value (string->number (second split))])
(cond [(string=? command "forward")
(set! distance (+ distance value))
(set! depth (+ depth (* aim value)))]
[(string=? command "down")
(set! aim (+ aim value))]
[(string=? command "up")
(set! aim (- aim value))]
)))
(printf "depth: ~a, distance: ~a, multiplied: ~a" depth distance (* depth distance))