2 ms·
Something like this should do the trick, good old coffee. pascal_r = (n) -> lines = [[1]] for i in [1...n] last = lines[i-1] lines[i] =
by jbrooksuk 14y ago
Something like this should do the trick, good old coffee.
pascal_r = (n) ->
lines = [[1]]
for i in [1...n]
last = lines[i-1]
lines[i] = []
for j in [0..i]
lines[i][j] = (last[j-1] or 0) + (last[j] or 0)
lines[n-1]
console.log pascal_r(1)
console.log pascal_r(4)
Edit: Bloody HN formatting got the better of me again.