Skip to content

Instantly share code, notes, and snippets.

@chiragmongia
Created March 19, 2013 05:24
Show Gist options
  • Select an option

  • Save chiragmongia/5193888 to your computer and use it in GitHub Desktop.

Select an option

Save chiragmongia/5193888 to your computer and use it in GitHub Desktop.
def fact(n)
if n == 0
1
else
n * fact(n-1)
end
end
def pascal_row(n)
for k in 0..n
yield(fact(n)/(fact(k)*fact(n-k)))
end
end
def pascal(no_of_row)
for k in 0..no_of_row
pascal_row(k) {|x| print "#{x}"}
print "\n"
end
end
print "Number of rows for Pascal's triangle: "
row = gets.to_i
pascal(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment