From d3dba4b9cd353b852b230e8ac2d8cd5790f5c625 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 12 Apr 2010 15:53:19 +0000 Subject: [PATCH] Problem 015 git-svn-id: file:///srv/svn/euler@40 e5f4c3ec-3c0c-11df-b522-21efaa4426b5 --- e015.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 e015.py diff --git a/e015.py b/e015.py new file mode 100644 index 0000000..d20a635 --- /dev/null +++ b/e015.py @@ -0,0 +1,33 @@ +""" +Calculate the number of possible paths from the top left corner to the bottom +right, without backtracking (no moving up or left) + +i.e., for a 2x2 grid: + _ _ + |_|_| + |_|_| + +Paths to each point, forming a Pascal Triangle: + 1 1 1 + 1 2 3 + 1 3 6 + + 001 001 001 001 + 001 002 003 004 + 001 003 006 010 + 001 004 010 020 +""" +def pascal(row, col): + val = 1 + r = row + 1 + for c in range(1, col + 1): + val = (val * ((r - c) / float(c))) + return int(val) +def paths(size): + return pascal(size + (size - 2), size - 1) + +if __name__ == '__main__': + # 20x20 grid + # Points = cubes + 1 + size = 21 + print 'Paths: ', paths(size)