Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 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"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement