This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(if #f (display "a") (display "b")) ; 结果打印b 可以看出,内置的if 是惰性求值的。 | |
(define (t a b) b) | |
(t (display "a") (display "b")) ; 结果打印 ab 说明在代入参数过程中是需要进行求值的。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(/ | |
(+ 5 4 | |
(- 2 (- 3 (+ 6 (/ 4 5)))) | |
) | |
(* 3 (- 6 2) (- 2 7)) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (good-enough? guess x) | |
(< | |
(abs (- 1 (/ guess (improve guess x)))) | |
0.0001 | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 这些代码不知道能不能执行。 | |
(define (+ a b) | |
(if (= a 0) | |
b | |
(inc (+ (dec a) b)) | |
) | |
) | |
(+ 4 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) | |
; 以此类推 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (pascal level n) | |
(cond ((or (= n 1) (= n level)) 1) | |
(else (+ | |
(pascal (- level 1) (- n 1)) | |
(pascal (- level 1) n))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[:] |