15 Lattice Paths

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?

#include <iostream>
#include <limits>
#include <vector>

using namespace std;

void pause() { cin.ignore(numeric_limits<streamsize>::max(), '\n'); }

#define GRID 20

int main()
{
    long long int combinations = 1;
    for (int i = 0; i < GRID; i++)
    {
        combinations *= 2 * GRID - i;
        combinations /= i + 1; 
    }

    cout << combinations;
    pause();
}

Solution: 137846528820

Last updated