RosettaCodeData/Task/Arithmetic-Rational/EchoLisp/arithmetic-rational-1.echolisp
2016-12-05 23:44:36 +01:00

6 lines
243 B
Text

;; Finding perfect numbers
(define (sum/inv n) ;; look for div's in [2..sqrt(n)] and add 1/n
(for/fold (acc (/ n)) [(i (in-range 2 (sqrt n)))]
#:break (> acc 1) ; no hope
(when (zero? (modulo n i ))
(set! acc (+ acc (/ i) (/ i n))))))