summaryrefslogtreecommitdiffstats
path: root/one
diff options
context:
space:
mode:
authorrsiddharth <rsiddharth@ninthfloor.org>2016-01-12 09:20:44 -0500
committerrsiddharth <rsiddharth@ninthfloor.org>2016-01-12 09:20:44 -0500
commit251afc1ce861519ab3b54d599edc9db84d3e1e56 (patch)
tree1f96215bc2f949685c379d308e5714a5567c2123 /one
parent1a07a33cae1ae2ceb76079dfa98a6c7ca2506173 (diff)
added one/three.scm
Diffstat (limited to 'one')
-rw-r--r--one/three.scm32
1 files changed, 32 insertions, 0 deletions
diff --git a/one/three.scm b/one/three.scm
new file mode 100644
index 0000000..53a8a3c
--- /dev/null
+++ b/one/three.scm
@@ -0,0 +1,32 @@
+(define-module (one three)
+ #:export (square sum-of-squares largest first-arg-2nd-largest-p
+ sum-of-squares-of-largest-two))
+
+(define (square x) (* x x))
+
+(define (sum-of-squares x y)
+ (+ (square x) (square y)))
+
+(define (largest x y z)
+ (cond ((and (>= x y)
+ (>= x z)) x)
+ ((and (>= y x)
+ (>= y z)) y)
+ ((and (>= z x)
+ (>= z y)) z)))
+
+(define (first-arg-2nd-largest-p x y z)
+ (or (and (>= x y)
+ (<= x z))
+ (and (<= x y)
+ (>= x z))
+ ))
+
+(define (sum-of-squares-of-largest-two x y z)
+ (sum-of-squares (largest x y z)
+ (cond ((first-arg-2nd-largest-p x y z)
+ x)
+ ((first-arg-2nd-largest-p y x z)
+ y)
+ ((first-arg-2nd-largest-p z x y)
+ z))))