Skip to content

Commit

Permalink
Exercises done up to 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Gryszko committed Dec 10, 2011
1 parent 497e926 commit 02233b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ex1.2.scm
@@ -0,0 +1,2 @@
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3 (- 6 2) (- 2 7)))
24 changes: 24 additions & 0 deletions ex1.3.scm
@@ -0,0 +1,24 @@
(define (square x)
(* x x))

(define (sum-of-squares a b)
(+ (square a) (square b)))

(define (square-of-two-larger a b c)
(cond ((and (>= a b) (>= b c)) (sum-of-squares a b))
((and (>= a c) (>= c b)) (sum-of-squares a c))
((and (>= b a) (>= a c)) (sum-of-squares b a))
((and (>= b c) (>= c a)) (sum-of-squares b c))
((and (>= c a) (>= a b)) (sum-of-squares c a))
((and (>= c b) (>= b a)) (sum-of-squares c b))))

(square-of-two-larger 2 3 4)
(square-of-two-larger 2 4 3)
(square-of-two-larger 3 2 4)
(square-of-two-larger 3 4 2)
(square-of-two-larger 4 2 3)
(square-of-two-larger 4 3 2)
(square-of-two-larger 3 3 3)
(square-of-two-larger 2 3 3)
(square-of-two-larger 3 2 3)
(square-of-two-larger 3 3 2)
8 changes: 8 additions & 0 deletions ex1.5.scm
@@ -0,0 +1,8 @@
(define (p) (p))

(define (test x y)
(if (= x 0)
0
y))

(test 0 (p))

0 comments on commit 02233b1

Please sign in to comment.