2015-02-20 00:35:01 -05:00
|
|
|
def pascal(n)
|
|
|
|
|
raise ArgumentError, "must be positive." if n < 1
|
|
|
|
|
yield ar = [1]
|
|
|
|
|
(n-1).times do
|
|
|
|
|
ar.unshift(0).push(0) # tack a zero on both ends
|
2018-06-22 20:57:24 +00:00
|
|
|
yield ar = ar.each_cons(2).map(&:sum)
|
2013-04-10 23:57:08 -07:00
|
|
|
end
|
|
|
|
|
end
|
2015-02-20 00:35:01 -05:00
|
|
|
|
|
|
|
|
pascal(8){|row| puts row.join(" ").center(20)}
|