Files
euler-project/problems/015_problem/015_problem.py
2020-08-02 22:00:06 -04:00

36 lines
1006 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Problem 15:
#
# [Euler Project #15](https://projecteuler.net/problem=15)
#
# 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?
#
# ---
# Let's try to map the example cases, by assigning a binary value to RIGHT and DOWN moves.
# 0 = R
# 1 = D
#
# 0 0 1 1
# 0 1 0 1
# 0 1 1 0
# 1 0 0 1
# 1 0 1 0
# 1 1 0 0
# A couple things that shake out of this,
# 1. The total length of a sequence of moves is the equal to Length + Width of the grid.
# 2. Each unique sequence of moves has a twin which is a mirror across the diagonal.
# 3. Each valid sequence has an equal number of RIGHT and DOWN moves.
# I'm sure there is some combinatorial mathematics that describes how to do this analytically,
# but I'd rather practice programming a loop, than researching an elegant solution.
length=20
width=20
move_sequence_length=length+width
count=0