标签:def define bsp icp col ack sicp cal racket
1.11
求f(n)=f(n-1)+2*f(n-2)+3*f(n-3)
1 #lang racket 2 (define (fff n) 3 (define (fff-iter a b c n) 4 (if (= n 0) 5 a 6 (fff-iter b c (+ (* 3 a)(* 2 b) c) (- n 1)))) 7 (fff-iter 0 1 2 n))
递归版本
#lang racket (define (fff n) (if (< n 3) n (+ (fff (- n 1)) (* 2 (fff (- n 2))) (* 3 (fff (- n 3))))))
1.12 帕斯卡三角
#lang racket (define (pascal row col) (cond ((< row col) (error "error")) ((or (= col 0) (= col row)) 1) (else (+ (pascal (- row 1) col) (pascal (- row 1) (- col 1))))))
标签:def define bsp icp col ack sicp cal racket
原文地址:http://www.cnblogs.com/fcyworld/p/7965422.html