Project Euler : Problem 015

Project Euler problems in Oforth . Feel free to post your own code.

Project Euler : Problem 015

Postby Franck » 01 Aug 2015 17:13

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 / ]
}
Franck
 
Posts: 145
Joined: 29 Oct 2014 19:01

Return to Project Euler in Oforth

Who is online

Users browsing this forum: No registered users and 1 guest