Skip to content

Instantly share code, notes, and snippets.

@xbony2
Created June 9, 2019 13:32
Show Gist options
  • Save xbony2/f3cdf0700334b1762bbd4a6a79efd189 to your computer and use it in GitHub Desktop.
Save xbony2/f3cdf0700334b1762bbd4a6a79efd189 to your computer and use it in GitHub Desktop.
## Created by Eric Schneider
def makeTriangle(rows)
rows.times do |row| # Note this starts at 0
print " " * (rows - row - 1)
makeRow(row + 1).each do |n|
print "#{n} "
end
puts
end
end
def makeRow(row)
if row == 1
[1]
else
oldRow = makeRow(row - 1)
newRow = [1]
(oldRow.length - 1).times do |i|
newRow.push(oldRow[i] + oldRow[i + 1])
end
newRow.push(1)
end
end
makeTriangle(10)
"Program Complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment