Skip to content

Instantly share code, notes, and snippets.

@tamalw
Created February 19, 2013 03:43
Show Gist options
  • Save tamalw/4982902 to your computer and use it in GitHub Desktop.
Save tamalw/4982902 to your computer and use it in GitHub Desktop.
Falls apart when the numbers get long
rows = 8
t = []
rows.times do |i|
t[i] = []
(i+1).times do |j|
if j == 0 || j == i
t[i] << 1
else
t[i] << t[i-1][j-1] + t[i-1][j]
end
end
end
pt = t.map { |r| r.join(' ') }
pt.each do |r|
puts r.center(pt.last.length)
end
# >> 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment