Automatic commit performed through alias...
This commit is contained in:
35
problems/015_problem/015_problem.py
Normal file
35
problems/015_problem/015_problem.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user