fork download
  1. ; approximate squaring
  2.  
  3. (define (asq x)
  4. (define (sq x) (* x (ceiling x)))
  5. (let loop ((x (sq x)) (xs (list x)))
  6. (if (integer? x)
  7. (reverse (cons x xs))
  8. (loop (sq x) (cons x xs)))))
  9.  
  10. (display (asq 8/7)) (newline)
  11. (display (asq 10/6)) (newline)
  12.  
  13. (define (asq-table d)
  14. (do ((n (+ d 1) (+ n 1))) ((= n (+ d d)))
  15. (let ((xs (asq (/ n d))))
  16. (display n) (display " ")
  17. (display (- (length xs) 1)) (display " ")
  18. (display (car (reverse xs))) (newline))))
  19.  
  20. (asq-table 6)
  21. (asq-table 8)
Success #stdin #stdout 0.01s 7856KB
stdin
Standard input is empty
stdout
(1.14285714285714 2.28571428571429 6.85714285714286 48.0)
(1.66666666666667 3.33333333333333 13.3333333333333 186.666666666667 34906.6666666667 1218487013.33333 1.48471060247431e+18)
7 2 7.0
8 2 8.0
9 1 3.0
10 6 1.48471060247431e+18
11 3 220.0
9 4 2268.0
10 3 60.0
11 7 9.2499580699014e+29
12 1 3.0
13 2 13.0
14 2 14.0
15 2 15.0