Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created May 29, 2011 07:48
Show Gist options
  • Save johana-star/997548 to your computer and use it in GitHub Desktop.
Save johana-star/997548 to your computer and use it in GitHub Desktop.
Euler Project Problem #015
# Solution to Project Euler's fifteenth problem
# http://projecteuler.net/index.php?section=problems&id=15
# How many routes are there through a 2020 grid?
def generate_Pascals_triangle(depth)
triangle = [[1], [1,1]]
(2..depth).each do |d|
# generate row #
triangle[d] = []
next_row = triangle[d-1]
next_row.push 0; next_row.unshift 0
(1..(next_row.length-1)).each do |o|
triangle[d].push (next_row[o-1] + next_row[o])
end
end
return triangle
end
number = 40
triangle = generate_Pascals_triangle(number)
p triangle[40][20]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment