fork download
  1. (defun integer-sqrt (num)
  2. (if (zerop num)
  3. 0
  4. (labels ((next-approx (curr)
  5. (truncate (/ (+ curr (truncate (/ num curr))) 2)))
  6. (int-sqrt (n n1)
  7. (if (>= n1 n)
  8. n
  9. (int-sqrt n1 (next-approx n1)))))
  10. (let ((first-aprox (1+ (truncate (/ num 2)))))
  11. (int-sqrt first-aprox (next-approx first-aprox))))))
  12.  
  13. (integer-sqrt 26)
Success #stdin #stdout 0.03s 10584KB
stdin
Standard input is empty
stdout
Standard output is empty