summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--problem-9.scm25
1 files changed, 25 insertions, 0 deletions
diff --git a/problem-9.scm b/problem-9.scm
new file mode 100644
index 0000000..cc0b862
--- /dev/null
+++ b/problem-9.scm
@@ -0,0 +1,25 @@
+(use-modules (srfi srfi-1)
+ (srfi srfi-42))
+
+(define (square x)
+ (* x x))
+
+;; Euclid's formula.
+(define (generate-triple n m)
+ (list (- (square n) (square m))
+ (* 2 n m)
+ (+ (square n) (square m))))
+
+(define (generate-triples max-n max-m)
+ (concatenate
+ (list-ec (:range n 2 max-n)
+ (list-ec (:range m 1 (1- n))
+ (generate-triple n m)))))
+
+(define (find-triple-sum goal)
+ (find (lambda (triple)
+ (= (apply + triple) goal))
+ ;; Assumed that this range would be enough. :)
+ (generate-triples 100 99)))
+
+(apply * (find-triple-sum 1000))