blob: e53e0abac962c6ec6e5607f6dae0a09f1c79a2eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#!/usr/bin/env -S guile -s
!#
(use-modules (ice-9 textual-ports))
(define (read-lines port)
(letrec ((loop (lambda (l ls)
(if (eof-object? l)
ls
(loop (get-line port) (cons l ls))))))
(reverse (loop (get-line port) '()))))
(define (value-for-line line)
(string->number (string-filter char-set:digit line)))
(define (travel-distance total-time hold-time)
(* (- total-time hold-time) hold-time))
(let* ((port (open-input-file "6.txt"))
(lines (read-lines port))
(time (value-for-line (car lines)))
(distance (value-for-line (cadr lines)))
(current 0)
(count 0))
(close-port port)
(while (<= current distance)
(set! current (travel-distance time count))
(set! count (1+ count)))
(display (- (+ time 1) (* 2 (- count 1)))))
|