This demonstrates a mathematical concept of a perfect number in a computational abstraction utilizing scheme.
This demonstrates a mathematical concept of a perfect number in a computational abstraction utilizing scheme, a dialect of Lisp.
Date Created:Thursday September 11th, 2008 03:09 PM
Date Modified:Tuesday January 19th, 2010 10:33 PM
A perfect number is a number such that it is the sum of all of its factors less than itself.
(define (factors x y) (if (= y 0) '() (se (if (and (= (modulo x y) 0) (not (= x y))) y '()) (factors x (- y 1)) ) ) ) (define (sumup s) (if (empty? s) 0 (+ (first s) (sumup (bf s)) ) ) ) (define (factor x) (factors x x) ) (define (perfect? x) (= (sumup (factor x)) x) ) (define (next-perf n) (if (perfect? (+ 1 n)) (+ 1 n) (next-perf (+ 1 n))) )
Please login or Click Here to register for downloads
Perfect Numbers by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com