diff options
-rw-r--r-- | problem-6.scm | 18 |
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) |