|
|
|
|
|
by mangodrunk
5276 days ago
|
|
Using (map + (cdr L) L) doesn't work since they're different sizes (with DrRacket that I used, I see that it worked for you in your other comment, it is a very nice solution!). I'm not sure of an easy constant time way to append a zero to the end of (cdr L). The way I did it is similar to how you did it without map: (define next
(lambda (l)
(if (null? (cdr l)) '(1) (cons (+ (car l) (cadr l)) (next (cdr l)))))) (define pascal
(lambda (n)
(cond
((< n 1) '())
((= n 1) '(1))
(else (cons 1 (next (pascal (- n 1)))))))) |
|