Skip to content

Commit a0d31fe

Browse files
authored
Merge branch 'master' into Fix-ftp-to-allow-doctests
2 parents 6f6ce9f + c964d74 commit a0d31fe

17 files changed

+465
-84
lines changed

.travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ script:
1616
--ignore=machine_learning/perceptron.py
1717
--ignore=machine_learning/random_forest_classification/random_forest_classification.py
1818
--ignore=machine_learning/random_forest_regression/random_forest_regression.py
19-
--ignore=maths/abs_min.py
20-
--ignore=maths/binary_exponentiation.py
21-
--ignore=maths/lucas_series.py
22-
--ignore=maths/sieve_of_eratosthenes.py
2319
--ignore=virtualenv # do not test our dependencies
2420
after_success:
2521
- python scripts/build_directory_md.py

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ We want your work to be readable by others; therefore, we encourage you to note
6969
"""
7070
This function sums two integers a and b
7171
Return: a + b
72-
"""
72+
"""
7373
return a + b
7474
```
7575

DIRECTORY.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [newton method](https://github.com/TheAlgorithms/Python/blob/master/arithmetic_analysis/newton_method.py)
66
* [newton raphson method](https://github.com/TheAlgorithms/Python/blob/master/arithmetic_analysis/newton_raphson_method.py)
77
## Backtracking
8+
* [all combinations](https://github.com/TheAlgorithms/Python/blob/master/backtracking/all_combinations.py)
89
* [all permutations](https://github.com/TheAlgorithms/Python/blob/master/backtracking/all_permutations.py)
910
* [all subsequences](https://github.com/TheAlgorithms/Python/blob/master/backtracking/all_subsequences.py)
1011
* [minimax](https://github.com/TheAlgorithms/Python/blob/master/backtracking/minimax.py)
@@ -27,7 +28,6 @@
2728
* [morse code implementation](https://github.com/TheAlgorithms/Python/blob/master/ciphers/morse_code_implementation.py)
2829
* [onepad cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/onepad_cipher.py)
2930
* [playfair cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/playfair_cipher.py)
30-
* [prehistoric men](https://github.com/TheAlgorithms/Python/blob/master/ciphers/prehistoric_men.txt)
3131
* [rabin miller](https://github.com/TheAlgorithms/Python/blob/master/ciphers/rabin_miller.py)
3232
* [rot13](https://github.com/TheAlgorithms/Python/blob/master/ciphers/rot13.py)
3333
* [rsa cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/rsa_cipher.py)
@@ -39,6 +39,7 @@
3939
* [vigenere cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/vigenere_cipher.py)
4040
* [xor cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/xor_cipher.py)
4141
## Compression
42+
* [burrows wheeler](https://github.com/TheAlgorithms/Python/blob/master/compression/burrows_wheeler.py)
4243
* [huffman](https://github.com/TheAlgorithms/Python/blob/master/compression/huffman.py)
4344
* [peak signal to noise ratio](https://github.com/TheAlgorithms/Python/blob/master/compression/peak_signal_to_noise_ratio.py)
4445
* Image Data
@@ -100,8 +101,10 @@
100101
## Dynamic Programming
101102
* [abbreviation](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/abbreviation.py)
102103
* [bitmask](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/bitmask.py)
104+
* [climbing stairs](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/climbing_stairs.py)
103105
* [coin change](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/coin_change.py)
104106
* [edit distance](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/edit_distance.py)
107+
* [factorial](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/factorial.py)
105108
* [fast fibonacci](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/fast_fibonacci.py)
106109
* [fibonacci](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/fibonacci.py)
107110
* [floyd warshall](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/floyd_warshall.py)
@@ -142,9 +145,9 @@
142145
* [eulerian path and circuit for undirected graph](https://github.com/TheAlgorithms/Python/blob/master/graphs/eulerian_path_and_circuit_for_undirected_graph.py)
143146
* [even tree](https://github.com/TheAlgorithms/Python/blob/master/graphs/even_tree.py)
144147
* [finding bridges](https://github.com/TheAlgorithms/Python/blob/master/graphs/finding_bridges.py)
145-
* [floyd warshall](https://github.com/TheAlgorithms/Python/blob/master/graphs/floyd_warshall.py)
146148
* [graph list](https://github.com/TheAlgorithms/Python/blob/master/graphs/graph_list.py)
147149
* [graph matrix](https://github.com/TheAlgorithms/Python/blob/master/graphs/graph_matrix.py)
150+
* [graphs floyd warshall](https://github.com/TheAlgorithms/Python/blob/master/graphs/graphs_floyd_warshall.py)
148151
* [kahns algorithm long](https://github.com/TheAlgorithms/Python/blob/master/graphs/kahns_algorithm_long.py)
149152
* [kahns algorithm topo](https://github.com/TheAlgorithms/Python/blob/master/graphs/kahns_algorithm_topo.py)
150153
* [minimum spanning tree kruskal](https://github.com/TheAlgorithms/Python/blob/master/graphs/minimum_spanning_tree_kruskal.py)
@@ -170,13 +173,17 @@
170173
* [knn sklearn](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/knn_sklearn.py)
171174
* [linear regression](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/linear_regression.py)
172175
* [logistic regression](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/logistic_regression.py)
176+
* [NaiveBayes](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/NaiveBayes.ipynb)
173177
* [perceptron](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/perceptron.py)
178+
* [reuters one vs rest classifier](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/reuters_one_vs_rest_classifier.ipynb)
174179
* [scoring functions](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/scoring_functions.py)
175180
* Random Forest Classification
176181
* [random forest classification](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/random_forest_classification/random_forest_classification.py)
182+
* [random forest classifier](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/random_forest_classification/random_forest_classifier.ipynb)
177183
* [Social Network Ads](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/random_forest_classification/Social_Network_Ads.csv)
178184
* Random Forest Regression
179185
* [Position Salaries](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/random_forest_regression/Position_Salaries.csv)
186+
* [random forest regression](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/random_forest_regression/random_forest_regression.ipynb)
180187
* [random forest regression](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/random_forest_regression/random_forest_regression.py)
181188
## Maths
182189
* [3n+1](https://github.com/TheAlgorithms/Python/blob/master/maths/3n+1.py)
@@ -197,7 +204,7 @@
197204
* [find max](https://github.com/TheAlgorithms/Python/blob/master/maths/find_max.py)
198205
* [find min](https://github.com/TheAlgorithms/Python/blob/master/maths/find_min.py)
199206
* [greater common divisor](https://github.com/TheAlgorithms/Python/blob/master/maths/greater_common_divisor.py)
200-
* [lucas series](https://github.com/TheAlgorithms/Python/blob/master/maths/lucas%20series.py)
207+
* [lucas series](https://github.com/TheAlgorithms/Python/blob/master/maths/lucas_series.py)
201208
* [modular exponential](https://github.com/TheAlgorithms/Python/blob/master/maths/modular_exponential.py)
202209
* [newton raphson](https://github.com/TheAlgorithms/Python/blob/master/maths/newton_raphson.py)
203210
* [prime check](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_check.py)
@@ -208,6 +215,8 @@
208215
* [volume](https://github.com/TheAlgorithms/Python/blob/master/maths/volume.py)
209216
## Matrix
210217
* [matrix operation](https://github.com/TheAlgorithms/Python/blob/master/matrix/matrix_operation.py)
218+
* [nth fibonacci using matrix exponentiation](https://github.com/TheAlgorithms/Python/blob/master/matrix/nth_fibonacci_using_matrix_exponentiation.py)
219+
* [rotate matrix](https://github.com/TheAlgorithms/Python/blob/master/matrix/rotate_matrix.py)
211220
* [searching in sorted matrix](https://github.com/TheAlgorithms/Python/blob/master/matrix/searching_in_sorted_matrix.py)
212221
* [spiral print](https://github.com/TheAlgorithms/Python/blob/master/matrix/spiral_print.py)
213222
## Networking Flow
@@ -216,16 +225,17 @@
216225
## Neural Network
217226
* [back propagation neural network](https://github.com/TheAlgorithms/Python/blob/master/neural_network/back_propagation_neural_network.py)
218227
* [convolution neural network](https://github.com/TheAlgorithms/Python/blob/master/neural_network/convolution_neural_network.py)
228+
* [fully connected neural network](https://github.com/TheAlgorithms/Python/blob/master/neural_network/fully_connected_neural_network.ipynb)
219229
* [perceptron](https://github.com/TheAlgorithms/Python/blob/master/neural_network/perceptron.py)
220230
## Other
221231
* [anagrams](https://github.com/TheAlgorithms/Python/blob/master/other/anagrams.py)
222232
* [binary exponentiation](https://github.com/TheAlgorithms/Python/blob/master/other/binary_exponentiation.py)
223233
* [binary exponentiation 2](https://github.com/TheAlgorithms/Python/blob/master/other/binary_exponentiation_2.py)
224234
* [detecting english programmatically](https://github.com/TheAlgorithms/Python/blob/master/other/detecting_english_programmatically.py)
225-
* [dictionary](https://github.com/TheAlgorithms/Python/blob/master/other/dictionary.txt)
226235
* [euclidean gcd](https://github.com/TheAlgorithms/Python/blob/master/other/euclidean_gcd.py)
227236
* [finding primes](https://github.com/TheAlgorithms/Python/blob/master/other/finding_primes.py)
228237
* [fischer yates shuffle](https://github.com/TheAlgorithms/Python/blob/master/other/fischer_yates_shuffle.py)
238+
* [Food wastage analysis from 1961-2013 (FAO)](https://github.com/TheAlgorithms/Python/blob/master/other/Food%20wastage%20analysis%20from%201961-2013%20(FAO).ipynb)
229239
* [frequency finder](https://github.com/TheAlgorithms/Python/blob/master/other/frequency_finder.py)
230240
* [game of life](https://github.com/TheAlgorithms/Python/blob/master/other/game_of_life.py)
231241
* [linear congruential generator](https://github.com/TheAlgorithms/Python/blob/master/other/linear_congruential_generator.py)
@@ -238,8 +248,6 @@
238248
* [two sum](https://github.com/TheAlgorithms/Python/blob/master/other/two_sum.py)
239249
* [word patterns](https://github.com/TheAlgorithms/Python/blob/master/other/word_patterns.py)
240250
* [words](https://github.com/TheAlgorithms/Python/blob/master/other/words)
241-
* Pycache
242-
* [password generator.cpython-37](https://github.com/TheAlgorithms/Python/blob/master/other/__pycache__/password_generator.cpython-37.pyc)
243251
## Project Euler
244252
* Problem 01
245253
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_01/sol1.py)
@@ -281,16 +289,13 @@
281289
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_10/sol1.py)
282290
* [sol2](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_10/sol2.py)
283291
* Problem 11
284-
* [grid](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_11/grid.txt)
285292
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_11/sol1.py)
286293
* [sol2](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_11/sol2.py)
287294
* Problem 12
288295
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_12/sol1.py)
289296
* [sol2](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_12/sol2.py)
290297
* Problem 13
291-
* [num](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_13/num.txt)
292298
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_13/sol1.py)
293-
* [sol2](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_13/sol2.py)
294299
* Problem 14
295300
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_14/sol1.py)
296301
* [sol2](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_14/sol2.py)
@@ -309,7 +314,6 @@
309314
* Problem 21
310315
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_21/sol1.py)
311316
* Problem 22
312-
* [p022 names](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_22/p022_names.txt)
313317
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_22/sol1.py)
314318
* [sol2](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_22/sol2.py)
315319
* Problem 234
@@ -337,8 +341,6 @@
337341
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_53/sol1.py)
338342
* Problem 76
339343
* [sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_76/sol1.py)
340-
## Scripts
341-
* [build directory md](https://github.com/TheAlgorithms/Python/blob/master/scripts/build_directory_md.py)
342344
## Searches
343345
* [binary search](https://github.com/TheAlgorithms/Python/blob/master/searches/binary_search.py)
344346
* [interpolation search](https://github.com/TheAlgorithms/Python/blob/master/searches/interpolation_search.py)
@@ -347,7 +349,6 @@
347349
* [quick select](https://github.com/TheAlgorithms/Python/blob/master/searches/quick_select.py)
348350
* [sentinel linear search](https://github.com/TheAlgorithms/Python/blob/master/searches/sentinel_linear_search.py)
349351
* [tabu search](https://github.com/TheAlgorithms/Python/blob/master/searches/tabu_search.py)
350-
* [tabu test data](https://github.com/TheAlgorithms/Python/blob/master/searches/tabu_test_data.txt)
351352
* [ternary search](https://github.com/TheAlgorithms/Python/blob/master/searches/ternary_search.py)
352353
## Sorts
353354
* [bitonic sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/bitonic_sort.py)

arithmetic_analysis/newton_raphson_method.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Implementing Newton Raphson method in Python
2-
# Author: Haseeb
2+
# Author: Syed Haseeb Shah (github.com/QuantumNovice)
33

44
from sympy import diff
55
from decimal import Decimal
@@ -30,7 +30,3 @@ def NewtonRaphson(func, a):
3030

3131
# Exponential Roots
3232
print ('exp(x) - 1 = 0', NewtonRaphson('exp(x) - 1', 0))
33-
34-
35-
36-

graphs/dijkstra.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def dijkstra(graph, start, end):
7171
"F": [["C", 3], ["E", 3]],
7272
}
7373

74-
"""
74+
r"""
7575
Layout of G2:
7676
7777
E -- 1 --> B -- 1 --> C -- 1 --> D -- 1 --> F
@@ -87,7 +87,7 @@ def dijkstra(graph, start, end):
8787
"F": [],
8888
}
8989

90-
"""
90+
r"""
9191
Layout of G3:
9292
9393
E -- 1 --> B -- 1 --> C -- 1 --> D -- 1 --> F

maths/abs_min.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from abs import abs_val
1+
from .abs import abs_val
2+
23

34
def absMin(x):
45
"""
5-
# >>>absMin([0,5,1,11])
6+
>>> absMin([0,5,1,11])
67
0
7-
# >>absMin([3,-10,-2])
8+
>>> absMin([3,-10,-2])
89
-2
910
"""
1011
j = x[0]
@@ -13,9 +14,11 @@ def absMin(x):
1314
j = i
1415
return j
1516

17+
1618
def main():
1719
a = [-3,-1,2,-11]
1820
print(absMin(a)) # = -1
1921

22+
2023
if __name__ == '__main__':
2124
main()

maths/binary_exponentiation.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ def binary_exponentiation(a, n):
1717
return b * b
1818

1919

20-
try:
21-
BASE = int(input('Enter Base : '))
22-
POWER = int(input("Enter Power : "))
23-
except ValueError:
24-
print("Invalid literal for integer")
25-
26-
RESULT = binary_exponentiation(BASE, POWER)
27-
print("{}^({}) : {}".format(BASE, POWER, RESULT))
20+
if __name__ == "__main__":
21+
try:
22+
BASE = int(input("Enter Base : ").strip())
23+
POWER = int(input("Enter Power : ").strip())
24+
except ValueError:
25+
print("Invalid literal for integer")
26+
27+
RESULT = binary_exponentiation(BASE, POWER)
28+
print("{}^({}) : {}".format(BASE, POWER, RESULT))

maths/gaussian.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
"""
3+
Reference: https://en.wikipedia.org/wiki/Gaussian_function
4+
5+
python/black : True
6+
python : 3.7.3
7+
8+
"""
9+
from numpy import pi, sqrt, exp
10+
11+
12+
13+
def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
14+
"""
15+
>>> gaussian(1)
16+
0.24197072451914337
17+
18+
>>> gaussian(24)
19+
3.342714441794458e-126
20+
21+
Supports NumPy Arrays
22+
Use numpy.meshgrid with this to generate gaussian blur on images.
23+
>>> import numpy as np
24+
>>> x = np.arange(15)
25+
>>> gaussian(x)
26+
array([3.98942280e-01, 2.41970725e-01, 5.39909665e-02, 4.43184841e-03,
27+
1.33830226e-04, 1.48671951e-06, 6.07588285e-09, 9.13472041e-12,
28+
5.05227108e-15, 1.02797736e-18, 7.69459863e-23, 2.11881925e-27,
29+
2.14638374e-32, 7.99882776e-38, 1.09660656e-43])
30+
31+
>>> gaussian(15)
32+
5.530709549844416e-50
33+
34+
>>> gaussian([1,2, 'string'])
35+
Traceback (most recent call last):
36+
...
37+
TypeError: unsupported operand type(s) for -: 'list' and 'float'
38+
39+
>>> gaussian('hello world')
40+
Traceback (most recent call last):
41+
...
42+
TypeError: unsupported operand type(s) for -: 'str' and 'float'
43+
44+
>>> gaussian(10**234) # doctest: +IGNORE_EXCEPTION_DETAIL
45+
Traceback (most recent call last):
46+
...
47+
OverflowError: (34, 'Result too large')
48+
49+
>>> gaussian(10**-326)
50+
0.3989422804014327
51+
52+
>>> gaussian(2523, mu=234234, sigma=3425)
53+
0.0
54+
"""
55+
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-(x - mu) ** 2 / 2 * sigma ** 2)
56+
57+
58+
if __name__ == "__main__":
59+
import doctest
60+
61+
doctest.testmod()

maths/images/gaussian.png

52.3 KB
Loading

maths/is_square_free.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
References: wikipedia:square free number
3+
python/black : True
4+
flake8 : True
5+
"""
6+
from typing import List
7+
8+
9+
def is_square_free(factors: List[int]) -> bool:
10+
"""
11+
# doctest: +NORMALIZE_WHITESPACE
12+
This functions takes a list of prime factors as input.
13+
returns True if the factors are square free.
14+
>>> is_square_free([1, 1, 2, 3, 4])
15+
False
16+
17+
These are wrong but should return some value
18+
it simply checks for repition in the numbers.
19+
>>> is_square_free([1, 3, 4, 'sd', 0.0])
20+
True
21+
22+
>>> is_square_free([1, 0.5, 2, 0.0])
23+
True
24+
>>> is_square_free([1, 2, 2, 5])
25+
False
26+
>>> is_square_free('asd')
27+
True
28+
>>> is_square_free(24)
29+
Traceback (most recent call last):
30+
...
31+
TypeError: 'int' object is not iterable
32+
"""
33+
return len(set(factors)) == len(factors)
34+
35+
36+
if __name__ == "__main__":
37+
import doctest
38+
39+
doctest.testmod()

maths/lucas_series.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# Lucas Sequence Using Recursion
22

33
def recur_luc(n):
4-
if n == 1:
5-
return n
6-
if n == 0:
7-
return 2
8-
return (recur_luc(n-1) + recur_luc(n-2))
9-
10-
limit = int(input("How many terms to include in Lucas series:"))
11-
print("Lucas series:")
12-
for i in range(limit):
13-
print(recur_luc(i))
4+
"""
5+
>>> recur_luc(1)
6+
1
7+
>>> recur_luc(0)
8+
2
9+
"""
10+
if n == 1:
11+
return n
12+
if n == 0:
13+
return 2
14+
return recur_luc(n - 1) + recur_luc(n - 2)
15+
16+
17+
if __name__ == "__main__":
18+
limit = int(input("How many terms to include in Lucas series:"))
19+
print("Lucas series:")
20+
for i in range(limit):
21+
print(recur_luc(i))

0 commit comments

Comments
 (0)