summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-02-02 16:29:12 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-02-02 16:29:12 -0500
commit7cb3055eafac589c525543fe529caf19d64e7517 (patch)
tree7f7e8e26ebb0d5c2ee8dd6801adfde8f9a21ee6c
parentd665c637c9877a120e8affd020fb754874250361 (diff)
Solve problem 5.
-rw-r--r--problem-5.scm24
1 files changed, 24 insertions, 0 deletions
diff --git a/problem-5.scm b/problem-5.scm
new file mode 100644
index 0000000..3fe26b5
--- /dev/null
+++ b/problem-5.scm
@@ -0,0 +1,24 @@
+(use-modules (srfi srfi-1))
+
+(define (divisible? m n)
+ (zero? (modulo m n)))
+
+(define (divisible-by-all? min max x)
+ (define (inner x n)
+ (cond ((= n max)
+ #t)
+ ((divisible? x n)
+ (inner x (1+ n)))
+ (else
+ #f)))
+ (inner x min))
+
+(define (smallest-multiple min max)
+ (define (inner n)
+ (if (divisible-by-all? min max n)
+ n
+ (inner (1+ n))))
+ (inner 1))
+
+;; WARNING: Takes a long time.
+(smallest-multiple 1 21)