2010년 9월 29일 수요일

[sicp] 1.12

Exercise 1.12.  The following pattern of numbers is called Pascal's triangle.

The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it.35 Write a procedure that computes elements of Pascal's triangle by means of a recursive process.


#lang scheme
(define (pascal_triangle a b )
  (cond
       ((= a b) 1)
        ((= a 2) 1)
         ((= b 1) 1)
       (else (+ (pascal_triangle (- a 1) (- b 2))
               (pascal_triangle (- a 1) (- b 1))))))


--------------------------------------------------------------------------------

;;; sicp 1.12
#lang scheme
(define (pascal_triangle a b )
  (cond
       ((< a b) '틀렸음)
       ((= a b) 1)
         ((= b 1) 1)
       (else (+ (pascal_triangle (- a 1) (- b 1))
               (pascal_triangle (- a 1) b)))))

 

수정함


댓글 없음:

댓글 쓰기