Advertisement
PonaFly

build-matrix(20-n5)

Apr 19th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. (define (build-matrix)
  2. (define in (open-input-file "peaks.txt"))
  3. (define out (open-output-file "out.txt" #:exists 'replace ))
  4. (define len (car(function (string->list (read-line in)) '() 0 0)))
  5. (define (iter )
  6. (define line (read-line in))
  7. (if (equal? line eof) (close-output-port out)
  8. (help (function (cdr(string->list line)) '() 0 0) (build-list len (λ(x) (- x x)) ) ) ) )
  9.  
  10. (define (help lst result)
  11. (if (empty? lst) (begin (display result out) (display #\newline out) (iter))
  12. (help (cdr lst) (map + (build-lst 1 (car lst) (+ 1 len) '() ) result))))
  13.  
  14. (iter))
  15.  
  16. (define (build-lst i n len result) ;для каждого значения в списке создется один список из нулей и единички а потом map со всеми остальными значениями
  17. (if (= len i) (reverse result)
  18. (if (not (= i n)) (build-lst (+ i 1) n len (cons 0 result))
  19. (build-lst (+ i 1) n len (cons 1 result)))))
  20.  
  21. (define (function lst result number degree)
  22. (if (empty? lst) result
  23. (let ((ch (char->integer(car lst))))
  24. (if (and (>= ch 48) (<= ch 57)) (function (cdr lst) result (+ number (*(- ch 48) (expt 10 degree))) (+ degree 1))
  25. (function (cdr lst) (if (= number 0) result (cons number result)) 0 0)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement