Skip to content

Commit e3c7942

Browse files
kgashokvolf52
authored andcommitted
added function for Python3 (#1)
1 parent 9fe4a37 commit e3c7942

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • recipes/Python/Combination without using factorials

recipes/Python/Combination without using factorials/combo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ def ncr(n, r):
77
num = reduce(op.mul, xrange(n, n-1, -1))
88
denom = reduce(op.mul, xrange(1, r+1))
99
return num // denom
10+
11+
def ncr3(n, r):
12+
r = min(r, n-r)
13+
if x == 0: return 1
14+
num = reduce(op.mul, range(n, n-1, -1))
15+
denom = reduce(op.mul, range(1, r+1))
16+
return num // denom

0 commit comments

Comments
 (0)