Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calc_nums(row)
- return [1] if row == 1
- temp = [1] # the current row
- rev = calc_nums(row - 1)
- 1.upto(row-2) do |i|
- temp[i] = rev[i - 1] + rev[i]
- end
- temp << 1
- temp
- end
- puts "What row do you want to see?"
- rowNum = gets.chomp.to_i # chomp off newline and convert to int
- puts "Here is row #{rowNum}:" # confirm
- nums = calc_nums rowNum # convert to integer then pass
- puts nums.join(" ")
Add Comment
Please, Sign In to add comment