Created combination.py in maths (#304) · Jacke/python_algorithms@bb9d6c1 · GitHub
Skip to content

Commit bb9d6c1

Browse files
geon0325goswami-rahul
authored andcommitted
Created combination.py in maths (keon#304)
* Create combination.py * Update __init__.py * Update test_maths.py * Update README.md * Update README_CN.md * Update README_GE.md * Update README_JP.md * Update README_KR.md
1 parent e414353 commit bb9d6c1

8 files changed

Lines changed: 26 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ pip3 uninstall -y algorithms
164164
- [valid_sudoku:有效数独](algorithms/map/valid_sudoku.py)
165165
- [math:数学问题](algorithms/maths)
166166
- [extended_gcd:扩展欧几里得算法](algorithms/maths/extended_gcd.py)
167+
- [combination](algorithms/maths/combination.py)
167168
- [gcd/lcm:最大公约数和最小公倍数](algorithms/maths/gcd.py)
168169
- [prime_test:主要测试](algorithms/maths/prime_test.py)
169170
- [primes_sieve_of_eratosthenes:埃拉托色尼的质数筛](algorithms/maths/primes_sieve_of_eratosthenes.py)

README_GE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Um das Projekt zu deinstallieren tippen Sie folgendes:
179179
- [valid_sudoku](algorithms/map/valid_sudoku.py)
180180
- [maths](algorithms/maths)
181181
- [base_conversion](algorithms/maths/base_conversion.py)
182+
- [combination](algorithms/maths/combination.py)
182183
- [extended_gcd](algorithms/maths/extended_gcd.py)
183184
- [gcd/lcm](algorithms/maths/gcd.py)
184185
- [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)

README_JP.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[English](README.md) | [简体中文](README_CN.md) | [Deutsch](README_GE.md) | 日本語 | [한국어](README_KR.md)
22

3-
pythonのデータ構造とアルゴリズム
3+
Pythonのデータ構造とアルゴリズム
44
=========================================
55

66
Python 3で開発された簡単で明確なデータ構造とアルゴリズムの例を紹介します。
@@ -169,6 +169,7 @@ if __name__ == "__main__":
169169
- [valid_sudoku](algorithms/map/valid_sudoku.py)
170170
- [maths : 数学](algorithms/maths)
171171
- [base_conversion](algorithms/maths/base_conversion.py)
172+
- [combination](algorithms/maths/combination.py)
172173
- [extended_gcd](algorithms/maths/extended_gcd.py)
173174
- [gcd/lcm](algorithms/maths/gcd.py)
174175
- [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)

README_KR.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ if __name__ == "__main__":
165165
- [valid_sudoku](algorithms/map/valid_sudoku.py)
166166
- [maths : 수학 계산](algorithms/maths)
167167
- [base_conversion](algorithms/maths/base_conversion.py)
168+
- [combination](algorithms/maths/combination.py)
168169
- [extended_gcd](algorithms/maths/extended_gcd.py)
169170
- [gcd/lcm](algorithms/maths/gcd.py)
170171
- [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)

algorithms/maths/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
from .pythagoras import *
1010
from .rabin_miller import *
1111
from .rsa import *
12+
from .combination import *

algorithms/maths/combination.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def combination(n, r):
2+
# This function calculates nCr
3+
if n == r or r == 0:
4+
return 1
5+
else:
6+
return combination(n-1, r-1) + combination(n-1, r)

tests/test_maths.py

Lines changed: 13 additions & 1 deletion

0 commit comments

Comments
 (0)