codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
; the sum of two squares (define (isqrt n) (let loop ((x n) (y (quotient (+ n 1) 2))) (if (<= 0 (- y x) 1) x (loop y (quotient (+ y (quotient n y)) 2))))) (define (squares n) (let loop ((x (isqrt n)) (y 0) (zs '())) (cond ((< x y) zs) ((< (+ (* x x) (* y y)) n) (loop x (+ y 1) zs)) ((< n (+ (* x x) (* y y))) (loop (- x 1) y zs)) (else (loop (- x 1) (+ y 1) (cons (list x y) zs)))))) (display (squares 50)) (newline) (display (squares 48612265)) (newline) (display (squares 999)) (newline)
Private
[
?
]
Run code
Submit