Skip to content

Instantly share code, notes, and snippets.

View tioover's full-sized avatar

ACCOUNT MOVED tioover

View GitHub Profile
@tioover
tioover / 1.3-1.scm
Created June 27, 2013 11:15
SICP exercises 1.3
(define (max-of-three a b c)
(cond
((and (> a b) (> a c)) a)
((and (> b a) (> b c)) b)
((and (> c a) (> c b)) c)
)
)
@tioover
tioover / 1.6.scm
Created June 27, 2013 12:07
about SICP exercises 1.6
(if #f (display "a") (display "b")) ; 结果打印b 可以看出,内置的if 是惰性求值的。
(define (t a b) b)
(t (display "a") (display "b")) ; 结果打印 ab 说明在代入参数过程中是需要进行求值的。
@tioover
tioover / 1.1.scm
Created June 27, 2013 12:45
SICP exercises 1.1
10 ; 10
(+ 5 3 4) ; -> 12
(/ 6 2) ; -> 3
(+ (* 2 4)(- 4 6)) ; -> (+ 8 2) -> 6
(define a 3)
(define b (+ a 1))
(+ a b (* a b)) ; -> (+ 3 4 12) -> 19
(= a b) ; -> #f
@tioover
tioover / 1.2.scm
Created June 27, 2013 12:47
SICP exercises 1.2
(/
(+ 5 4
(- 2 (- 3 (+ 6 (/ 4 5))))
)
(* 3 (- 6 2) (- 2 7))
)
@tioover
tioover / 1.7.scm
Created June 27, 2013 13:12
SICP exercises 1.7
(define (good-enough? guess x)
(<
(abs (- 1 (/ guess (improve guess x))))
0.0001
)
)
; 这些代码不知道能不能执行。
(define (+ a b)
(if (= a 0)
b
(inc (+ (dec a) b))
)
)
(+ 4 5)
@tioover
tioover / 1-10.scm
Last active December 19, 2015 12:29
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1) (A x (- y 1))))))
(A 1 10)
(A 0 (A 1 9))
(A 0 (A 0 (A 1 8)))
; 以此类推
@tioover
tioover / 1-11.scm
Last active December 19, 2015 12:29
(define (recu_f n)
(cond ((< n 3) n)
(else (+
(recu_f (- n 1))
(* 2 (recu_f (- n 2)))
(* 3 (recu_f (- n 3)))))))
(define (iter_f x)
(define (f a b c n)
(if (= n x)
(define (pascal level n)
(cond ((or (= n 1) (= n level)) 1)
(else (+
(pascal (- level 1) (- n 1))
(pascal (- level 1) n)))))
@tioover
tioover / P
Last active December 23, 2015 12:49
def P(list, prev=None):
if prev is None:
prev = []
if not list:
print(prev)
return
for i in list:
nprev = prev[:]
nprev.append(i)
nlist = list[:]