Created
June 9, 2019 13:32
-
-
Save xbony2/f3cdf0700334b1762bbd4a6a79efd189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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