From 8338e816700ca4ac78bd74eaed27cf63dea647bf Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Mon, 23 Sep 2019 07:58:22 +0200 Subject: [PATCH] Clarify comment --- C/p015.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/C/p015.c b/C/p015.c index ed7c530..9b62c38 100644 --- a/C/p015.c +++ b/C/p015.c @@ -1,3 +1,6 @@ +/* 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 #include #include @@ -11,6 +14,11 @@ int main(int argc, char **argv) clock_gettime(CLOCK_MONOTONIC, &start); + /* Using a combinatorial solution: in a 20x20 grid there will always be + * 20 movements to the right and 20 movements down, that can be represented + * as a string of Rs and Ds. The number of routes is the number of combinations. + * This is obtained calculating n!/(k!*(n-k)!), where n=40 and k=20. The GMP + * Library is used to calculate the factorials.*/ mpz_inits(count, tmp, NULL); mpz_fac_ui(count, 40); mpz_fac_ui(tmp, 20);