15 lines
495 B
Scheme
15 lines
495 B
Scheme
; 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))))]))))
|
|
|
|
; returns numbers 0 to 9 from ascii character
|
|
(define (char->number c)
|
|
(- (char->integer c) 48)) ; 48 is ASCII's number zero
|
|
|