C# Implementation of Problem 15

View source code here on GitHub!

Includes

Problem Solution

class p0015
: Euler.IEuler
object Answer ()
 1/*
 2Project Euler Problem 15
 3
 4Turns out this is easy, if you think sideways a bit
 5
 6You can only go down or right. If we say right=1, then you can only have 20 1s, since otherwise you go off the grid.
 7You also can't have fewer than 20 1s, since then you go off the grid the other way. This means you can look at it as a
 8bit string, and the number of 40-bit strings with 20 1s is 40c20.
 9
10Problem:
11
12Starting 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
13routes to the bottom right corner.
14
15How many such routes are there through a 20×20 grid?
16*/
17using System;
18
19namespace Euler
20{
21    public class p0015 : IEuler
22    {
23        public object Answer()
24        {
25            return (long)Mathematics.NChooseR(40, 20);
26        }
27    }
28}

Tags: combinatorics