Repository: keon/algorithms
Pull request #304 (2018-06-04 03:04:44)

Created combination.py in maths
I created combination.py that calculates nCr. Also added test cases as well.

coveralls: ## Pull Request Test Coverage Report for [Build 346](https://coveralls.io/builds/17300016)

* **8** of **8**   **(100.0%)**  changed or added relevant lines in **2** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.02%**) to **91.561%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/17300016/badge)](https://coveralls.io/builds/17300016) |
| :-- | --: |
| Change from base [Build 340](https://coveralls.io/builds/17295523): |  0.02% |
| Covered Lines: | 2756 |
| Relevant Lines: | 3010 |

---
##### 💛  - [Coveralls](https://coveralls.io)

lg970325: README work complete :)

Patch:
diff --git a/README.md b/README.md
index 231facd..3814933 100644
--- a/README.md
+++ b/README.md
@@ -172,6 +172,7 @@ If you want to uninstall algorithms, it is as simple as:
     - [valid_sudoku](algorithms/map/valid_sudoku.py)
 - [maths](algorithms/maths)
     - [base_conversion](algorithms/maths/base_conversion.py)
+    - [combination](algorithms/maths/combination.py)
     - [extended_gcd](algorithms/maths/extended_gcd.py)
     - [gcd/lcm](algorithms/maths/gcd.py)
     - [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)
diff --git a/README_CN.md b/README_CN.md
index 130898a..5427972 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -164,6 +164,7 @@ pip3 uninstall -y algorithms
     - [valid_sudoku：有效数独](algorithms/map/valid_sudoku.py)
 - [math：数学问题](algorithms/maths)
     - [extended_gcd：扩展欧几里得算法](algorithms/maths/extended_gcd.py)
+    - [combination](algorithms/maths/combination.py)
     - [gcd/lcm：最大公约数和最小公倍数](algorithms/maths/gcd.py)
     - [prime_test：主要测试](algorithms/maths/prime_test.py)
     - [primes_sieve_of_eratosthenes：埃拉托色尼的质数筛](algorithms/maths/primes_sieve_of_eratosthenes.py)
diff --git a/README_GE.md b/README_GE.md
index 5380e65..bd9c469 100644
--- a/README_GE.md
+++ b/README_GE.md
@@ -179,6 +179,7 @@ Um das Projekt zu deinstallieren tippen Sie folgendes:
     - [valid_sudoku](algorithms/map/valid_sudoku.py)
 - [maths](algorithms/maths)
     - [base_conversion](algorithms/maths/base_conversion.py)
+    - [combination](algorithms/maths/combination.py)
     - [extended_gcd](algorithms/maths/extended_gcd.py)
     - [gcd/lcm](algorithms/maths/gcd.py)
     - [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)
diff --git a/README_JP.md b/README_JP.md
index f50d6df..393e0bb 100644
--- a/README_JP.md
+++ b/README_JP.md
@@ -1,6 +1,6 @@
 [English](README.md) | [简体中文](README_CN.md) | [Deutsch](README_GE.md) | 日本語 | [한국어](README_KR.md)
 
-pythonのデータ構造とアルゴリズム
+Pythonのデータ構造とアルゴリズム
 =========================================
 
 Python 3で開発された簡単で明確なデータ構造とアルゴリズムの例を紹介します。
@@ -169,6 +169,7 @@ if __name__ == "__main__":
     - [valid_sudoku](algorithms/map/valid_sudoku.py)
 - [maths : 数学](algorithms/maths)
     - [base_conversion](algorithms/maths/base_conversion.py)
+    - [combination](algorithms/maths/combination.py)
     - [extended_gcd](algorithms/maths/extended_gcd.py)
     - [gcd/lcm](algorithms/maths/gcd.py)
     - [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)
diff --git a/README_KR.md b/README_KR.md
index a2b408a..dd1bfb8 100644
--- a/README_KR.md
+++ b/README_KR.md
@@ -165,6 +165,7 @@ if __name__ == "__main__":
     - [valid_sudoku](algorithms/map/valid_sudoku.py)
 - [maths : 수학 계산](algorithms/maths)
     - [base_conversion](algorithms/maths/base_conversion.py)
+    - [combination](algorithms/maths/combination.py)
     - [extended_gcd](algorithms/maths/extended_gcd.py)
     - [gcd/lcm](algorithms/maths/gcd.py)
     - [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)
diff --git a/algorithms/maths/__init__.py b/algorithms/maths/__init__.py
index 6716384..d791ad8 100644
--- a/algorithms/maths/__init__.py
+++ b/algorithms/maths/__init__.py
@@ -9,3 +9,4 @@ from .primes_sieve_of_eratosthenes import *
 from .pythagoras import *
 from .rabin_miller import *
 from .rsa import *
+from .combination import *
diff --git a/algorithms/maths/combination.py b/algorithms/maths/combination.py
new file mode 100644
index 0000000..ea9e4b3
--- /dev/null
+++ b/algorithms/maths/combination.py
@@ -0,0 +1,6 @@
+def combination(n, r):
+    # This function calculates nCr
+    if n == r or r == 0:
+        return 1
+    else:
+        return combination(n-1, r-1) + combination(n-1, r)


Test patch:
diff --git a/tests/test_maths.py b/tests/test_maths.py
index afafd2e..fbf0772 100644
--- a/tests/test_maths.py
+++ b/tests/test_maths.py
@@ -9,7 +9,8 @@ from algorithms.maths import (
     primes,
     pythagoras,
     is_prime,
-    encrypt, decrypt, generate_key
+    encrypt, decrypt, generate_key,
+    combination
 )
 
 import unittest
@@ -202,6 +203,17 @@ class TestRSA(unittest.TestCase):
     #         dec = decrypt(en, d, n)
     #         self.assertEqual(data,dec)
 
+class TestCombination(unittest.TestCase):
+    """[summary]
+    Test for the file rsa.py
+
+    Arguments:
+        unittest {[type]} -- [description]
+    """
 
+    def test_combination(self):
+        self.assertEqual(10, combination(5, 2))
+        self.assertEqual(252, combination(10, 5))
+        
 if __name__ == "__main__":
     unittest.main()