Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Exercise 1.12

Name: Anonymous 2013-05-04 20:04

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: Anonymous 2013-05-05 13:55

>>9
|
| |
| |
| | |
| | | |
| | | | |
| | | | |

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List