4 ms·
And now, for your entertainment, an implementation in a language I'm pretty confident has a user base of just me: gimli> pascal <- local { gimli+ loo
by tmoertel 15y ago
And now, for your entertainment, an implementation in a language I'm pretty confident has a user base of just me:
gimli> pascal <- local {
gimli+ loop <- function(n, xs) {
gimli+ if n > 0 then do
gimli+ print(xs);
gimli+ loop(n - 1, [0, xs] + [xs, 0]);
gimli+ end
gimli+ };
gimli+ function(n) loop(n, [1])
gimli+ }
func(n) loop(n,[1])
gimli> pascal(0)
F
gimli> pascal(1)
1
F
gimli> pascal(9)
1
[1,1]
[1,2,1]
[1,3,3,1]
[1,4,6,4,1]
[1,5,10,10,5,1]
[1,6,15,20,15,6,1]
[1,7,21,35,35,21,7,1]
[1,8,28,56,70,56,28,8,1]
F
To clear up what's happening in the recursive call to loop, the (+) operator represents vector addition, not list concatenation:
gimli> xs <- [1]
1
gimli> xs <- [0, xs] + [xs, 0]
[1,1]
gimli> xs <- [0, xs] + [xs, 0]
[1,2,1]