Browse files

2.4-2.6

  • Loading branch information...
1 parent e4decba commit 184106b12012c4a8777ec6c697eef2b8724d0f33 Sayem Islam committed May 24, 2012
Showing with 41 additions and 0 deletions.
  1. +19 −0 2.1/2.5.scm
  2. +22 −0 2.1/2.6.scm
View
19 2.1/2.5.scm
@@ -3,3 +3,22 @@
(* (expt 2 a)
(expt 3 b)))
+; counts number of times d is divided into n:
+
+(define (num-divs n d)
+ (define (iter x count)
+ (if (= 0 (remainder x d))
+ (iter (/ x d) (+ 1 count))
+ count))
+ (iter n 0))
+
+(define (car x)
+ (num-divs x 2))
+
+(define (cdr x)
+ (num-divs x 3))
+
+
+; (car (cons 9 70)) = 9
+
+; (cdr (cons 9 70)) = 70
View
22 2.1/2.6.scm
@@ -0,0 +1,22 @@
+
+(define zero (lambda (f) (lambda (x) x)))
+
+(define (add-1 n) (lambda (f) (lambda (x) (f ((n f) x)))))
+
+(define (inc n)
+ (+ n 1))
+
+(define one
+ (lambda (f) (lambda (x) (f x))))
+
+(define two
+ (lambda (f) (lambda (x) (f (f x)))))
+
+
+; ((one inc) 5) = 6
+
+; ((two inc) 5) = 7
+
+; ((one inc) 15) = 16
+
+; ((two inc) 15) = 17

0 comments on commit 184106b

Please sign in to comment.