Repository: keon/algorithms
Pull request #351 (2018-06-11 16:33:40)

simulation code for radix_sort
For issue #315, I made a change for simulating radix_sort
Thanks

(Put an `X` inside the `[ ]` to denote check mark `[X]`.)

- [X] **if done some changes :**
  - [X] wrote short description in the PR explaining what the changes do ?
  - [X] Fixes #[issue number] if related to any issue


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

* **4** of **7**   **(57.14%)**  changed or added relevant lines in **1** file are covered.
* **1** unchanged line in **1** file lost coverage.
* Overall coverage decreased (**-0.04%**) to **70.558%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [algorithms/sort/radix_sort.py](https://coveralls.io/builds/17428952/source?filename=algorithms%2Fsort%2Fradix_sort.py#L11) | 4 | 7 | 57.14%
<!-- | **Total:** | **4** | **7** | **57.14%** | -->

|  Files with Coverage Reduction | New Missed Lines | % |
| :-----|--------------|--: |
| [algorithms/sort/top_sort.py](https://coveralls.io/builds/17428952/source?filename=algorithms%2Fsort%2Ftop_sort.py#L55) | 1 | 92.31% |
<!-- | **Total:** | **1** |  | -->

|  Totals | [![Coverage Status](https://coveralls.io/builds/17428952/badge)](https://coveralls.io/builds/17428952) |
| :-- | --: |
| Change from base [Build 621](https://coveralls.io/builds/17415977): |  -0.04% |
| Covered Lines: | 3554 |
| Relevant Lines: | 5037 |

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


Patch:
diff --git a/MANIFEST.in b/MANIFEST.in
index daf8a52..50af9b9 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,3 @@
 include README.md
 include LICENSE
 include algorithms/*
-include tests/*
diff --git a/README.md b/README.md
index d85ec44..c03bece 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,7 @@ If you want to uninstall algorithms, it is as simple as:
     - [flatten](algorithms/arrays/flatten.py)
     - [garage](algorithms/arrays/garage.py)
     - [josephus_problem](algorithms/arrays/josephus.py)
+    - [limit](algorithms/arrays/limit.py)
     - [longest_non_repeat](algorithms/arrays/longest_non_repeat.py/)
     - [max_ones_index](algorithms/arrays/max_ones_index.py)
     - [merge_intervals](algorithms/arrays/merge_intervals.py)
diff --git a/README_CN.md b/README_CN.md
index b675f6f..42f7b36 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -78,6 +78,7 @@ pip3 uninstall -y algorithms
     - [garage：停车场](algorithms/arrays/garage.py)
     - [josephus_problem: 约瑟夫问题](algorithms/arrays/josephus.py)
     - [max_ones_index](algorithms/arrays/max_ones_index.py)
+    - [limit](algorithms/arrays/limit.py)
     - [longest_non_repeat：最长不重复子串](algorithms/arrays/longest_non_repeat.py/) 
     - [merge_intervals：合并重叠间隔](algorithms/arrays/merge_intervals.py)
     - [missing_ranges：遗失的范围](algorithms/arrays/missing_ranges.py)
diff --git a/README_GE.md b/README_GE.md
index e21dca3..f9f4757 100644
--- a/README_GE.md
+++ b/README_GE.md
@@ -67,6 +67,7 @@ Um das Projekt zu deinstallieren tippen Sie folgendes:
     - [flatten](algorithms/arrays/flatten.py)
     - [garage](algorithms/arrays/garage.py)
     - [josephus_problem](algorithms/arrays/josephus.py)
+    - [limit](algorithms/arrays/limit.py)
     - [longest_non_repeat](algorithms/arrays/longest_non_repeat.py/)
     - [max_ones_index](algorithms/arrays/max_ones_index.py)
     - [merge_intervals](algorithms/arrays/merge_intervals.py)
diff --git a/README_JP.md b/README_JP.md
index 636d79f..571c70f 100644
--- a/README_JP.md
+++ b/README_JP.md
@@ -61,6 +61,7 @@ if __name__ == "__main__":
     - [flatten](algorithms/arrays/flatten.py)
     - [garage](algorithms/arrays/garage.py)
     - [josephus_problem](algorithms/arrays/josephus.py)
+    - [limit](algorithms/arrays/limit.py)
     - [longest_non_repeat](algorithms/arrays/longest_non_repeat.py/)
     - [max_ones_index](algorithms/arrays/max_ones_index.py)
     - [merge_intervals](algorithms/arrays/merge_intervals.py)
diff --git a/README_KR.md b/README_KR.md
index b38cdd4..773babd 100644
--- a/README_KR.md
+++ b/README_KR.md
@@ -60,6 +60,7 @@ if __name__ == "__main__":
     - [flatten](algorithms/arrays/flatten.py)
     - [garage](algorithms/arrays/garage.py)
     - [josephus_problem](algorithms/arrays/josephus.py)
+    - [limit](algorithms/arrays/limit.py)
     - [longest_non_repeat](algorithms/arrays/longest_non_repeat.py/)
     - [max_ones_index](algorithms/arrays/max_ones_index.py)
     - [merge_intervals](algorithms/arrays/merge_intervals.py)
diff --git a/algorithms/arrays/__init__.py b/algorithms/arrays/__init__.py
index 7e57f63..c0d8b8f 100644
--- a/algorithms/arrays/__init__.py
+++ b/algorithms/arrays/__init__.py
@@ -14,3 +14,4 @@ from .three_sum import *
 from .trimmean import *
 from .top_1 import *
 from .two_sum import *
+from .limit import *
diff --git a/algorithms/arrays/limit.py b/algorithms/arrays/limit.py
new file mode 100644
index 0000000..adcc577
--- /dev/null
+++ b/algorithms/arrays/limit.py
@@ -0,0 +1,30 @@
+"""
+Sometimes you need to limit array result to use. Such as you only need the value over
+10 or, you need value under than 100. By use this algorithms, you can limit your array
+to specific value
+
+If array, Min, Max value was given, it returns array that contains values of given array
+which was larger than Min, and lower than Max. You need to give 'unlimit' to use only Min
+or Max.
+
+ex) limit([1,2,3,4,5], None, 3) = [1,2,3]
+
+Complexity = O(n)
+"""
+
+def limit(arr, min_lim = None, max_lim = None):
+    result = []
+    if min_lim == None:
+        for i in arr:
+            if i<= max_lim:
+                result.append(i)
+    elif max_lim == None:
+        for i in arr:
+            if i >= min_lim:
+                result.append(i)
+    else:
+        for i in arr:
+            if i >= min_lim and i <= max_lim:
+                result.append(i)
+
+    return result
diff --git a/algorithms/sort/radix_sort.py b/algorithms/sort/radix_sort.py
index fee0f2f..dd4113d 100644
--- a/algorithms/sort/radix_sort.py
+++ b/algorithms/sort/radix_sort.py
@@ -2,10 +2,14 @@
 radix sort
 complexity: O(nk) . n is the size of input list and k is the digit length of the number
 """
-def radix_sort(arr):
+def radix_sort(arr, simulation=False):
     is_done = False
     position = 1
 
+    iteration = 0
+    if simulation:
+        print("iteration",iteration,":",*arr)
+
     while not is_done:
         queue_list = [list() for _ in range(10)]
         is_done = True
@@ -22,5 +26,9 @@ def radix_sort(arr):
                 arr[index] = num
                 index += 1
 
+        if simulation:
+            iteration = iteration + 1
+            print("iteration",iteration,":",*arr)
+
         position *= 10
     return arr


Test patch:
diff --git a/tests/test_array.py b/tests/test_array.py
index e3f6f6d..6002adb 100644
--- a/tests/test_array.py
+++ b/tests/test_array.py
@@ -14,7 +14,8 @@ from algorithms.arrays import (
     two_sum,
     max_ones_index,
     trimmean,
-    top_1
+    top_1,
+    limit
 )
 
 import unittest
@@ -322,6 +323,14 @@ class TestTop1(unittest.TestCase):
         self.assertListEqual(top_1([1 , 1, 2, 2, 3]), [1, 2])
         self.assertListEqual(top_1([1, 2, 3, 324, 234, 23, 23, 1, 23, 23]), [23])
 
+class TestLimit(unittest.TestCase):
+    
+    def test_limit(self):
+        self.assertListEqual(limit([1, 2, 3, 4, 5], 2, 4), [2, 3, 4])
+        self.assertListEqual(limit([1, 2, 3, 4, 5], 2), [2, 3, 4, 5])
+        self.assertListEqual(limit([1, 2, 3, 4, 5], None, 4), [1, 2, 3, 4])
+
+        
 
 
 if __name__ == '__main__':