GeezerVison is showing github.com — improved prime numbers implementation (#1606) · jusing-es/Python@938dd0b
File treeExpand file treeCollapse file tree Open diff view settings data_structures/data_structures/heap
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: DIRECTORY.md +7-1Lines changed: 7 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 133 | 133 | * [Gaussian Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/gaussian_filter.py) | 134 | 134 | * [Median Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/median_filter.py) | 135 | 135 | * [Sobel Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/sobel_filter.py) | | 136 | + * [Index Calculation](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/index_calculation.py) | 136 | 137 | * Rotation | 137 | 138 | * [Rotation](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/rotation/rotation.py) | 138 | 139 | * [Test Digital Image Processing](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/test_digital_image_processing.py) | | 216 | 217 | ## Hashes | 217 | 218 | * [Chaos Machine](https://github.com/TheAlgorithms/Python/blob/master/hashes/chaos_machine.py) | 218 | 219 | * [Enigma Machine](https://github.com/TheAlgorithms/Python/blob/master/hashes/enigma_machine.py) | | 220 | + * [Hamming Code](https://github.com/TheAlgorithms/Python/blob/master/hashes/hamming_code.py) | 219 | 221 | * [Md5](https://github.com/TheAlgorithms/Python/blob/master/hashes/md5.py) | 220 | 222 | * [Sha1](https://github.com/TheAlgorithms/Python/blob/master/hashes/sha1.py) | 221 | 223 |
| | 234 | 236 | * [Linear Discriminant Analysis](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/linear_discriminant_analysis.py) | 235 | 237 | * [Linear Regression](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/linear_regression.py) | 236 | 238 | * [Logistic Regression](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/logistic_regression.py) | | 239 | + * [Multilayer Perceptron Classifier](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/multilayer_perceptron_classifier.py) | 237 | 240 | * [Polymonial Regression](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/polymonial_regression.py) | 238 | 241 | * [Scoring Functions](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/scoring_functions.py) | 239 | 242 | * [Sequential Minimum Optimization](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/sequential_minimum_optimization.py) | | 252 | 255 | * [Binomial Coefficient](https://github.com/TheAlgorithms/Python/blob/master/maths/binomial_coefficient.py) | 253 | 256 | * [Ceil](https://github.com/TheAlgorithms/Python/blob/master/maths/ceil.py) | 254 | 257 | * [Collatz Sequence](https://github.com/TheAlgorithms/Python/blob/master/maths/collatz_sequence.py) | | 258 | + * [Eulers Totient](https://github.com/TheAlgorithms/Python/blob/master/maths/eulers_totient.py) | 255 | 259 | * [Explicit Euler](https://github.com/TheAlgorithms/Python/blob/master/maths/explicit_euler.py) | 256 | 260 | * [Extended Euclidean Algorithm](https://github.com/TheAlgorithms/Python/blob/master/maths/extended_euclidean_algorithm.py) | 257 | 261 | * [Factorial Python](https://github.com/TheAlgorithms/Python/blob/master/maths/factorial_python.py) | | 286 | 290 | * [Prime Factors](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_factors.py) | 287 | 291 | * [Prime Numbers](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_numbers.py) | 288 | 292 | * [Prime Sieve Eratosthenes](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_sieve_eratosthenes.py) | | 293 | + * [Pythagoras](https://github.com/TheAlgorithms/Python/blob/master/maths/pythagoras.py) | 289 | 294 | * [Qr Decomposition](https://github.com/TheAlgorithms/Python/blob/master/maths/qr_decomposition.py) | 290 | 295 | * [Quadratic Equations Complex Numbers](https://github.com/TheAlgorithms/Python/blob/master/maths/quadratic_equations_complex_numbers.py) | 291 | 296 | * [Radix2 Fft](https://github.com/TheAlgorithms/Python/blob/master/maths/radix2_fft.py) | | 499 | 504 | * [I Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/i_sort.py) | 500 | 505 | * [Insertion Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py) | 501 | 506 | * [Merge Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py) | 502 | | - * [Merge Sort Fastest](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort_fastest.py) | 503 | 507 | * [Odd Even Transposition Parallel](https://github.com/TheAlgorithms/Python/blob/master/sorts/odd_even_transposition_parallel.py) | 504 | 508 | * [Odd Even Transposition Single Threaded](https://github.com/TheAlgorithms/Python/blob/master/sorts/odd_even_transposition_single_threaded.py) | 505 | 509 | * [Pancake Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/pancake_sort.py) | 506 | 510 | * [Pigeon Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/pigeon_sort.py) | | 511 | + * [Pigeonhole Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/pigeonhole_sort.py) | 507 | 512 | * [Quick Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/quick_sort.py) | 508 | 513 | * [Quick Sort 3 Partition](https://github.com/TheAlgorithms/Python/blob/master/sorts/quick_sort_3_partition.py) | 509 | 514 | * [Radix Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/radix_sort.py) | | 516 | 521 | * [Tim Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/tim_sort.py) | 517 | 522 | * [Topological Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/topological_sort.py) | 518 | 523 | * [Tree Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/tree_sort.py) | | 524 | + * [Unknown Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/unknown_sort.py) | 519 | 525 | * [Wiggle Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/wiggle_sort.py) | 520 | 526 |
| 521 | 527 | ## Strings | |
Collapse file Copy file name to clipboardExpand all lines: data_structures/data_structures/heap/heap_generic.py +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,7 +30,8 @@ def _swap(self, i, j): | 30 | 30 | """Performs changes required for swapping two elements in the heap""" | 31 | 31 | # First update the indexes of the items in index map. | 32 | 32 | self.pos_map[self.arr[i][0]], self.pos_map[self.arr[j][0]] = ( | 33 | | - self.pos_map[self.arr[j][0]], self.pos_map[self.arr[i][0]] | | 33 | + self.pos_map[self.arr[j][0]], | | 34 | + self.pos_map[self.arr[i][0]], | 34 | 35 | ) | 35 | 36 | # Then swap the items in the list. | 36 | 37 | self.arr[i], self.arr[j] = self.arr[j], self.arr[i] | |
Collapse file Copy file name to clipboardExpand all lines: digital_image_processing/index_calculation.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -176,10 +176,10 @@ def calculation( | 176 | 176 |
| 177 | 177 | def ARVI2(self): | 178 | 178 | """ | 179 | | - Atmospherically Resistant Vegetation Index 2 | 180 | | - https://www.indexdatabase.de/db/i-single.php?id=396 | 181 | | - :return: index | 182 | | - −0.18+1.17*(self.nir−self.red)/(self.nir+self.red) | | 179 | + Atmospherically Resistant Vegetation Index 2 | | 180 | + https://www.indexdatabase.de/db/i-single.php?id=396 | | 181 | + :return: index | | 182 | + −0.18+1.17*(self.nir−self.red)/(self.nir+self.red) | 183 | 183 | """ | 184 | 184 | return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red))) | 185 | 185 |
| |
Collapse file Copy file name to clipboard +25-19Lines changed: 25 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -from typing import List | | 1 | +from typing import Generator | 2 | 2 |
| 3 | 3 |
| 4 | | -def primes(max: int) -> List[int]: | | 4 | +def primes(max: int) -> Generator[int, None, None]: | 5 | 5 | """ | 6 | 6 | Return a list of all primes numbers up to max. | 7 | | - >>> primes(10) | 8 | | - [2, 3, 5, 7] | 9 | | - >>> primes(11) | 10 | | - [2, 3, 5, 7, 11] | 11 | | - >>> primes(25) | | 7 | + >>> list(primes(0)) | | 8 | + [] | | 9 | + >>> list(primes(-1)) | | 10 | + [] | | 11 | + >>> list(primes(-10)) | | 12 | + [] | | 13 | + >>> list(primes(25)) | 12 | 14 | [2, 3, 5, 7, 11, 13, 17, 19, 23] | 13 | | - >>> primes(1_000_000)[-1] | 14 | | - 999983 | | 15 | + >>> list(primes(11)) | | 16 | + [2, 3, 5, 7, 11] | | 17 | + >>> list(primes(33)) | | 18 | + [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] | | 19 | + >>> list(primes(10000))[-1] | | 20 | + 9973 | 15 | 21 | """ | 16 | | - max += 1 | 17 | | - numbers = [False] * max | 18 | | - ret = [] | 19 | | - for i in range(2, max): | 20 | | - if not numbers[i]: | 21 | | - for j in range(i, max, i): | 22 | | - numbers[j] = True | 23 | | - ret.append(i) | 24 | | - return ret | | 22 | + numbers: Generator = (i for i in range(1, (max + 1))) | | 23 | + for i in (n for n in numbers if n > 1): | | 24 | + for j in range(2, i): | | 25 | + if (i % j) == 0: | | 26 | + break | | 27 | + else: | | 28 | + yield i | 25 | 29 |
| 26 | 30 |
| 27 | 31 | if __name__ == "__main__": | 28 | | - print(primes(int(input("Calculate primes up to:\n>> ")))) | | 32 | + number = int(input("Calculate primes up to:\n>> ").strip()) | | 33 | + for ret in primes(number): | | 34 | + print(ret) |
Collapse file Copy file name to clipboardExpand all lines: sorts/pigeonhole_sort.py +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,8 +36,9 @@ def pigeonhole_sort(a): | 36 | 36 |
| 37 | 37 |
| 38 | 38 | def main(): | 39 | | - pigeonhole_sort([8, 3, 2, 7, 4, 6, 8]) | 40 | | - print("Sorted order is: ", " ", join(a)) | | 39 | + a = [8, 3, 2, 7, 4, 6, 8] | | 40 | + pigeonhole_sort(a) | | 41 | + print("Sorted order is:", " ".join(a)) | 41 | 42 |
| 42 | 43 |
| 43 | 44 | if __name__ == "__main__": | |
|