renamed folders with days' name

This commit is contained in:
2021-12-06 14:19:57 +01:00
parent b0f362f6ec
commit 146396c887
14 changed files with 0 additions and 0 deletions

45
02-dive/code.scm Normal file
View File

@@ -0,0 +1,45 @@
(define (get-word text-port)
(let loop [(w '())]
(let [(c (get-char text-port))]
(if (or (eof-object? c) (char-whitespace? c))
(list->string (reverse w))
(loop (cons c w))))))
(call-with-input-file
"input"
(lambda (file)
(let loop [(x 0) (y 0)]
(let [(amount (string->number (get-word file)))
(move (get-word file))]
(cond
((string=? move "forward")
(loop (+ x amount) y))
((string=? move "down")
(loop x (+ y amount)))
((string=? move "up")
(loop x (- y amount)))
(else
(display "part 1: ")
(display (* x y))
(newline)))))))
(call-with-input-file
"input"
(lambda (file)
(let loop [(x 0) (y 0) (aim 0)]
(let [(amount (string->number (get-word file)))
(move (get-word file))]
(cond
((string=? move "forward")
(loop
(+ x amount)
(+ y (* aim amount))
aim))
((string=? move "down")
(loop x y (+ aim amount)))
((string=? move "up")
(loop x y (- aim amount)))
(else
(display "part 2: ")
(display (* x y))
(newline)))))))

1000
02-dive/input Normal file

File diff suppressed because it is too large Load Diff