Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang scheme
- (define (listribs)
- (define in (open-input-file "peaks.txt"))
- (define out (open-output-file "out.txt" #:exists 'replace ))
- (define (iter Nstr )
- (define line (read-line in))
- (if (equal? line eof) (close-output-port out)
- (if (= Nstr 0) (iter (+ 1 Nstr))
- (help (function (reverse(cdr (string->list line))) '() 0 0 ) Nstr ))))
- (define (help lst Nstr)
- (if (empty? lst) (iter (+ 1 Nstr))
- (cond
- ( (>= Nstr (car lst)) (display (cons Nstr (car lst)) out) (display #\newline out) (help (cdr lst) Nstr))
- (else (help (cdr lst) Nstr)))))
- (iter 0))
- (define (function lst result number degree)
- (if (empty? lst) result
- (let ((ch (char->integer(car lst))))
- (if (and (>= ch 48) (<= ch 57)) (function (cdr lst) result (+ number (*(- ch 48) (expt 10 degree))) (+ degree 1))
- (function (cdr lst) (if (= number 0) result (cons number result)) 0 0)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement