summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-02-02 16:45:08 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-02-02 16:45:08 -0500
commit055cb2a5fb08342d6b673a8355f4c052fd6fa367 (patch)
tree65065249c81b678ef43f3718acbe07035b485c81
parent7cb3055eafac589c525543fe529caf19d64e7517 (diff)
Solve problem 6.
-rw-r--r--problem-6.scm18
1 files changed, 18 insertions, 0 deletions
diff --git a/problem-6.scm b/problem-6.scm
new file mode 100644
index 0000000..62852a0
--- /dev/null
+++ b/problem-6.scm
@@ -0,0 +1,18 @@
+(use-modules (srfi srfi-41))
+
+(define (square x)
+ (* x x))
+
+(define naturals (stream-from 1))
+
+(define squares
+ (stream-map square naturals))
+
+(define (sum-stream n stream)
+ (stream-fold + 0 (stream-take n stream)))
+
+(define (sum-square-difference n)
+ (- (square (sum-stream n naturals))
+ (sum-stream n squares)))
+
+(sum-square-difference 100)