Skip to content

Commit

Permalink
1.2.4 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Gryszko committed Apr 18, 2012
1 parent 763a04d commit 8ecb5a8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions ex1.16.scm
@@ -0,0 +1 @@
`xzc`xc
18 changes: 18 additions & 0 deletions ex1.17.scm
@@ -0,0 +1,18 @@
(define (even? n)
(= (remainder n 2) 0))

(define (halve n)
(/ n 2))

(define (double n)
(+ n n))

(define (* a b)
(cond ((= b 0) 0)
((even? b) (* (double a) (halve b)))
(else (+ a (* a (- b 1))))))

(* 2 2)
(* 3 4)
(* 15 11)

Empty file added ex1.18.scm
Empty file.
14 changes: 14 additions & 0 deletions ex1.19.scm
@@ -0,0 +1,14 @@
(define (fib n)
(fib-iter 1 0 0 1 n))

(define (fib-iter a b p q count)
(cond ((= count 0) b)
((even? count) (fib-iter a
b
<??> ; compute p’
<??> ; compute q’ (/ count 2)))
(else (fib-iter (+ (* b q) (* a q) (* a p))
(+ (* b p) (* a q))
p
q
(- count 1)))))

0 comments on commit 8ecb5a8

Please sign in to comment.