repo_name
stringclasses
1 value
pr_number
int64
4.12k
11.2k
pr_title
stringlengths
9
107
pr_description
stringlengths
107
5.48k
author
stringlengths
4
18
date_created
timestamp[ns, tz=UTC]
date_merged
timestamp[ns, tz=UTC]
previous_commit
stringlengths
40
40
pr_commit
stringlengths
40
40
query
stringlengths
118
5.52k
before_content
stringlengths
0
7.93M
after_content
stringlengths
0
7.93M
label
int64
-1
1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
"""README, Author - Anurag Kumar(mailto:anuragkumarak95@gmail.com) Requirements: - sklearn - numpy - matplotlib Python: - 3.5 Inputs: - X , a 2D numpy array of features. - k , number of clusters to create. - initial_centroids , initial centroid values generated by utility function(mentioned in usage)....
"""README, Author - Anurag Kumar(mailto:anuragkumarak95@gmail.com) Requirements: - sklearn - numpy - matplotlib Python: - 3.5 Inputs: - X , a 2D numpy array of features. - k , number of clusters to create. - initial_centroids , initial centroid values generated by utility function(mentioned in usage)....
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Problem 16: https://projecteuler.net/problem=16 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? """ def solution(power: int = 1000) -> int: """Returns the sum of the digits of the number 2^power. >>> solution(1000) 1366 >>> so...
""" Problem 16: https://projecteuler.net/problem=16 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? """ def solution(power: int = 1000) -> int: """Returns the sum of the digits of the number 2^power. >>> solution(1000) 1366 >>> so...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
# flake8: noqa """The following implementation assumes that the activities are already sorted according to their finish time""" """Prints a maximum set of activities that can be done by a single person, one at a time""" # n --> Total number of activities # start[]--> An array that contains start time of all activitie...
# flake8: noqa """The following implementation assumes that the activities are already sorted according to their finish time""" """Prints a maximum set of activities that can be done by a single person, one at a time""" # n --> Total number of activities # start[]--> An array that contains start time of all activitie...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Counting Summations Problem 76: https://projecteuler.net/problem=76 It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 2 + 1 + 1 + 1 1 + 1 + 1 + 1 + 1 How many different ways can one hundred be written as a sum of at least two positive integers? """ def solutio...
""" Counting Summations Problem 76: https://projecteuler.net/problem=76 It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 2 + 1 + 1 + 1 1 + 1 + 1 + 1 + 1 How many different ways can one hundred be written as a sum of at least two positive integers? """ def solutio...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
class things: def __init__(self, name, value, weight): self.name = name self.value = value self.weight = weight def __repr__(self): return f"{self.__class__.__name__}({self.name}, {self.value}, {self.weight})" def get_value(self): return self.value def get_name...
class things: def __init__(self, name, value, weight): self.name = name self.value = value self.weight = weight def __repr__(self): return f"{self.__class__.__name__}({self.name}, {self.value}, {self.weight})" def get_value(self): return self.value def get_name...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" author: Christian Bender date: 21.12.2017 class: XORCipher This class implements the XOR-cipher algorithm and provides some useful methods for encrypting and decrypting strings and files. Overview about methods - encrypt : list of char - dec...
""" author: Christian Bender date: 21.12.2017 class: XORCipher This class implements the XOR-cipher algorithm and provides some useful methods for encrypting and decrypting strings and files. Overview about methods - encrypt : list of char - dec...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word...
""" The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
import math from numpy import inf from scipy.integrate import quad def gamma(num: float) -> float: """ https://en.wikipedia.org/wiki/Gamma_function In mathematics, the gamma function is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all...
import math from numpy import inf from scipy.integrate import quad def gamma(num: float) -> float: """ https://en.wikipedia.org/wiki/Gamma_function In mathematics, the gamma function is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107. A modern encryption method is to take a text file, convert the bytes to ASCII, then XOR each byte...
""" Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107. A modern encryption method is to take a text file, convert the bytes to ASCII, then XOR each byte...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
# Print all subset combinations of n element in given set of r element. def combination_util(arr, n, r, index, data, i): """ Current combination is ready to be printed, print it arr[] ---> Input Array data[] ---> Temporary array to store current combination start & end ---> Staring and Ending ind...
# Print all subset combinations of n element in given set of r element. def combination_util(arr, n, r, index, data, i): """ Current combination is ready to be printed, print it arr[] ---> Input Array data[] ---> Temporary array to store current combination start & end ---> Staring and Ending ind...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Project Euler Problem 6: https://projecteuler.net/problem=6 Sum square difference The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^2 = 55^2 = 3025 Hence the difference between the sum of...
""" Project Euler Problem 6: https://projecteuler.net/problem=6 Sum square difference The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^2 = 55^2 = 3025 Hence the difference between the sum of...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Slowsort is a sorting algorithm. It is of humorous nature and not useful. It's based on the principle of multiply and surrender, a tongue-in-cheek joke of divide and conquer. It was published in 1986 by Andrei Broder and Jorge Stolfi in their paper Pessimal Algorithms and Simplexity Analysis (a parody of optimal al...
""" Slowsort is a sorting algorithm. It is of humorous nature and not useful. It's based on the principle of multiply and surrender, a tongue-in-cheek joke of divide and conquer. It was published in 1986 by Andrei Broder and Jorge Stolfi in their paper Pessimal Algorithms and Simplexity Analysis (a parody of optimal al...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
def oct_to_decimal(oct_string: str) -> int: """ Convert a octal value to its decimal equivalent >>> oct_to_decimal("12") 10 >>> oct_to_decimal(" 12 ") 10 >>> oct_to_decimal("-45") -37 >>> oct_to_decimal("2-0Fm") Traceback (most recent call last): ... ValueError: Non-oc...
def oct_to_decimal(oct_string: str) -> int: """ Convert a octal value to its decimal equivalent >>> oct_to_decimal("12") 10 >>> oct_to_decimal(" 12 ") 10 >>> oct_to_decimal("-45") -37 >>> oct_to_decimal("2-0Fm") Traceback (most recent call last): ... ValueError: Non-oc...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm def binary_xor(a: int, b: int) -> str: """ Take in 2 integers, convert them to binary, return a binary number that is the result of a binary xor operation on the integers provided. >>> binary_xor(25, 32) '0b111001' >>>...
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm def binary_xor(a: int, b: int) -> str: """ Take in 2 integers, convert them to binary, return a binary number that is the result of a binary xor operation on the integers provided. >>> binary_xor(25, 32) '0b111001' >>>...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" https://en.wikipedia.org/wiki/Shellsort#Pseudocode """ def shell_sort(collection): """Pure implementation of shell sort algorithm in Python :param collection: Some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending >>> she...
""" https://en.wikipedia.org/wiki/Shellsort#Pseudocode """ def shell_sort(collection): """Pure implementation of shell sort algorithm in Python :param collection: Some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending >>> she...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
from .stack import Stack def balanced_parentheses(parentheses: str) -> bool: """Use a stack to check if a string of parentheses is balanced. >>> balanced_parentheses("([]{})") True >>> balanced_parentheses("[()]{}{[()()]()}") True >>> balanced_parentheses("[(])") False >>> balanced_par...
from .stack import Stack def balanced_parentheses(parentheses: str) -> bool: """Use a stack to check if a string of parentheses is balanced. >>> balanced_parentheses("([]{})") True >>> balanced_parentheses("[()]{}{[()()]()}") True >>> balanced_parentheses("[(])") False >>> balanced_par...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
[report] sort = Cover omit = .env/*
[report] sort = Cover omit = .env/*
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
from typing import List def compare_string(string1: str, string2: str) -> str: """ >>> compare_string('0010','0110') '0_10' >>> compare_string('0110','1101') 'X' """ l1 = list(string1) l2 = list(string2) count = 0 for i in range(len(l1)): if l1[i] != l2[i]: ...
from typing import List def compare_string(string1: str, string2: str) -> str: """ >>> compare_string('0010','0110') '0_10' >>> compare_string('0110','1101') 'X' """ l1 = list(string1) l2 = list(string2) count = 0 for i in range(len(l1)): if l1[i] != l2[i]: ...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Name scores Problem 22 Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a ...
""" Name scores Problem 22 Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a ...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
#!/bin/sh # # An example hook script to prepare a packed repository for use over # dumb transports. # # To enable this hook, rename this file to "post-update". exec git update-server-info
#!/bin/sh # # An example hook script to prepare a packed repository for use over # dumb transports. # # To enable this hook, rename this file to "post-update". exec git update-server-info
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
from __future__ import annotations def abs_max(x: list[int]) -> int: """ >>> abs_max([0,5,1,11]) 11 >>> abs_max([3,-10,-2]) -10 """ j = x[0] for i in x: if abs(i) > abs(j): j = i return j def abs_max_sort(x): """ >>> abs_max_sort([0,5,1,11]) 11 ...
from __future__ import annotations def abs_max(x: list[int]) -> int: """ >>> abs_max([0,5,1,11]) 11 >>> abs_max([3,-10,-2]) -10 """ j = x[0] for i in x: if abs(i) > abs(j): j = i return j def abs_max_sort(x): """ >>> abs_max_sort([0,5,1,11]) 11 ...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072406154908250 23067588207539346171171980310421047513778063246676 89261670696623633820136378418383684178734361726757 28112879812849...
37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072406154908250 23067588207539346171171980310421047513778063246676 89261670696623633820136378418383684178734361726757 28112879812849...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
536fb4bca48f69cb66cfbd03aeb02550def07977
536fb4bca48f69cb66cfbd03aeb02550def07977
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Project Euler Problem 27 https://projecteuler.net/problem=27 Problem Statement: Euler discovered the remarkable quadratic formula: n2 + n + 41 It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and ...
""" Project Euler Problem 27 https://projecteuler.net/problem=27 Problem Statement: Euler discovered the remarkable quadratic formula: n2 + n + 41 It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and ...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm def binary_or(a: int, b: int) -> str: """ Take in 2 integers, convert them to binary, and return a binary number that is the result of a binary or operation on the integers provided. >>> binary_or(25, 32) '0b111001' >>> bi...
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm def binary_or(a: int, b: int) -> str: """ Take in 2 integers, convert them to binary, and return a binary number that is the result of a binary or operation on the integers provided. >>> binary_or(25, 32) '0b111001' >>> bi...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
def factors_of_a_number(num: int) -> list: """ >>> factors_of_a_number(1) [1] >>> factors_of_a_number(5) [1, 5] >>> factors_of_a_number(24) [1, 2, 3, 4, 6, 8, 12, 24] >>> factors_of_a_number(-24) [] """ return [i for i in range(1, num + 1) if num % i == 0] if __name__ == "_...
def factors_of_a_number(num: int) -> list: """ >>> factors_of_a_number(1) [1] >>> factors_of_a_number(5) [1, 5] >>> factors_of_a_number(24) [1, 2, 3, 4, 6, 8, 12, 24] >>> factors_of_a_number(-24) [] """ return [i for i in range(1, num + 1) if num % i == 0] if __name__ == "_...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" This script demonstrates the implementation of the Softmax function. Its a function that takes as input a vector of K real numbers, and normalizes it into a probability distribution consisting of K probabilities proportional to the exponentials of the input numbers. After softmax, the elements of the vector always...
""" This script demonstrates the implementation of the Softmax function. Its a function that takes as input a vector of K real numbers, and normalizes it into a probability distribution consisting of K probabilities proportional to the exponentials of the input numbers. After softmax, the elements of the vector always...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
import sys from collections import defaultdict def PrimsAlgorithm(l): # noqa: E741 nodePosition = [] def get_position(vertex): return nodePosition[vertex] def set_position(vertex, pos): nodePosition[vertex] = pos def top_to_bottom(heap, start, size, positions): if start > ...
import sys from collections import defaultdict def PrimsAlgorithm(l): # noqa: E741 nodePosition = [] def get_position(vertex): return nodePosition[vertex] def set_position(vertex, pos): nodePosition[vertex] = pos def top_to_bottom(heap, start, size, positions): if start > ...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
""" Project Euler Problem 7: https://projecteuler.net/problem=7 10001st prime By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? References: - https://en.wikipedia.org/wiki/Prime_number """ from math import sqrt def is_prime(...
""" Project Euler Problem 7: https://projecteuler.net/problem=7 10001st prime By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? References: - https://en.wikipedia.org/wiki/Prime_number """ from math import sqrt def is_prime(...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
from __future__ import annotations import math from typing import List, Union class SegmentTree: def __init__(self, size: int) -> None: self.size = size # approximate the overall size of segment tree with given value self.segment_tree = [0 for i in range(0, 4 * size)] # create arr...
from __future__ import annotations import math from typing import List, Union class SegmentTree: def __init__(self, size: int) -> None: self.size = size # approximate the overall size of segment tree with given value self.segment_tree = [0 for i in range(0, 4 * size)] # create arr...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
# https://en.wikipedia.org/wiki/Continuous_knapsack_problem # https://www.guru99.com/fractional-knapsack-problem-greedy.html # https://medium.com/walkinthecode/greedy-algorithm-fractional-knapsack-problem-9aba1daecc93 from __future__ import annotations def fractional_knapsack( value: list[int], weight: list[int]...
# https://en.wikipedia.org/wiki/Continuous_knapsack_problem # https://www.guru99.com/fractional-knapsack-problem-greedy.html # https://medium.com/walkinthecode/greedy-algorithm-fractional-knapsack-problem-9aba1daecc93 from __future__ import annotations def fractional_knapsack( value: list[int], weight: list[int]...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
-1
TheAlgorithms/Python
4,314
fix(mypy): type annotations for conversions algorithms
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I have ...
dhruvmanila
2021-04-04T13:03:20Z
2021-04-04T13:25:49Z
536fb4bca48f69cb66cfbd03aeb02550def07977
20c7518028efbb6e8ae46a42b28c3f2e27acb2a2
fix(mypy): type annotations for conversions algorithms. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md)...
import math from timeit import timeit def num_digits(n: int) -> int: """ Find the number of digits in a number. >>> num_digits(12345) 5 >>> num_digits(123) 3 >>> num_digits(0) 1 >>> num_digits(-1) 1 >>> num_digits(-123456) 6 """ digits = 0 n = abs(n) wh...
import math from timeit import timeit def num_digits(n: int) -> int: """ Find the number of digits in a number. >>> num_digits(12345) 5 >>> num_digits(123) 3 >>> num_digits(0) 1 >>> num_digits(-1) 1 >>> num_digits(-123456) 6 """ digits = 0 n = abs(n) wh...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
name: "build" on: pull_request: schedule: - cron: "0 0 * * *" # Run everyday jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: "3.9" - uses: actions/cache@v2 with: path: ~...
name: "build" on: pull_request: schedule: - cron: "0 0 * * *" # Run everyday jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: "3.9" - uses: actions/cache@v2 with: path: ~...
1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Adler-32 is a checksum algorithm which was invented by Mark Adler in 1995. Compared to a cyclic redundancy check of the same length, it trades reliability for speed (preferring the latter). Adler-32 is more reliable than Fletcher-16, and slightly less reliable than Fletcher-32.[2] source: h...
""" Adler-32 is a checksum algorithm which was invented by Mark Adler in 1995. Compared to a cyclic redundancy check of the same length, it trades reliability for speed (preferring the latter). Adler-32 is more reliable than Fletcher-16, and slightly less reliable than Fletcher-32.[2] source: h...
1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
"""example of simple chaos machine""" # Chaos Machine (K, t, m) K = [0.33, 0.44, 0.55, 0.44, 0.33] t = 3 m = 5 # Buffer Space (with Parameters Space) buffer_space, params_space = [], [] # Machine Time machine_time = 0 def push(seed): global buffer_space, params_space, machine_time, K, m, t # Choosing Dyna...
"""example of simple chaos machine""" # Chaos Machine (K, t, m) K = [0.33, 0.44, 0.55, 0.44, 0.33] t = 3 m = 5 # Buffer Space (with Parameters Space) buffer_space: list[float] = [] params_space: list[float] = [] # Machine Time machine_time = 0 def push(seed): global buffer_space, params_space, machine_time, K,...
1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
alphabets = [chr(i) for i in range(32, 126)] gear_one = [i for i in range(len(alphabets))] gear_two = [i for i in range(len(alphabets))] gear_three = [i for i in range(len(alphabets))] reflector = [i for i in reversed(range(len(alphabets)))] code = [] gear_one_pos = gear_two_pos = gear_three_pos = 0 def rotator(): ...
alphabets = [chr(i) for i in range(32, 126)] gear_one = [i for i in range(len(alphabets))] gear_two = [i for i in range(len(alphabets))] gear_three = [i for i in range(len(alphabets))] reflector = [i for i in reversed(range(len(alphabets)))] code = [] gear_one_pos = gear_two_pos = gear_three_pos = 0 def rotator(): ...
1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" This algorithm was created for sdbm (a public-domain reimplementation of ndbm) database library. It was found to do well in scrambling bits, causing better distribution of the keys and fewer splits. It also happens to be a good general hashing function with good distribution. The actual func...
""" This algorithm was created for sdbm (a public-domain reimplementation of ndbm) database library. It was found to do well in scrambling bits, causing better distribution of the keys and fewer splits. It also happens to be a good general hashing function with good distribution. The actual func...
1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
def reverse_words(input_str: str) -> str: """ Reverses words in a given string >>> reverse_words("I love Python") 'Python love I' >>> reverse_words("I Love Python") 'Python Love I' """ return " ".join(input_str.split()[::-1]) if __name__ == "__main__": import doctest ...
def reverse_words(input_str: str) -> str: """ Reverses words in a given string >>> reverse_words("I love Python") 'Python love I' >>> reverse_words("I Love Python") 'Python Love I' """ return " ".join(input_str.split()[::-1]) if __name__ == "__main__": import doctest ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
class FlowNetwork: def __init__(self, graph, sources, sinks): self.sourceIndex = None self.sinkIndex = None self.graph = graph self._normalizeGraph(sources, sinks) self.verticesCount = len(graph) self.maximumFlowAlgorithm = None # make only one source and one si...
class FlowNetwork: def __init__(self, graph, sources, sinks): self.sourceIndex = None self.sinkIndex = None self.graph = graph self._normalizeGraph(sources, sinks) self.verticesCount = len(graph) self.maximumFlowAlgorithm = None # make only one source and one si...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
def perfect_cube(n: int) -> bool: """ Check if a number is a perfect cube or not. >>> perfect_cube(27) True >>> perfect_cube(4) False """ val = n ** (1 / 3) return (val * val * val) == n if __name__ == "__main__": print(perfect_cube(27)) print(perfect_cube(4))
def perfect_cube(n: int) -> bool: """ Check if a number is a perfect cube or not. >>> perfect_cube(27) True >>> perfect_cube(4) False """ val = n ** (1 / 3) return (val * val * val) == n if __name__ == "__main__": print(perfect_cube(27)) print(perfect_cube(4))
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
hex_table = {hex(i)[2:]: i for i in range(16)} # Use [:2] to strip off the leading '0x' def hex_to_decimal(hex_string: str) -> int: """ Convert a hexadecimal value to its decimal equivalent #https://www.programiz.com/python-programming/methods/built-in/hex >>> hex_to_decimal("a") 10 >>> hex_...
hex_table = {hex(i)[2:]: i for i in range(16)} # Use [:2] to strip off the leading '0x' def hex_to_decimal(hex_string: str) -> int: """ Convert a hexadecimal value to its decimal equivalent #https://www.programiz.com/python-programming/methods/built-in/hex >>> hex_to_decimal("a") 10 >>> hex_...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" def main(): message = input("Enter message: ") key = input("Enter key [alphanumeric]: ") mode = input("Encrypt/Decrypt [e/d]: ") if mode.lower().startswith("e"): mode = "encrypt" translated = encryptMessage(key, message) elif mode.lower().sta...
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" def main(): message = input("Enter message: ") key = input("Enter key [alphanumeric]: ") mode = input("Encrypt/Decrypt [e/d]: ") if mode.lower().startswith("e"): mode = "encrypt" translated = encryptMessage(key, message) elif mode.lower().sta...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Created on Fri Oct 16 09:31:07 2020 @author: Dr. Tobias Schröder @license: MIT-license This file contains the test-suite for the knapsack problem. """ import unittest from knapsack import knapsack as k class Test(unittest.TestCase): def test_base_case(self): """ test for the base case ...
""" Created on Fri Oct 16 09:31:07 2020 @author: Dr. Tobias Schröder @license: MIT-license This file contains the test-suite for the knapsack problem. """ import unittest from knapsack import knapsack as k class Test(unittest.TestCase): def test_base_case(self): """ test for the base case ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Modular Exponential. Modular exponentiation is a type of exponentiation performed over a modulus. For more explanation, please check https://en.wikipedia.org/wiki/Modular_exponentiation """ """Calculate Modular Exponential.""" def modular_exponential(base: int, power: int, mod: int): """ ...
""" Modular Exponential. Modular exponentiation is a type of exponentiation performed over a modulus. For more explanation, please check https://en.wikipedia.org/wiki/Modular_exponentiation """ """Calculate Modular Exponential.""" def modular_exponential(base: int, power: int, mod: int): """ ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
#!/usr/bin/env python3 """Provide the functionality to manipulate a single bit.""" def set_bit(number: int, position: int) -> int: """ Set the bit at position to 1. Details: perform bitwise or for given number and X. Where X is a number with all the bits – zeroes and bit on given position – one....
#!/usr/bin/env python3 """Provide the functionality to manipulate a single bit.""" def set_bit(number: int, position: int) -> int: """ Set the bit at position to 1. Details: perform bitwise or for given number and X. Where X is a number with all the bits – zeroes and bit on given position – one....
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
# An OOP approach to representing and manipulating matrices class Matrix: """ Matrix object generated from a 2D array where each element is an array representing a row. Rows can contain type int or float. Common operations and information available. >>> rows = [ ... [1, 2, 3], ... ...
# An OOP approach to representing and manipulating matrices class Matrix: """ Matrix object generated from a 2D array where each element is an array representing a row. Rows can contain type int or float. Common operations and information available. >>> rows = [ ... [1, 2, 3], ... ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Project Euler Problem 9: https://projecteuler.net/problem=9 Special Pythagorean triplet A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find th...
""" Project Euler Problem 9: https://projecteuler.net/problem=9 Special Pythagorean triplet A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find th...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Testing here assumes that numpy and linalg is ALWAYS correct!!!! If running from PyCharm you can place the following line in "Additional Arguments" for the pytest run configuration -vv -m mat_ops -p no:cacheprovider """ import logging # standard libraries import sys import numpy as np import pytest # type: ign...
""" Testing here assumes that numpy and linalg is ALWAYS correct!!!! If running from PyCharm you can place the following line in "Additional Arguments" for the pytest run configuration -vv -m mat_ops -p no:cacheprovider """ import logging # standard libraries import sys import numpy as np import pytest # type: ign...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Description The Koch snowflake is a fractal curve and one of the earliest fractals to have been described. The Koch snowflake can be built up iteratively, in a sequence of stages. The first stage is an equilateral triangle, and each successive stage is formed by adding outward bends to each side of ...
""" Description The Koch snowflake is a fractal curve and one of the earliest fractals to have been described. The Koch snowflake can be built up iteratively, in a sequence of stages. The first stage is an equilateral triangle, and each successive stage is formed by adding outward bends to each side of ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
"""Implementation of Basic Math in Python.""" import math def prime_factors(n: int) -> list: """Find Prime Factors. >>> prime_factors(100) [2, 2, 5, 5] """ pf = [] while n % 2 == 0: pf.append(2) n = int(n / 2) for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i...
"""Implementation of Basic Math in Python.""" import math def prime_factors(n: int) -> list: """Find Prime Factors. >>> prime_factors(100) [2, 2, 5, 5] """ pf = [] while n % 2 == 0: pf.append(2) n = int(n / 2) for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
import os import random import sys from . import cryptomath_module as cryptomath from . import rabin_miller min_primitive_root = 3 # I have written my code naively same as definition of primitive root # however every time I run this program, memory exceeded... # so I used 4.80 Algorithm in # Handbook of Applied Cry...
import os import random import sys from . import cryptomath_module as cryptomath from . import rabin_miller min_primitive_root = 3 # I have written my code naively same as definition of primitive root # however every time I run this program, memory exceeded... # so I used 4.80 Algorithm in # Handbook of Applied Cry...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" The Reverse Polish Nation also known as Polish postfix notation or simply postfix notation. https://en.wikipedia.org/wiki/Reverse_Polish_notation Classic examples of simple stack implementations Valid operators are +, -, *, /. Each operand may be an integer or another expression. """ def evaluate_postfix(postfix_...
""" The Reverse Polish Nation also known as Polish postfix notation or simply postfix notation. https://en.wikipedia.org/wiki/Reverse_Polish_notation Classic examples of simple stack implementations Valid operators are +, -, *, /. Each operand may be an integer or another expression. """ def evaluate_postfix(postfix_...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
from __future__ import annotations import re def natural_sort(input_list: list[str]) -> list[str]: """ Sort the given list of strings in the way that humans expect. The normal Python sort algorithm sorts lexicographically, so you might not get the results that you expect... >>> example1 = ['2 f...
from __future__ import annotations import re def natural_sort(input_list: list[str]) -> list[str]: """ Sort the given list of strings in the way that humans expect. The normal Python sort algorithm sorts lexicographically, so you might not get the results that you expect... >>> example1 = ['2 f...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Project Euler Problem 57: https://projecteuler.net/problem=57 It is possible to show that the square root of two can be expressed as an infinite continued fraction. sqrt(2) = 1 + 1 / (2 + 1 / (2 + 1 / (2 + ...))) By expanding this for the first four iterations, we get: 1 + 1 / 2 = 3 / 2 = 1.5 1 + 1 / (2 + 1 / 2} ...
""" Project Euler Problem 57: https://projecteuler.net/problem=57 It is possible to show that the square root of two can be expressed as an infinite continued fraction. sqrt(2) = 1 + 1 / (2 + 1 / (2 + 1 / (2 + ...))) By expanding this for the first four iterations, we get: 1 + 1 / 2 = 3 / 2 = 1.5 1 + 1 / (2 + 1 / 2} ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" pseudo-code DIJKSTRA(graph G, start vertex s, destination vertex d): //all nodes initially unexplored 1 - let H = min heap data structure, initialized with 0 and s [here 0 indicates the distance from start vertex s] 2 - while H is non-empty: 3 - remove the first node and cost of H, call it U and cost 4...
""" pseudo-code DIJKSTRA(graph G, start vertex s, destination vertex d): //all nodes initially unexplored 1 - let H = min heap data structure, initialized with 0 and s [here 0 indicates the distance from start vertex s] 2 - while H is non-empty: 3 - remove the first node and cost of H, call it U and cost 4...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Lychrel numbers Problem 55: https://projecteuler.net/problem=55 If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindromes so quickly. For example, 349 + 943 = 1292, 1292 + 2921 = 4213 4213 + 3124 = 7337 That is, 349 took three iterations to arrive at a palindrome. A...
""" Lychrel numbers Problem 55: https://projecteuler.net/problem=55 If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindromes so quickly. For example, 349 + 943 = 1292, 1292 + 2921 = 4213 4213 + 3124 = 7337 That is, 349 took three iterations to arrive at a palindrome. A...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Implemented an algorithm using opencv to tone an image with sepia technique """ from cv2 import destroyAllWindows, imread, imshow, waitKey def make_sepia(img, factor: int): """ Function create sepia tone. Source: https://en.wikipedia.org/wiki/Sepia_(color) """ pixel_h, pixel_v = img.shape[...
""" Implemented an algorithm using opencv to tone an image with sepia technique """ from cv2 import destroyAllWindows, imread, imshow, waitKey def make_sepia(img, factor: int): """ Function create sepia tone. Source: https://en.wikipedia.org/wiki/Sepia_(color) """ pixel_h, pixel_v = img.shape[...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
class Node: def __init__(self, data): self.data = data self.next = None def __repr__(self): return f"Node({self.data})" class LinkedList: def __init__(self): self.head = None def __iter__(self): node = self.head while node: yield node.data ...
class Node: def __init__(self, data): self.data = data self.next = None def __repr__(self): return f"Node({self.data})" class LinkedList: def __init__(self): self.head = None def __iter__(self): node = self.head while node: yield node.data ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Project Euler Problem 129: https://projecteuler.net/problem=129 A number consisting entirely of ones is called a repunit. We shall define R(k) to be a repunit of length k; for example, R(6) = 111111. Given that n is a positive integer and GCD(n, 10) = 1, it can be shown that there always exists a value, k, for wh...
""" Project Euler Problem 129: https://projecteuler.net/problem=129 A number consisting entirely of ones is called a repunit. We shall define R(k) to be a repunit of length k; for example, R(6) = 111111. Given that n is a positive integer and GCD(n, 10) = 1, it can be shown that there always exists a value, k, for wh...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
# Check whether Graph is Bipartite or Not using DFS # A Bipartite Graph is a graph whose vertices can be divided into two independent sets, # U and V such that every edge (u, v) either connects a vertex from U to V or a vertex # from V to U. In other words, for every edge (u, v), either u belongs to U and v to V, # o...
# Check whether Graph is Bipartite or Not using DFS # A Bipartite Graph is a graph whose vertices can be divided into two independent sets, # U and V such that every edge (u, v) either connects a vertex from U to V or a vertex # from V to U. In other words, for every edge (u, v), either u belongs to U and v to V, # o...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
# Numbers of alphabet which we call base alphabet_size = 256 # Modulus to hash a string modulus = 1000003 def rabin_karp(pattern: str, text: str) -> bool: """ The Rabin-Karp Algorithm for finding a pattern within a piece of text with complexity O(nm), most efficient when it is used with multiple patterns ...
# Numbers of alphabet which we call base alphabet_size = 256 # Modulus to hash a string modulus = 1000003 def rabin_karp(pattern: str, text: str) -> bool: """ The Rabin-Karp Algorithm for finding a pattern within a piece of text with complexity O(nm), most efficient when it is used with multiple patterns ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Project Euler Problem 10: https://projecteuler.net/problem=10 Summation of primes The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. References: - https://en.wikipedia.org/wiki/Prime_number - https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes """ d...
""" Project Euler Problem 10: https://projecteuler.net/problem=10 Summation of primes The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. References: - https://en.wikipedia.org/wiki/Prime_number - https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes """ d...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" This is a pure Python implementation of the Harmonic Series algorithm https://en.wikipedia.org/wiki/Harmonic_series_(mathematics) For doctests run following command: python -m doctest -v harmonic_series.py or python3 -m doctest -v harmonic_series.py For manual testing run: python3 harmonic_series.py """ def har...
""" This is a pure Python implementation of the Harmonic Series algorithm https://en.wikipedia.org/wiki/Harmonic_series_(mathematics) For doctests run following command: python -m doctest -v harmonic_series.py or python3 -m doctest -v harmonic_series.py For manual testing run: python3 harmonic_series.py """ def har...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
{ "001": "233168", "002": "4613732", "003": "6857", "004": "906609", "005": "232792560", "006": "25164150", "007": "104743", "008": "23514624000", "009": "31875000", "010": "142913828922", "011": "70600674", "012": "76576500", "013": "5537376230", "014": "837799", "015": "137846528820", ...
{ "001": "233168", "002": "4613732", "003": "6857", "004": "906609", "005": "232792560", "006": "25164150", "007": "104743", "008": "23514624000", "009": "31875000", "010": "142913828922", "011": "70600674", "012": "76576500", "013": "5537376230", "014": "837799", "015": "137846528820", ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
import random class Onepad: def encrypt(self, text: str) -> ([str], [int]): """Function to encrypt text using pseudo-random numbers""" plain = [ord(i) for i in text] key = [] cipher = [] for i in plain: k = random.randint(1, 300) c = (i + k) * k ...
import random class Onepad: def encrypt(self, text: str) -> ([str], [int]): """Function to encrypt text using pseudo-random numbers""" plain = [ord(i) for i in text] key = [] cipher = [] for i in plain: k = random.randint(1, 300) c = (i + k) * k ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" This is pure Python implementation of Tabu search algorithm for a Travelling Salesman Problem, that the distances between the cities are symmetric (the distance between city 'a' and city 'b' is the same between city 'b' and city 'a'). The TSP can be represented into a graph. The cities are represented by nodes and ...
""" This is pure Python implementation of Tabu search algorithm for a Travelling Salesman Problem, that the distances between the cities are symmetric (the distance between city 'a' and city 'b' is the same between city 'b' and city 'a'). The TSP can be represented into a graph. The cities are represented by nodes and ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Problem 120 Square remainders: https://projecteuler.net/problem=120 Description: Let r be the remainder when (a−1)^n + (a+1)^n is divided by a^2. For example, if a = 7 and n = 3, then r = 42: 6^3 + 8^3 = 728 ≡ 42 mod 49. And as n varies, so too will r, but for a = 7 it turns out that r_max = 42. For 3 ≤ a ≤ 1000,...
""" Problem 120 Square remainders: https://projecteuler.net/problem=120 Description: Let r be the remainder when (a−1)^n + (a+1)^n is divided by a^2. For example, if a = 7 and n = 3, then r = 42: 6^3 + 8^3 = 728 ≡ 42 mod 49. And as n varies, so too will r, but for a = 7 it turns out that r_max = 42. For 3 ≤ a ≤ 1000,...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
# flake8: noqa """ This is pure Python implementation of tree traversal algorithms """ from __future__ import annotations import queue class TreeNode: def __init__(self, data): self.data = data self.right = None self.left = None def build_tree(): print("\n********Press N to stop en...
# flake8: noqa """ This is pure Python implementation of tree traversal algorithms """ from __future__ import annotations import queue class TreeNode: def __init__(self, data): self.data = data self.right = None self.left = None def build_tree(): print("\n********Press N to stop en...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
"""Password generator allows you to generate a random password of length N.""" from random import choice, shuffle from string import ascii_letters, digits, punctuation def password_generator(length=8): """ >>> len(password_generator()) 8 >>> len(password_generator(length=16)) 16 >>> len(passwo...
"""Password generator allows you to generate a random password of length N.""" from random import choice, shuffle from string import ascii_letters, digits, punctuation def password_generator(length=8): """ >>> len(password_generator()) 8 >>> len(password_generator(length=16)) 16 >>> len(passwo...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
from binascii import hexlify from hashlib import sha256 from os import urandom # RFC 3526 - More Modular Exponential (MODP) Diffie-Hellman groups for # Internet Key Exchange (IKE) https://tools.ietf.org/html/rfc3526 primes = { # 1536-bit 5: { "prime": int( "FFFFFFFFFFFFFFFFC90FDAA22168C234...
from binascii import hexlify from hashlib import sha256 from os import urandom # RFC 3526 - More Modular Exponential (MODP) Diffie-Hellman groups for # Internet Key Exchange (IKE) https://tools.ietf.org/html/rfc3526 primes = { # 1536-bit 5: { "prime": int( "FFFFFFFFFFFFFFFFC90FDAA22168C234...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, … shows the first 11 ugly numbers. By convention, 1 is included. Given an integer n, we have to find the nth ugly number. For more details, refer this article https://www.geeksforgeeks.org/ugly-numbers...
""" Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, … shows the first 11 ugly numbers. By convention, 1 is included. Given an integer n, we have to find the nth ugly number. For more details, refer this article https://www.geeksforgeeks.org/ugly-numbers...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
from datetime import datetime import requests def download_video(url: str) -> bytes: base_url = "https://downloadgram.net/wp-json/wppress/video-downloader/video?url=" video_url = requests.get(base_url + url).json()[0]["urls"][0]["src"] return requests.get(video_url).content if __name__ == "__main__": ...
from datetime import datetime import requests def download_video(url: str) -> bytes: base_url = "https://downloadgram.net/wp-json/wppress/video-downloader/video?url=" video_url = requests.get(base_url + url).json()[0]["urls"][0]["src"] return requests.get(video_url).content if __name__ == "__main__": ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock's price for all n days. The span Si of the stock's price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the pri...
""" The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock's price for all n days. The span Si of the stock's price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the pri...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
__author__ = "Tobias Carryer" from time import time class LinearCongruentialGenerator: """ A pseudorandom number generator. """ def __init__(self, multiplier, increment, modulo, seed=int(time())): """ These parameters are saved and used when nextNumber() is called. modulo is...
__author__ = "Tobias Carryer" from time import time class LinearCongruentialGenerator: """ A pseudorandom number generator. """ def __init__(self, multiplier, increment, modulo, seed=int(time())): """ These parameters are saved and used when nextNumber() is called. modulo is...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" Created on Mon Feb 26 14:29:11 2018 @author: Christian Bender @license: MIT-license This module contains some useful classes and functions for dealing with linear algebra in python. Overview: - class Vector - function zeroVector(dimension) - function unitBasisVector(dimension,pos) - function axpy(scalar,vector1...
""" Created on Mon Feb 26 14:29:11 2018 @author: Christian Bender @license: MIT-license This module contains some useful classes and functions for dealing with linear algebra in python. Overview: - class Vector - function zeroVector(dimension) - function unitBasisVector(dimension,pos) - function axpy(scalar,vector1...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-,16,12,21,-,-,- 16,-,-,17,20,-,- 12,-,-,28,-,31,- 21,17,28,-,18,19,23 -,20,-,18,-,-,11 -,-,31,19,-,-,27 -,-,-,23,11,27,-
-,16,12,21,-,-,- 16,-,-,17,20,-,- 12,-,-,28,-,31,- 21,17,28,-,18,19,23 -,20,-,18,-,-,11 -,-,31,19,-,-,27 -,-,-,23,11,27,-
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
from __future__ import annotations import random class Dice: NUM_SIDES = 6 def __init__(self): """ Initialize a six sided dice """ self.sides = list(range(1, Dice.NUM_SIDES + 1)) def roll(self): return random.choice(self.sides) def _str_(self): return "Fair Dice" ...
from __future__ import annotations import random class Dice: NUM_SIDES = 6 def __init__(self): """ Initialize a six sided dice """ self.sides = list(range(1, Dice.NUM_SIDES + 1)) def roll(self): return random.choice(self.sides) def _str_(self): return "Fair Dice" ...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
-1
TheAlgorithms/Python
4,305
[mypy] fix hashes folder
### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is all my own work -- I h...
algobytewise
2021-04-02T08:55:40Z
2021-04-03T08:01:46Z
5229c749553d9ec65d455e0183a574e45ac3e73e
a53fcf221bc1d361b26c055aa12be38c4e8b2022
[mypy] fix hashes folder. ### **Describe your change:** * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request...
""" https://en.wikipedia.org/wiki/Strongly_connected_component Finding strongly connected components in directed graph """ test_graph_1 = {0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []} test_graph_2 = {0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]} def topology_sort(graph: dict, vert: int, visited: list) -> lis...
""" https://en.wikipedia.org/wiki/Strongly_connected_component Finding strongly connected components in directed graph """ test_graph_1 = {0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []} test_graph_2 = {0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]} def topology_sort(graph: dict, vert: int, visited: list) -> lis...
-1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
name: "build" on: pull_request: schedule: - cron: "0 0 * * *" # Run everyday jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: "3.9" - uses: actions/cache@v2 with: path: ~...
name: "build" on: pull_request: schedule: - cron: "0 0 * * *" # Run everyday jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: "3.9" - uses: actions/cache@v2 with: path: ~...
1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
name: pre-commit on: [push, pull_request] jobs: pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/cache@v2 with: path: | ~/.cache/pre-commit ~/.cache/pip key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-c...
name: pre-commit on: [push, pull_request] jobs: pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/cache@v2 with: path: | ~/.cache/pre-commit ~/.cache/pip key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-c...
1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
""" Gaussian elimination method for solving a system of linear equations. Gaussian elimination - https://en.wikipedia.org/wiki/Gaussian_elimination """ import numpy as np def retroactive_resolution(coefficients: np.matrix, vector: np.array) -> np.array: """ This function performs a retroactive linear system...
""" Gaussian elimination method for solving a system of linear equations. Gaussian elimination - https://en.wikipedia.org/wiki/Gaussian_elimination """ import numpy as np def retroactive_resolution(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray: """ This function performs a retroactive linear sy...
1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
""" Checks if a system of forces is in static equilibrium. """ from typing import List from numpy import array, cos, cross, radians, sin def polar_force( magnitude: float, angle: float, radian_mode: bool = False ) -> List[float]: """ Resolves force along rectangular components. (force, angle) => (for...
""" Checks if a system of forces is in static equilibrium. """ from typing import List from numpy import array, cos, cross, ndarray, radians, sin def polar_force( magnitude: float, angle: float, radian_mode: bool = False ) -> List[float]: """ Resolves force along rectangular components. (force, angle...
1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
-1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
""" Problem 14: https://projecteuler.net/problem=14 Problem Statement: The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4...
""" Problem 14: https://projecteuler.net/problem=14 Problem Statement: The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4...
-1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
#!/usr/bin/env python3 from .number_theory.prime_numbers import next_prime class HashTable: """ Basic Hash Table example with open addressing and linear probing """ def __init__(self, size_table, charge_factor=None, lim_charge=None): self.size_table = size_table self.values = [None] *...
#!/usr/bin/env python3 from .number_theory.prime_numbers import next_prime class HashTable: """ Basic Hash Table example with open addressing and linear probing """ def __init__(self, size_table, charge_factor=None, lim_charge=None): self.size_table = size_table self.values = [None] *...
-1
TheAlgorithms/Python
4,304
[mypy] Fix directory arithmetic_analysis
### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). * [x] This pull request is al...
algobytewise
2021-04-02T07:15:46Z
2021-04-02T07:32:13Z
895bca36541598a04dba525568a20d2282e0ffd9
5229c749553d9ec65d455e0183a574e45ac3e73e
[mypy] Fix directory arithmetic_analysis. ### **Describe your change:** Related Issue: #4052 * [ ] Add an algorithm? * [x] Fix a bug or typo in an existing algorithm? * [ ] Documentation change? ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRI...
-1