Created
March 21, 2017 15:46
-
-
Save mainroach/6de3d6f61249c3396fa1cfe1c440cd1f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from fractions import Fraction | |
def pascDiagFast(row,length): | |
#compute the fractions of this diag | |
fracs=[1]*(length) | |
for i in range(length-1): | |
num = i+1 | |
denom = row+1+i | |
fracs[i] = Fraction(num,denom) | |
#now let's compute the values | |
vals=[0]*length | |
#first figure out the leftmost tail of this diag | |
lowRow = row + (length-1) | |
lowRowCol = row | |
tail = pascalIndexInRowFast(lowRow,lowRowCol) | |
vals[-1] = tail | |
#walk backwards! | |
for i in reversed(range(length-1)): | |
vals[i] = int(fracs[i]*vals[i+1]) | |
return vals |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment