Last active
December 5, 2015 20:49
-
-
Save acomjean/91d6226863cf91cc96ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Author: Aram Comjean Dec/ 2015 | |
#http://stackoverflow.com/questions/6667201/how-to-define-two-dimensional-array-in-python | |
Lookup = [[0 for x in range(50)] for x in range(50)] | |
def alignment_paths (x,y): | |
#if we have a 1x1 matrix or are at the left or top edge, there is one path | |
if (x == 0 or y == 0): | |
return 1; | |
else: | |
# try looking up in lookup table | |
if Lookup[x][y] !=0: | |
return Lookup[x][y] | |
# the result is the # number of alignment paths from the 3 adjacent squares | |
val = alignment_paths(x-1, y-1) + alignment_paths(x-1, y) + alignment_paths (x, y-1) | |
#we have the result, store away value for future use | |
Lookup[x][y] = val | |
return val | |
#------------ | |
# Main | |
#------------ | |
#count paths.. Anything above 12 is really long | |
for i in range (1,50): | |
print i,"x",i,": ", | |
print alignment_paths(i,i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment