diff options
author | lamp | 2023-12-06 20:14:46 +0000 |
---|---|---|
committer | lamp | 2023-12-06 20:14:46 +0000 |
commit | de3954129bfa3a746a313181cae71e1f384dda59 (patch) | |
tree | b6fced528c73c2d82a95b8bc673d150630097923 /6-2.scm | |
parent | 92d487dc052788b0ef77071cccad2427c20f66df (diff) |
add day 6 solutions
Diffstat (limited to '6-2.scm')
-rwxr-xr-x | 6-2.scm | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -0,0 +1,30 @@ +#!/usr/bin/env -S guile -s +!# +(use-modules (ice-9 regex) + (ice-9 textual-ports) + (srfi srfi-1)) + +(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))))) |