aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science
diff options
context:
space:
mode:
authorSteve Lee <me@xiangyangli.com>2017-12-02 06:10:20 +0800
committerSteve Lee <me@xiangyangli.com>2017-12-02 06:10:20 +0800
commit9b939e65cf007e859dabe5de6b31d255d647e0ce (patch)
treebf9229755f4e58bb81add73c7f3c32fe4023e7ec /Computer_Science
parent5dc061ae68ac3b5b28556bdbd1574579d8da33e7 (diff)
download42-9b939e65cf007e859dabe5de6b31d255d647e0ce.tar.xz
42-9b939e65cf007e859dabe5de6b31d255d647e0ce.zip
category
Diffstat (limited to 'Computer_Science')
-rw-r--r--Computer_Science/SICP/README.md1
-rw-r--r--Computer_Science/SICP/c.c8
-rw-r--r--Computer_Science/SICP/ch1_3.scm33
-rw-r--r--Computer_Science/SICP/ch2_2_2.scm134
-rw-r--r--Computer_Science/SICP/ex1-1.scm16
-rw-r--r--Computer_Science/SICP/ex2-2.scm97
-rw-r--r--Computer_Science/SICP/ex2-4.scm86
-rw-r--r--Computer_Science/SICP/ex2_17.scm188
-rw-r--r--Computer_Science/SICP/ex2_7.scm90
-rw-r--r--Computer_Science/SICP/test.pl64
-rw-r--r--Computer_Science/SICP/test.scm4
-rw-r--r--Computer_Science/SICP/tmp.scm133
12 files changed, 854 insertions, 0 deletions
diff --git a/Computer_Science/SICP/README.md b/Computer_Science/SICP/README.md
new file mode 100644
index 0000000..1082579
--- /dev/null
+++ b/Computer_Science/SICP/README.md
@@ -0,0 +1 @@
+Exercises for SICP.
diff --git a/Computer_Science/SICP/c.c b/Computer_Science/SICP/c.c
new file mode 100644
index 0000000..fae921b
--- /dev/null
+++ b/Computer_Science/SICP/c.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("hello world\n");
+ return 0;
+
+}
diff --git a/Computer_Science/SICP/ch1_3.scm b/Computer_Science/SICP/ch1_3.scm
new file mode 100644
index 0000000..76fadb7
--- /dev/null
+++ b/Computer_Science/SICP/ch1_3.scm
@@ -0,0 +1,33 @@
+(define (cube x) (* x x x))
+
+;; Sum from a to b.
+
+(define (sum term a next b)
+ (if (> a b )
+ 0
+ (+ (term a)
+ (sum term (next a) next b))))
+
+(define (inc n) (+ n 1))
+(define (sum-cubes a b)
+ (sum cube a inc b))
+
+(sum-cubes 1 10)
+
+(define (identity x) x)
+(define (sum-integers a b)
+ (sum identity a inc b))
+(sum-integers 1 10)
+
+(define (pi-sum a b)
+ (define (pi-term x)
+ (/ 1.0 (* x (+ x 2))))
+ (define (pi-next x)
+ (+ x 4))
+(* 8 (sum pi-term a pi-next b)))
+(pi-sum 1 1000)
+
+(define (intergral f a b dx)
+ (define (add-dx x) (+ x dx))
+ (* (sum f (+ a (/ dx 2.0)) add-dx b) dx))
+(intergral cube 0 1 0.0001)
diff --git a/Computer_Science/SICP/ch2_2_2.scm b/Computer_Science/SICP/ch2_2_2.scm
new file mode 100644
index 0000000..fbcf46d
--- /dev/null
+++ b/Computer_Science/SICP/ch2_2_2.scm
@@ -0,0 +1,134 @@
+(define x (cons (list 1 2) (list 3 4)))
+
+(define (length x)
+ (cond ((null? x) 0)
+ ((not (pair? x)) 1)
+ (else (+ (length (cdr x)) 1))))
+
+(define (count-leaves x)
+ (cond ((null? x) 0)
+ ((not (pair? x)) 1)
+ (else (+ (count-leaves (car x))
+ (count-leaves (cdr x))))))
+
+(length x)
+(count-leaves x)
+
+;; Exercise 2.24
+;; Length is wrong !!!
+;; (car (cdr )) to get the left leaf
+
+(define list-1 (list 1 (list 2 (list 3 4))))
+(length list-1)
+(count-leaves list-1)
+
+;; Exercise 2.25
+(car (cdr (car (cdr (cdr (list 1 3 (list 5 7) 9))))))
+(car (car (list (list 7))))
+(car (cdr (car (cdr (car (cdr (car (cdr (car (cdr (car (cdr (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7))))))))))))))))))
+
+;; Exercise 2.26
+(define z (list 1 1 1))
+(define x (list 1 2 3))
+(define y (list 4 5 6))
+
+(append x y)
+(car (car (cons x y)))
+(car (car (list x y)))
+
+(car (cdr (cons x y)))
+(car (car (cdr (list x y))))
+
+;; Exercise 2.27
+
+!!! ;; Exercise2.18
+(define (reverse items)
+ (if (null? (cdr items))
+ items
+ (append (reverse (cdr items))
+ (cons (car items) nil))))
+
+(define (deep-reverse items)
+ (if (null? (cdr items))
+ (if (not (pair? (car items)))
+ items
+ (cons (deep-reverse (car items)) nil))
+ (append (cond ((pair? (cdr items))
+ (deep-reverse (cdr items)))
+ ((pair? (car (cdr items)))
+ (cons (deep-reverse (car (cdr items))) nil))
+ ;; Some problem in else.
+ (else (deep-reverse (cdr items))))
+ (cond ((pair? (car items))
+ (cons (deep-reverse (car items)) nil))
+ (else (cons (car items) nil))))))
+
+(define y
+ (list (list 1 2) (list 3 4) (list 5 6)))
+
+(define z (list (list 1 2)))
+(deep-reverse z)
+(reverse z)
+
+(reverse y)
+(deep-reverse y)
+
+(cons (deep-reverse (car (list (list 1 2)))) nil)
+
+(deep-reverse
+ (list 1 (list 2 3) 4 (list 5 6)))
+
+(define x
+ (list (list 1 2) (list 3 4)))
+(list (list 1 2) (list 3 4))
+(reverse x)
+(deep-reverse x)
+(deep-reverse (list 3 4))
+(deep-reverse (list 1 2 3))
+(reverse (list 1 2 3))
+
+;; Exercise2.28
+
+(define (fringe items)
+ (if (not (pair? items))
+ (list items)
+ (append (fringe (car items))
+ (if (null? (cdr items))
+ nil
+ (fringe (cdr items))))))
+
+
+(append (list 3) (list 4))
+(append (list 4) nil)
+(append nil (list 4))
+(list 4)
+(list 3 4)
+(list nil)
+(append (list nil) (list nil))
+
+(define x
+ (list (list 1 2) (list 3 4)))
+(fringe x)
+(fringe (list x x))
+(list 1 2 3 4)
+(list 1 2 3 4 1 2 3 4)
+
+(append (list 2) (list 3))
+(list 2 3)
+(list (list 1 2) (list 3 4))
+(list (list 1 2) 3 4)
+
+;; Exercise2.29
+
+(define (make-mobile left right)
+ (list left right))
+
+(define (make-branch length structure)
+ (list length structure))
+
+(define (left-branch mobile)
+ (car (mobile)))
+(define (right-branch mobile)
+ (cdr (mobile)))
+
+(define branch-length)
diff --git a/Computer_Science/SICP/ex1-1.scm b/Computer_Science/SICP/ex1-1.scm
new file mode 100644
index 0000000..7f0b307
--- /dev/null
+++ b/Computer_Science/SICP/ex1-1.scm
@@ -0,0 +1,16 @@
+(define (factorial n)
+ (if (= n 1)
+ n
+ (* n (factorial (- n 1)))
+ )
+ )
+
+(factorial 11000)
+
+(define (fib n)
+ (cond ((= n 0) 0)
+ ((= n 1) 1)
+ (else (+ (fib (- n 1))
+ (fib (- n 2))))))
+
+(fib 6)
diff --git a/Computer_Science/SICP/ex2-2.scm b/Computer_Science/SICP/ex2-2.scm
new file mode 100644
index 0000000..3a66fd3
--- /dev/null
+++ b/Computer_Science/SICP/ex2-2.scm
@@ -0,0 +1,97 @@
+(define (make-point x y) (cons x y))
+(define (x-point x) (car x))
+(define (y-point x) (cdr x))
+(define (point-add x y)
+ (make-point
+ (+ (x-point x) (x-point y))
+ (+ (y-point x) (y-point y))))
+
+(define (make-segment start-point end-point)
+ (cons start-point end-point))
+
+(define (start-segment segment) (car segment))
+(define (end-segment segment) (cdr segment))
+
+(define (midpoint-segment segment)
+ (make-point
+ (/ (+ (x-point (start-segment segment))
+ (x-point (end-segment segment)))
+ 2)
+ (/ (+ (y-point (start-segment segment))
+ (y-point (end-segment segment)))
+ 2)))
+
+(define (print-point p)
+ (newline)
+ (display "(")
+ (display (x-point p))
+ (display ",")
+ (display (y-point p))
+ (display ")"))
+
+;Ex2-3 without abstraction barries;
+(define point-a (make-point 1 3))
+(define point-b (make-point 11 9))
+(define segment-a (make-segment point-a point-b))
+(define midpoint-a (midpoint-segment segment-a))
+(print-point (make-point 1 2))
+(print-point (end-segment segment-a))
+(print-point (midpoint-segment segment-a))
+
+
+(define (make-rectangle pointA pointB) (cons pointA pointB))
+
+(define (right-top-point rectangle)
+ (cdr rectangle))
+(define (left-bottom-point rectangle)
+ (car rectangle))
+
+(define (calculate-perimeter rectangle)
+ (* 2 (+ (- (y-point (right-top-point rectangle))
+ (y-point (left-bottom-point rectangle)))
+ (- (x-point (right-top-point rectangle))
+ (x-point (left-bottom-point rectangle))))))
+
+(define (calculate-area rectangle)
+ (* (- (y-point (right-top-point rectangle))
+ (y-point (left-bottom-point rectangle)))
+ (- (x-point (right-top-point rectangle))
+ (x-point (left-bottom-point rectangle)))))
+
+(define rectangleA (make-rectangle point-a point-b))
+
+(calculate-perimeter rectangleA)
+(calculate-area rectangleA)
+
+;Ex2-3 with abstraction barriers.
+;Use left-bottom-point and right-top-point as abstraction barriers.
+
+(define (make-rectangle pointA len width)
+ (cons pointA (cons len width)))
+
+(define (left-bottom-point rectangle)
+ (car rectangle))
+(define (right-top-point rectangle)
+ (make-point
+ (+ (x-point (car rectangle)) (car (cdr rectangle)))
+ (+ (y-point (car rectangle)) (cdr (cdr rectangle)))))
+
+(define (calculate-perimeter rectangle)
+ (* 2 (+ (- (y-point (right-top-point rectangle))
+ (y-point (left-bottom-point rectangle)))
+ (- (x-point (right-top-point rectangle))
+ (x-point (left-bottom-point rectangle))))))
+
+(define (calculate-area rectangle)
+ (* (- (y-point (right-top-point rectangle))
+ (y-point (left-bottom-point rectangle)))
+ (- (x-point (right-top-point rectangle))
+ (x-point (left-bottom-point rectangle)))))
+
+(define rectangleB (make-rectangle point-a 10 10))
+
+(left-bottom-point rectangleB)
+(right-top-point rectangleB)
+
+(calculate-area rectangleB)
+(calculate-perimeter rectangleB)
diff --git a/Computer_Science/SICP/ex2-4.scm b/Computer_Science/SICP/ex2-4.scm
new file mode 100644
index 0000000..3ad6d15
--- /dev/null
+++ b/Computer_Science/SICP/ex2-4.scm
@@ -0,0 +1,86 @@
+(define (cons x y)
+ (define (dispatch m)
+ (cond ((= m 0) x)
+ ((= m 1) y)
+ (else
+ (error "Argument not 0 or 1:
+ CONS" m))))
+ dispatch)
+
+(define (car z) (z 0))
+(define (cdr z) (z 1))
+
+(define pair (cons 111 2))
+
+(car pair)
+
+;Exercise 2.4
+(define (cons x y)
+ (lambda (m) (m x y)))
+
+(define (car z)
+ (z (lambda (p q) p)))
+(define (cdr z)
+ (z (lambda (p q) q)))
+
+(cdr (cons 1 2))
+
+;Exercise 2.5
+(define (cons x y) (* (pow 2 x) (pow 3 y)))
+
+(define (pow x y)
+ (if (= y 0)
+ 1
+ (* x (pow x (- y 1)))))
+
+
+(define (car z)
+ (if (not (= (modulo z 2) 0))
+ 0
+ (+ (car (/ z 2)) 1)))
+(define (cdr z)
+ (if (not (= (modulo z 3) 0))
+ 0
+ (+ (cdr (/ z 3)) 1)))
+
+(car (cons 10 2))
+(cdr (cons 1 119))
+
+;Exercise 2.6
+
+(define zero (lambda (f) (lambda (x) x)))
+
+(define (add-1 n)
+ (lambda (f) (lambda (x) (f ((n f) x)))))
+;; (add-1 zero)
+;; (lambda (f) (lambda (x) (f ((zero f) x))))
+;; (lambda (f) (lambda (x) (f (f x))))
+
+(define (add a b)
+ (lambda (f)
+ (lambda (x)
+ ((a f) ((b f) x)))))
+(define one (lambda(f) (lambda (x) (f x))))
+(define two (lambda(f) (lambda (x) (f (f x)))))
+(define three (lambda(f) (lambda (x) (f (f (f x))))))
+
+(define (add a b)
+ (lambda (f)
+ (lambda (x)
+ ((a f) ((b f) x)))))
+
+;; Excellent answer for add a b, actually it's the
+;; same compared with above imp.
+(define (add a b)
+ ((a add-1) b))
+
+(zero 1)
+
+(define (square x) (* x x))
+
+((two square) 2)
+((three square) 2)
+
+(((add two one) square) 2)
+
+
diff --git a/Computer_Science/SICP/ex2_17.scm b/Computer_Science/SICP/ex2_17.scm
new file mode 100644
index 0000000..37e3eb3
--- /dev/null
+++ b/Computer_Science/SICP/ex2_17.scm
@@ -0,0 +1,188 @@
+(cons 1
+ (cons 2
+ (cons 3
+ (cons 4 nil))))
+
+(define one-through-four (list 1 2 3 4))
+
+one-through-four
+
+(car one-through-four)
+(cdr one-through-four)
+
+(define (list-ref items n)
+ (if (= n 0)
+ (car items)
+ (list-ref (cdr items)
+ (- n 1))))
+
+(list-ref one-through-four 3)
+
+(define (length items)
+ (if (null? items)
+ 0
+ (+ 1 (length (cdr items)))))
+
+(define (length items)
+ (define (length-iter a count)
+ (if (null? a)
+ count
+ (length-iter (cdr a)
+ (+ 1 count))))
+ (length-iter items 0))
+
+(define odds (list 1 3 5 7))
+(define squares (list 1 4 9 16 25))
+
+(define (append list1 list2)
+ (if (null? list1)
+ list2
+ (cons (car list1)
+ (append (cdr list1)
+ list2))))
+
+(append odds squares)
+
+;; Exercise2.17
+(define (last-pair items)
+ (if (null? (cdr items))
+ (car items)
+ (last-pair (cdr items))))
+
+(last-pair (list 1 2 3 4 9 23))
+
+;; Exercise2.18
+(define (reverse items)
+ (if (null? (cdr items))
+ items
+ (append (reverse (cdr items))
+ (cons (car items) nil))))
+
+(list 4 3 2 1)
+(reverse (list 1 2 3 4))
+
+;; Exercise2.19 Counting change
+
+(define (count-change amount)
+ (cc amount 5))
+
+(define us-coins
+ (list 50 25 10 5 1))
+(define uk-coins
+ (list 100 50 20 10 5 2 1 0.5))
+
+(define (cc amount coin-values)
+ (cond ((= amount 0)
+ 1)
+ ((or (< amount 0)
+ (no-more? coin-values))
+ 0)
+ (else
+ (+ (cc
+ amount
+ (except-first-denomination
+ coin-values))
+ (cc
+ (- amount
+ (first-denomination
+ coin-values))
+ coin-values)))))
+
+(define (first-denomination coin-values)
+ (car coin-values))
+(define (no-more? coin-values)
+ (null? coin-values))
+(define (except-first-denomination coin-values)
+ (if (null? coin-values)
+ null?
+ (cdr coin-values)))
+
+(cc 100 us-coins)
+
+;; Exercise2.20
+
+(define (same-parity x . y)
+ (define (find-same-parity parity z)
+ (if (null? z)
+ nil
+ (if (= parity 1)
+ (if (odd? (car z))
+ (cons (car z) (find-same-parity 1 (cdr z)))
+ (find-same-parity 1 (cdr z)))
+ (if (even? (car z))
+ (cons (car z) (find-same-parity 2 (cdr z)))
+ (find-same-parity 2 (cdr z))))))
+ (if (odd? x)
+ (cons x (find-same-parity 1 y))
+ (cons x (find-same-parity 2 y))))
+
+(define (same-parity first . rest)
+ (define (same-parity-iter source dist remainder-val)
+ (if (null? source)
+ dist
+ (same-parity-iter (cdr source)
+ (if (= (remainder (car source) 2) remainder-val)
+ (append dist (list (car source)))
+ dist)
+ remainder-val)))
+ (same-parity-iter rest (list first) (remainder first 2)))
+(same-parity 1 2 3 4 5 6 7)
+(same-parity 2 3 4 5 6 7)
+
+;; Exercise2.21
+(define (map proc items)
+ (if (null? items)
+ nil
+ (cons (proc (car items))
+ (map proc (cdr items)))))
+
+(define (squares items)
+ (map (lambda (x) (* x x)) items))
+(squares (list 1 2 3 4))
+
+;; Exercise2.22
+(define (square x) (* x x))
+(define (square-list items)
+ (define (iter things answer)
+ (if (null? things)
+ answer
+ (iter (cdr things)
+ (cons (square (car things))
+ answer))))
+ (iter items nil))
+;; Modify one
+(define (square-list items)
+ (define (iter things answer)
+ (if (null? things)
+ answer
+ (iter (cdr things)
+ (cons answer
+ (square
+ (car things))))))
+ (iter items nil))
+(square-list (list 1 2 3 4 5))
+(list 1 4 9 16 25)
+;; The right one;
+(cons 1 (cons 4 (cons 9 (cons 16 (cons 25 nil)))))
+;; The wrong one
+(cons (cons (cons (cons (cons nil 1) 4) 9) 16) 25)
+
+;; Exercise2.23
+;; why nil print '()
+(define (for-each proc items)
+ (define (iter proc items item)
+ (if (null? item)
+ nil
+ (proc item))
+ (if (null? items)
+ nil
+ (iter proc (cdr items) (car items))))
+ (iter proc items nil))
+
+(for-each
+ (lambda (x) (newline) (display x))
+ (list 57 321 88))
+
+(cons (list 1 2) (list 3 4))
+
+
diff --git a/Computer_Science/SICP/ex2_7.scm b/Computer_Science/SICP/ex2_7.scm
new file mode 100644
index 0000000..54e8b70
--- /dev/null
+++ b/Computer_Science/SICP/ex2_7.scm
@@ -0,0 +1,90 @@
+;; 2.1.4 Extended Exercise:Interval Arithmetic
+
+(define (add-interval x y)
+ (make-interval (+ (lower-bound x)
+ (lower-bound y))
+ (+ (upper-bound x)
+ (upper-bound y))))
+
+(define (mul-interval x y)
+ (let ((p1 (* (lower-bound x)
+ (lower-bound y)))
+ (p2 (* (lower-bound x)
+ (upper-bound y)))
+ (p3 (* (upper-bound x)
+ (lower-bound y)))
+ (p4 (* (upper-bound x)
+ (upper-bound y))))
+ (make-interval (min p1 p2 p3 p4)
+ (max p1 p2 p3 p4))))
+
+;; Todo:ensure this is right
+(define (div-interval x y)
+ (if (>= 0 (* (lower-bound y) (upper-bound y)))
+ (error "error!" y)
+ (mul-interval x
+ (make-interval
+ (/ 1.0 (upper-bound y))
+ (/ 1.0 (lower-bound y))))))
+
+(define (make-interval a b) (cons a b))
+
+;; Exercise:2.7
+
+;; My version
+;; (define (lower-bound interval) (car interval))
+;; (define (upper-bound interval) (cdr interval))
+
+(define (lower-bound interval) (min (car interval)
+ (cdr interval)))
+(define (upper-bound interval) (max (car interval)
+ (cdr interval)))
+
+;; ???
+;; Exercise:2.8
+(define (sub-interval x y)
+ (make-interval (- (lower-bound x) (upper-bound y))
+ (- (upper-bound x) (lower-bound y))))
+
+(define (display-interval i)
+ (newline)
+ (display "[")
+ (display (lower-bound i))
+ (display ",")
+ (display (upper-bound i))
+ (display "]"))
+
+(define i (make-interval 1 5))
+(define j (make-interval 1 4))
+
+(display-interval i)
+(display-interval (sub-interval i j))
+(display-interval (sub-interval j i))
+
+;; Exercise:2.9
+
+(define (interval-width i)
+ (/ (- (upper-bound i) (lower-bound i))
+ 2))
+
+(interval-width (make-interval 2 8))
+
+;; Exercise:2.10
+
+(define (div-interval x y)
+ (if (>= 0 (* (lower-bound y) (upper-bound y)))
+ (error "error!" y)
+ (mul-interval x
+ (make-interval
+ (/ 1.0 (upper-bound y))
+ (/ 1.0 (lower-bound y))))))
+
+(define (make-interval a b) (cons a b))
+
+(define span-0 (make-interval -1 2))
+
+(display-interval (div-interval i j))
+(display-interval (div-interval i span-0))
+
+;; Exercise:2.11
+
diff --git a/Computer_Science/SICP/test.pl b/Computer_Science/SICP/test.pl
new file mode 100644
index 0000000..2d52981
--- /dev/null
+++ b/Computer_Science/SICP/test.pl
@@ -0,0 +1,64 @@
+
+#!/usr/bin/perl
+# Author: Todd Larason <jtl@molehill.org>
+# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $
+
+# use the resources for colors 0-15 - usually more-or-less a
+# reproduction of the standard ANSI colors, but possibly more
+# pleasing shades
+
+# colors 16-231 are a 6x6x6 color cube
+for ($red = 0; $red < 6; $red++) {
+ for ($green = 0; $green < 6; $green++) {
+ for ($blue = 0; $blue < 6; $blue++) {
+ printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\",
+ 16 + ($red * 36) + ($green * 6) + $blue,
+ int ($red * 42.5),
+ int ($green * 42.5),
+ int ($blue * 42.5));
+ }
+ }
+}
+
+# colors 232-255 are a grayscale ramp, intentionally leaving out
+# black and white
+for ($gray = 0; $gray < 24; $gray++) {
+ $level = ($gray * 10) + 8;
+ printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\",
+ 232 + $gray, $level, $level, $level);
+}
+
+
+# display the colors
+
+# first the system ones:
+print "System colors:\n";
+for ($color = 0; $color < 8; $color++) {
+ print "\x1b[48;5;${color}m ";
+}
+print "\x1b[0m\n";
+for ($color = 8; $color < 16; $color++) {
+ print "\x1b[48;5;${color}m ";
+}
+print "\x1b[0m\n\n";
+
+# now the color cube
+print "Color cube, 6x6x6:\n";
+for ($green = 0; $green < 6; $green++) {
+ for ($red = 0; $red < 6; $red++) {
+ for ($blue = 0; $blue < 6; $blue++) {
+ $color = 16 + ($red * 36) + ($green * 6) + $blue;
+ print "\x1b[48;5;${color}m ";
+ }
+ print "\x1b[0m ";
+ }
+ print "\n";
+}
+
+
+# now the grayscale ramp
+print "Grayscale ramp:\n";
+for ($color = 232; $color < 256; $color++) {
+ print "\x1b[48;5;${color}m ";
+}
+print "\x1b[0m\n";
diff --git a/Computer_Science/SICP/test.scm b/Computer_Science/SICP/test.scm
new file mode 100644
index 0000000..46f73ee
--- /dev/null
+++ b/Computer_Science/SICP/test.scm
@@ -0,0 +1,4 @@
+(define (plus x y)
+ (+ x y))
+
+(plus 2 3)
diff --git a/Computer_Science/SICP/tmp.scm b/Computer_Science/SICP/tmp.scm
new file mode 100644
index 0000000..9bcc810
--- /dev/null
+++ b/Computer_Science/SICP/tmp.scm
@@ -0,0 +1,133 @@
+(define x (cons (list 1 2) (list 3 4)))
+
+(define (length x)
+ (cond ((null? x) 0)
+ ((not (pair? x)) 1)
+ (else (+ (length (cdr x)) 1))))
+
+(define (count-leaves x)
+ (cond ((null? x) 0)
+ ((not (pair? x)) 1)
+ (else (+ (count-leaves (car x))
+ (count-leaves (cdr x))))))
+
+(length x)
+(count-leaves x)
+
+;; Exercise 2.24
+;; Length is wrong !!!
+;; (car (cdr )) to get the left leaf
+
+(define list-1 (list 1 (list 2 (list 3 4))))
+(length list-1)
+(count-leaves list-1)
+
+;; Exercise 2.25
+(car (cdr (car (cdr (cdr (list 1 3 (list 5 7) 9))))))
+(car (car (list (list 7))))
+(car (cdr (car (cdr (car (cdr (car (cdr (car (cdr (car (cdr (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7))))))))))))))))))
+
+;; Exercise 2.26
+(define x (list 1 2 3))
+(define y (list 4 5 6))
+
+(append x y)
+(car (car (cons x y) ))
+(car (car (list x y)))
+
+(car (cdr (cons x y)))
+(car (car (cdr (list x y))))
+
+;; Exercise 2.27
+
+!!! ;; Exercise2.18
+(define (reverse items)
+ (if (null? (cdr items))
+ items
+ (append (reverse (cdr items))
+ (cons (car items) nil))))
+
+(define (deep-reverse items)
+ (if (null? (cdr items))
+ (if (not (pair? (car items)))
+ items
+ (cons (deep-reverse (car items)) nil))
+ (append (cond ((pair? (cdr items))
+ (deep-reverse (cdr items)))
+ ((pair? (car (cdr items)))
+ (cons (deep-reverse (car (cdr items))) nil))
+ ;; Some problem in else.
+ (else (deep-reverse (cdr items))))
+ (cond ((pair? (car items))
+ (cons (deep-reverse (car items)) nil))
+ (else (cons (car items) nil))))))
+
+(define y
+ (list (list 1 2) (list 3 4) (list 5 6)))
+
+(define z (list (list 1 2)))
+(deep-reverse z)
+(reverse z)
+
+(reverse y)
+(deep-reverse y)
+
+(cons (deep-reverse (car (list (list 1 2)))) nil)
+
+(deep-reverse
+ (list 1 (list 2 3) 4 (list 5 6)))
+
+(define x
+ (list (list 1 2) (list 3 4)))
+(list (list 1 2) (list 3 4))
+(reverse x)
+(deep-reverse x)
+(deep-reverse (list 3 4))
+(deep-reverse (list 1 2 3))
+(reverse (list 1 2 3))
+
+;; Exercise2.28
+
+(define (fringe items)
+ (if (not (pair? items))
+ (list items)
+ (append (fringe (car items))
+ (if (null? (cdr items))
+ nil
+ (fringe (cdr items))))))
+
+
+(append (list 3) (list 4))
+(append (list 4) nil)
+(append nil (list 4))
+(list 4)
+(list 3 4)
+(list nil)
+(append (list nil) (list nil))
+
+(define x
+ (list (list 1 2) (list 3 4)))
+(fringe x)
+(fringe (list x x))
+(list 1 2 3 4)
+(list 1 2 3 4 1 2 3 4)
+
+(append (list 2) (list 3))
+(list 2 3)
+(list (list 1 2) (list 3 4))
+(list (list 1 2) 3 4)
+
+;; Exercise2.29
+
+(define (make-mobile left right)
+ (list left right))
+
+(define (make-branch length structure)
+ (list length structure))
+
+(define (left-branch mobile)
+ (car (mobile)))
+(define (right-branch mobile)
+ (cdr (mobile)))
+
+(define branch-length)