Euler Problem 15

Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.

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

This is your standard Pascal’s triangle problem. Wiki has tons of great stuff on it. No doubt this one will come back in a later problem.

public class Euler15
{
    public static void main(String[] args)
    {
        System.out.print(“Problem 15:\n”);
        Euler15 e = new Euler15();
        System.out.print(“Answer = ” + e.Problem()+ “\n”);
    }
    public String Problem ()
    {
        int rows = 20;
        int cols = 20;
        return String.valueOf(P(2*rows, cols));
    }
    public static long P(int row, int col)
    {
        long current = 1;
        for (int i = 1; i <= col; i++ )
        {
            current = (current * (row + 1 – i)) / i;
        }
        return current;
    }
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s