move common code to common.scm

This commit is contained in:
2021-12-07 11:21:21 +01:00
parent 146396c887
commit f17f9dc81c
3 changed files with 12 additions and 20 deletions

View File

@@ -1,14 +1,5 @@
(import (srfi :43)) ; vector extensions
; returns a list of numbers parsed from the first line of the file,
; separated by commas
(define (read-comma-separated-numbers file)
(let loop [(draws '()) (n 0)]
(let [(c (get-char file))]
(cond
[(char=? c #\,) (loop (cons n draws) 0)]
[(char-whitespace? c) (reverse (cons n draws))]
[else (loop draws (+ (* n 10) (string->number (string c))))]))))
(load "../common.scm")
;; naive version, as per the example
; simulate lanterfish growth and returns the number of fishes after given days