Skip to content

Instantly share code, notes, and snippets.

@nattybear
Created January 12, 2017 02:02
Show Gist options
  • Save nattybear/657fcf3a2221c3802856f673ecdced25 to your computer and use it in GitHub Desktop.
Save nattybear/657fcf3a2221c3802856f673ecdced25 to your computer and use it in GitHub Desktop.
# python 2.7.9
# get factorial
def fact(n):
ret = 1
for i in range(1, n+1):
ret = ret * i
return ret
# get combination
def comb(n, k):
return fact(n) / fact(k) / fact(n-k)
# print result using iteration
for i in range(6):
for j in range(i+1):
print '%dC%d = %d' % (i, j, comb(i, j)),
print ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment