Page 1 of 1

Project Euler : Problem 015

PostPosted: 01 Aug 2015 17:13
by Franck
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

How many such routes are there through a 20×20 grid?

Code: Select all
// Here, we are looking for n paths from 2n possibilities, so C(2n, n)
// So : (2n)*(2n-1)*... *(n+1) / ( 1*2*... n)
: pe015(n)        // ( n -- n ) : Returns number of paths for a nxn grid
{
| i |
   1 n loop: i [ 2 n * i - 1 + * i / ]
}