Skip to content

Instantly share code, notes, and snippets.

@mainroach
Created March 21, 2017 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mainroach/5bd6e562ab2908f11ecb6d57c9ad1708 to your computer and use it in GitHub Desktop.
Save mainroach/5bd6e562ab2908f11ecb6d57c9ad1708 to your computer and use it in GitHub Desktop.
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