'Write a function find-abundant that takes a positive number and produces a list of all abundant numbers no greater than the given one

i would like to to that thing but i don't know how to do that Write a function find-abundant that takes as parameters a positive number and produces a list of all abundant numbers no greater than the given one, in order from the largest to the smallest. (find-abundant 25)



Solution 1:[1]

(define (find-abundant n)
  (define (check-abundant n)
    (define (sum-of-proper-divisors n)
      (let loop ((i (sub1 n)))
        (cond
          [(= i 1) 1]
          [(= (remainder n i) 0)
           (+ i (loop (sub1 i)))]
          [else (loop (sub1 i))])))
  (cond
    ((> (sum-of-proper-divisors n)  n) 1)
    (else 0)))
  (define (enumerate-interval high low)
    (if (> low high)
        null
        (cons high (enumerate-interval (- high 1) low))))
  (filter (lambda (n)
            (= (check-abundant n) 1))
          (enumerate-interval (- n 1) 12)))

It may look complicated at first glance but there are two nested procedure inside find-abundant also check-abundant has a nested procedure which is sum-of-proper-divisors. You can seperate all procedures too.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1