SHARE
TWEET

Untitled

a guest Jun 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Created by Eric Schneider
  2. def makeTriangle(rows)
  3.   rows.times do |row| # Note this starts at 0
  4.     print " " * (rows - row - 1)
  5.  
  6.     makeRow(row + 1).each do |n|
  7.       print "#{n} "
  8.     end
  9.  
  10.     puts
  11.   end
  12. end
  13.  
  14. def makeRow(row)
  15.   if row == 1
  16.     [1]
  17.   else
  18.     oldRow = makeRow(row - 1)
  19.  
  20.     newRow = [1]
  21.  
  22.     (oldRow.length - 1).times do |i|
  23.       newRow.push(oldRow[i] + oldRow[i + 1])
  24.     end
  25.  
  26.     newRow.push(1)
  27.   end
  28. end
  29.  
  30. makeTriangle(10)
  31.  
  32. "Program Complete"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top