Erik V. [email protected] writes:
row = [1, 4, 6, 4, 1]
p ([0]+row).zip(row<<0).map{|a,b|a+b} ===> [1, 5, 10, 10, 5, 1]
p row.zip([0]+row).map{|a,b|a+b}+[1] ===> [1, 5, 10, 10, 5, 1, 1]Different results…
row = [1, 4, 6, 4, 1]
p ([0]+row).zip(row<<0).map{|a,b|a+b} ===> [1, 5, 10, 10, 5, 1]
row = [1, 4, 6, 4, 1]
p row.zip([0]+row).map{|a,b|a+b}+[1] ===> [1, 5, 10, 10, 5, 1]
Running your code first mangles the value of “row”. It’s not fair if
you don’t give the same value for “row” to my code
Incidentally:
row = [1, 4, 6, 4, 1]
p ([0]+row).zip(row<<0).map{|a,b|a+b} ===> [1, 5, 10, 10, 5, 1]
p ([0]+row).zip(row<<0).map{|a,b|a+b} ===> [1, 5, 10, 10, 5, 1, 0]
t=(0…n).map{|i|r=1;[1]+(1…i).map{|a|r=r*(i+1-a)/a}}
Add one extra dot (0…n instead of 0…n) and you win!
Yeah; I’m not surprised I had an off-by-one error - what the quiz
calls the first row I’d call the “zeroth” row.