Skip to content

Instantly share code, notes, and snippets.

@heftig
Created February 9, 2012 13:30
Show Gist options
  • Save heftig/1779938 to your computer and use it in GitHub Desktop.
Save heftig/1779938 to your computer and use it in GitHub Desktop.
triangle = Enumerator.new do |e|
arr = [1]
loop do
e << arr.join(" ")
arr = [1, *arr.each_cons(2).map { |x| x.inject(:+) }, 1]
end
end
while (depth = gets.to_i) > 0
lines = triangle.take(depth)
just = lines.last.length
puts lines.map { |l| l.center(just) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment