Solution to problem 15
This commit is contained in:
parent
735795e9af
commit
48dae803d8
31
src/Python/Problem015.py
Normal file
31
src/Python/Problem015.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Created on 7 Jan 2018
|
||||||
|
|
||||||
|
@author: David Doblas Jiménez
|
||||||
|
@email: daviddoji@pm.me
|
||||||
|
|
||||||
|
Solution for problem 15 of Project Euler
|
||||||
|
https://projecteuler.net/problem=15
|
||||||
|
"""
|
||||||
|
|
||||||
|
from math import factorial
|
||||||
|
from utils import timeit
|
||||||
|
|
||||||
|
|
||||||
|
@timeit("Problem 15")
|
||||||
|
def compute():
|
||||||
|
"""
|
||||||
|
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?
|
||||||
|
"""
|
||||||
|
n = 20
|
||||||
|
return int(factorial(2*n) / (factorial(n) * factorial(2*n - n)))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
print(f"Result for Problem 15: {compute()}")
|
Loading…
x
Reference in New Issue
Block a user