Created
November 16, 2018 01:53
-
-
Save reddikih/384208b420ce17150bf7cbe1806d8c44 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
#!/usr/bin/env python3 | |
# coding:utf-8 | |
import sys | |
def combi(n, r): | |
assert r >= 0, 'r must be larger than zero' | |
if n < r: | |
return 0 | |
if r == 0: | |
return 1 | |
if r == 1: | |
return n | |
return combi(n-1, r) + combi(n-1, r-1) | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print('Usage: {} n r'.format(sys.argv[0])) | |
sys.exit(1) | |
try: | |
n = int(sys.argv[1]) | |
r = int(sys.argv[2]) | |
except ValueError: | |
print('n or r must be a integer') | |
sys.exit(1) | |
assert n >= r, 'n must be larger or equals to r' | |
print(combi(n, r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment