Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (build-matrix)
- (define in (open-input-file "peaks.txt"))
- (define out (open-output-file "out.txt" #:exists 'replace ))
- (define len (car(function (string->list (read-line in)) '() 0 0)))
- (define (iter )
- (define line (read-line in))
- (if (equal? line eof) (close-output-port out)
- (help (function (cdr(string->list line)) '() 0 0) (build-list len (λ(x) (- x x)) ) ) ) )
- (define (help lst result)
- (if (empty? lst) (begin (display result out) (display #\newline out) (iter))
- (help (cdr lst) (map + (build-lst 1 (car lst) (+ 1 len) '() ) result))))
- (iter))
- (define (build-lst i n len result) ;для каждого значения в списке создется один список из нулей и единички а потом map со всеми остальными значениями
- (if (= len i) (reverse result)
- (if (not (= i n)) (build-lst (+ i 1) n len (cons 0 result))
- (build-lst (+ i 1) n len (cons 1 result)))))
- (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