Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. def calc_nums(row)
  2. return [1] if row == 1
  3.  
  4. temp = [1] # the current row
  5. rev = calc_nums(row - 1)
  6.  
  7. 1.upto(row-2) do |i|
  8. temp[i] = rev[i - 1] + rev[i]
  9. end
  10.  
  11. temp << 1
  12. temp
  13. end
  14.  
  15. puts "What row do you want to see?"
  16. rowNum = gets.chomp.to_i # chomp off newline and convert to int
  17. puts "Here is row #{rowNum}:" # confirm
  18. nums = calc_nums rowNum # convert to integer then pass
  19. puts nums.join(" ")
Add Comment
Please, Sign In to add comment