Created
March 21, 2017 15:43
-
-
Save mainroach/5bd6e562ab2908f11ecb6d57c9ad1708 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
def pascalIndexInRowFast(row,index): | |
lastVal=1 | |
halfRow = (row>>1) | |
#early out, is index < half? if so, compute to that instead | |
if index > halfRow: | |
index = halfRow - (halfRow - index) | |
for i in range(0, index): | |
lastVal = lastVal * (row - i) / (i + 1) | |
return lastVal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment