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.
FUCKING EASY
(define (f n)
(if (= n 0) 1
(* n (f (- n 1)))))
(define (p x y)
(cond ((or (= x y) (= x 0)) 1)
(else (/ (f y)
(* (f x) (f (- y x)))))))
(define (pascal n)
(define (loop x)
(if (= x 0) (list 1) (cons (p x n) (loop (- x 1)))))
(loop n))
i think im staring to get a hang of this *grabs dick*
Name:
Anonymous2013-05-04 20:10
ur mom is recursive in bed ol
Name:
Anonymous2013-05-04 23:41
>>1
Symta:to p X Y: cond | or (X is Y) (X is 0): 1
| else: f.Y/f.X*(f Y-X)
Lisp:(define (p x y)
(cond ((or (= x y) (= x 0)) 1)
(else (/ (f y)
(* (f x) (f (- y x)))))))
Name:
Anonymous2013-05-04 23:42
fix:
Symta:
to p X Y: cond | or (X is Y) (X is 0): 1
| else: f.Y/f.X*(f Y-X)
Lisp:
(define (p x y)
(cond ((or (= x y) (= x 0)) 1)
(else (/ (f y)
(* (f x) (f (- y x)))))))
Name:
Anonymous2013-05-04 23:45
Lisp with a macro:
(to p X Y
! cond
! ! or (= X Y) (= X 0) :> 1
! ! or t :> / (f Y) (* (f X) (f (- Y X))))
expands into:
(DEFUN P (X Y)
(COND
((OR (= X Y) (= X 0))
(PROGN 1))
((OR T)
(/ (F Y) (* (F X) (F (- Y X)))))))
>>7
to pascal N
| if N is 0
| | list 1
| | pre 1
| | | let iter Ls (pascal N-1)
| | | | if Ls.tail empty?
| | | | | list 1
| | | | | list Ls.0+Ls.1 @Ls.tail,tail