/ Published in: Scheme
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(let loop ((i 0) (j 20) ;; comparison value: it decreases at each recursion (except the first one) (topvalue 20)) ;; komodo value : must be equal to j at the beginning (let ((txt "Toyota denies previous banking problem is safety")) (if (equal? (- topvalue i) j) ;; the first time (loop (+ i 1) j topvalue) (begin (print (substring txt (- topvalue i) j)) (if (string=? (substring txt (- topvalue i) j) " ") (string-append (substring txt 0 (- topvalue i)) "\n" (substring txt (- topvalue i) (string-length txt))) (if (< i topvalue) ;;avoid negative indexes in substring (loop (+ i 1) (- j 1) topvalue)))))))