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,949
Fix typos in Sorts and Bit_manipulation
### **Describe your change:** * [x] Fixes the typos in the sorts and bit_manipulation folder * [x] Fixes the initially messed links in bit_manipulation/README.md ![Screenshot from 2021-10-03 13-57-36](https://user-images.githubusercontent.com/76519771/135746011-7acfad52-9ee5-412d-821d-8314adaf5ada.png) ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
Manan-Rathi
2021-10-03T08:24:44Z
2021-10-20T08:42:32Z
83cf5786cddd694a2af25827f8861b7dbcbf706c
50485f7c8e33b0a3bf6e603cdae3505d40b1d97a
Fix typos in Sorts and Bit_manipulation. ### **Describe your change:** * [x] Fixes the typos in the sorts and bit_manipulation folder * [x] Fixes the initially messed links in bit_manipulation/README.md ![Screenshot from 2021-10-03 13-57-36](https://user-images.githubusercontent.com/76519771/135746011-7acfad52-9ee5-412d-821d-8314adaf5ada.png) ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
# Created by sarathkaul on 12/11/19 import requests _NEWS_API = "https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=" def fetch_bbc_news(bbc_news_api_key: str) -> None: # fetching a list of articles in json format bbc_news_page = requests.get(_NEWS_API + bbc_news_api_key).json() # each article in the list is a dict for i, article in enumerate(bbc_news_page["articles"], 1): print(f"{i}.) {article['title']}") if __name__ == "__main__": fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")
# Created by sarathkaul on 12/11/19 import requests _NEWS_API = "https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=" def fetch_bbc_news(bbc_news_api_key: str) -> None: # fetching a list of articles in json format bbc_news_page = requests.get(_NEWS_API + bbc_news_api_key).json() # each article in the list is a dict for i, article in enumerate(bbc_news_page["articles"], 1): print(f"{i}.) {article['title']}") if __name__ == "__main__": fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")
-1
TheAlgorithms/Python
4,949
Fix typos in Sorts and Bit_manipulation
### **Describe your change:** * [x] Fixes the typos in the sorts and bit_manipulation folder * [x] Fixes the initially messed links in bit_manipulation/README.md ![Screenshot from 2021-10-03 13-57-36](https://user-images.githubusercontent.com/76519771/135746011-7acfad52-9ee5-412d-821d-8314adaf5ada.png) ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
Manan-Rathi
2021-10-03T08:24:44Z
2021-10-20T08:42:32Z
83cf5786cddd694a2af25827f8861b7dbcbf706c
50485f7c8e33b0a3bf6e603cdae3505d40b1d97a
Fix typos in Sorts and Bit_manipulation. ### **Describe your change:** * [x] Fixes the typos in the sorts and bit_manipulation folder * [x] Fixes the initially messed links in bit_manipulation/README.md ![Screenshot from 2021-10-03 13-57-36](https://user-images.githubusercontent.com/76519771/135746011-7acfad52-9ee5-412d-821d-8314adaf5ada.png) ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
""" Author: P Shreyas Shetty Implementation of Newton-Raphson method for solving equations of kind f(x) = 0. It is an iterative method where solution is found by the expression x[n+1] = x[n] + f(x[n])/f'(x[n]) If no solution exists, then either the solution will not be found when iteration limit is reached or the gradient f'(x[n]) approaches zero. In both cases, exception is raised. If iteration limit is reached, try increasing maxiter. """ import math as m def calc_derivative(f, a, h=0.001): """ Calculates derivative at point a for function f using finite difference method """ return (f(a + h) - f(a - h)) / (2 * h) def newton_raphson(f, x0=0, maxiter=100, step=0.0001, maxerror=1e-6, logsteps=False): a = x0 # set the initial guess steps = [a] error = abs(f(a)) f1 = lambda x: calc_derivative(f, x, h=step) # noqa: E731 Derivative of f(x) for _ in range(maxiter): if f1(a) == 0: raise ValueError("No converging solution found") a = a - f(a) / f1(a) # Calculate the next estimate if logsteps: steps.append(a) if error < maxerror: break else: raise ValueError("Iteration limit reached, no converging solution found") if logsteps: # If logstep is true, then log intermediate steps return a, error, steps return a, error if __name__ == "__main__": from matplotlib import pyplot as plt f = lambda x: m.tanh(x) ** 2 - m.exp(3 * x) # noqa: E731 solution, error, steps = newton_raphson( f, x0=10, maxiter=1000, step=1e-6, logsteps=True ) plt.plot([abs(f(x)) for x in steps]) plt.xlabel("step") plt.ylabel("error") plt.show() print(f"solution = {{{solution:f}}}, error = {{{error:f}}}")
""" Author: P Shreyas Shetty Implementation of Newton-Raphson method for solving equations of kind f(x) = 0. It is an iterative method where solution is found by the expression x[n+1] = x[n] + f(x[n])/f'(x[n]) If no solution exists, then either the solution will not be found when iteration limit is reached or the gradient f'(x[n]) approaches zero. In both cases, exception is raised. If iteration limit is reached, try increasing maxiter. """ import math as m def calc_derivative(f, a, h=0.001): """ Calculates derivative at point a for function f using finite difference method """ return (f(a + h) - f(a - h)) / (2 * h) def newton_raphson(f, x0=0, maxiter=100, step=0.0001, maxerror=1e-6, logsteps=False): a = x0 # set the initial guess steps = [a] error = abs(f(a)) f1 = lambda x: calc_derivative(f, x, h=step) # noqa: E731 Derivative of f(x) for _ in range(maxiter): if f1(a) == 0: raise ValueError("No converging solution found") a = a - f(a) / f1(a) # Calculate the next estimate if logsteps: steps.append(a) if error < maxerror: break else: raise ValueError("Iteration limit reached, no converging solution found") if logsteps: # If logstep is true, then log intermediate steps return a, error, steps return a, error if __name__ == "__main__": from matplotlib import pyplot as plt f = lambda x: m.tanh(x) ** 2 - m.exp(3 * x) # noqa: E731 solution, error, steps = newton_raphson( f, x0=10, maxiter=1000, step=1e-6, logsteps=True ) plt.plot([abs(f(x)) for x in steps]) plt.xlabel("step") plt.ylabel("error") plt.show() print(f"solution = {{{solution:f}}}, error = {{{error:f}}}")
-1
TheAlgorithms/Python
4,949
Fix typos in Sorts and Bit_manipulation
### **Describe your change:** * [x] Fixes the typos in the sorts and bit_manipulation folder * [x] Fixes the initially messed links in bit_manipulation/README.md ![Screenshot from 2021-10-03 13-57-36](https://user-images.githubusercontent.com/76519771/135746011-7acfad52-9ee5-412d-821d-8314adaf5ada.png) ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
Manan-Rathi
2021-10-03T08:24:44Z
2021-10-20T08:42:32Z
83cf5786cddd694a2af25827f8861b7dbcbf706c
50485f7c8e33b0a3bf6e603cdae3505d40b1d97a
Fix typos in Sorts and Bit_manipulation. ### **Describe your change:** * [x] Fixes the typos in the sorts and bit_manipulation folder * [x] Fixes the initially messed links in bit_manipulation/README.md ![Screenshot from 2021-10-03 13-57-36](https://user-images.githubusercontent.com/76519771/135746011-7acfad52-9ee5-412d-821d-8314adaf5ada.png) ### **Checklist:** * [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
def dencrypt(s: str, n: int = 13) -> str: """ https://en.wikipedia.org/wiki/ROT13 >>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!" >>> s = dencrypt(msg) >>> s "Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!" >>> dencrypt(s) == msg True """ out = "" for c in s: if "A" <= c <= "Z": out += chr(ord("A") + (ord(c) - ord("A") + n) % 26) elif "a" <= c <= "z": out += chr(ord("a") + (ord(c) - ord("a") + n) % 26) else: out += c return out def main() -> None: s0 = input("Enter message: ") s1 = dencrypt(s0, 13) print("Encryption:", s1) s2 = dencrypt(s1, 13) print("Decryption: ", s2) if __name__ == "__main__": import doctest doctest.testmod() main()
def dencrypt(s: str, n: int = 13) -> str: """ https://en.wikipedia.org/wiki/ROT13 >>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!" >>> s = dencrypt(msg) >>> s "Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!" >>> dencrypt(s) == msg True """ out = "" for c in s: if "A" <= c <= "Z": out += chr(ord("A") + (ord(c) - ord("A") + n) % 26) elif "a" <= c <= "z": out += chr(ord("a") + (ord(c) - ord("a") + n) % 26) else: out += c return out def main() -> None: s0 = input("Enter message: ") s1 = dencrypt(s0, 13) print("Encryption:", s1) s2 = dencrypt(s1, 13) print("Decryption: ", s2) if __name__ == "__main__": import doctest doctest.testmod() main()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Bead sort only works for sequences of nonegative integers. https://en.wikipedia.org/wiki/Bead_sort """ def bead_sort(sequence: list) -> list: """ >>> bead_sort([6, 11, 12, 4, 1, 5]) [1, 4, 5, 6, 11, 12] >>> bead_sort([9, 8, 7, 6, 5, 4 ,3, 2, 1]) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> bead_sort([5, 0, 4, 3]) [0, 3, 4, 5] >>> bead_sort([8, 2, 1]) [1, 2, 8] >>> bead_sort([1, .9, 0.0, 0, -1, -.9]) Traceback (most recent call last): ... TypeError: Sequence must be list of nonnegative integers >>> bead_sort("Hello world") Traceback (most recent call last): ... TypeError: Sequence must be list of nonnegative integers """ if any(not isinstance(x, int) or x < 0 for x in sequence): raise TypeError("Sequence must be list of nonnegative integers") for _ in range(len(sequence)): for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])): if rod_upper > rod_lower: sequence[i] -= rod_upper - rod_lower sequence[i + 1] += rod_upper - rod_lower return sequence if __name__ == "__main__": assert bead_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] assert bead_sort([7, 9, 4, 3, 5]) == [3, 4, 5, 7, 9]
""" Bead sort only works for sequences of non-negative integers. https://en.wikipedia.org/wiki/Bead_sort """ def bead_sort(sequence: list) -> list: """ >>> bead_sort([6, 11, 12, 4, 1, 5]) [1, 4, 5, 6, 11, 12] >>> bead_sort([9, 8, 7, 6, 5, 4 ,3, 2, 1]) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> bead_sort([5, 0, 4, 3]) [0, 3, 4, 5] >>> bead_sort([8, 2, 1]) [1, 2, 8] >>> bead_sort([1, .9, 0.0, 0, -1, -.9]) Traceback (most recent call last): ... TypeError: Sequence must be list of nonnegative integers >>> bead_sort("Hello world") Traceback (most recent call last): ... TypeError: Sequence must be list of nonnegative integers """ if any(not isinstance(x, int) or x < 0 for x in sequence): raise TypeError("Sequence must be list of nonnegative integers") for _ in range(len(sequence)): for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])): if rod_upper > rod_lower: sequence[i] -= rod_upper - rod_lower sequence[i + 1] += rod_upper - rod_lower return sequence if __name__ == "__main__": assert bead_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] assert bead_sort([7, 9, 4, 3, 5]) == [3, 4, 5, 7, 9]
1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Source: https://en.wikipedia.org/wiki/Odd%E2%80%93even_sort This is a non-parallelized implementation of odd-even transpostiion sort. Normally the swaps in each set happen simultaneously, without that the algorithm is no better than bubble sort. """ def odd_even_transposition(arr: list) -> list: """ >>> odd_even_transposition([5, 4, 3, 2, 1]) [1, 2, 3, 4, 5] >>> odd_even_transposition([13, 11, 18, 0, -1]) [-1, 0, 11, 13, 18] >>> odd_even_transposition([-.1, 1.1, .1, -2.9]) [-2.9, -0.1, 0.1, 1.1] """ arr_size = len(arr) for _ in range(arr_size): for i in range(_ % 2, arr_size - 1, 2): if arr[i + 1] < arr[i]: arr[i], arr[i + 1] = arr[i + 1], arr[i] return arr if __name__ == "__main__": arr = list(range(10, 0, -1)) print(f"Original: {arr}. Sorted: {odd_even_transposition(arr)}")
""" Source: https://en.wikipedia.org/wiki/Odd%E2%80%93even_sort This is a non-parallelized implementation of odd-even transposition sort. Normally the swaps in each set happen simultaneously, without that the algorithm is no better than bubble sort. """ def odd_even_transposition(arr: list) -> list: """ >>> odd_even_transposition([5, 4, 3, 2, 1]) [1, 2, 3, 4, 5] >>> odd_even_transposition([13, 11, 18, 0, -1]) [-1, 0, 11, 13, 18] >>> odd_even_transposition([-.1, 1.1, .1, -2.9]) [-2.9, -0.1, 0.1, 1.1] """ arr_size = len(arr) for _ in range(arr_size): for i in range(_ % 2, arr_size - 1, 2): if arr[i + 1] < arr[i]: arr[i], arr[i + 1] = arr[i + 1], arr[i] return arr if __name__ == "__main__": arr = list(range(10, 0, -1)) print(f"Original: {arr}. Sorted: {odd_even_transposition(arr)}")
1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
"""Topological Sort.""" # a # / \ # b c # / \ # d e edges = {"a": ["c", "b"], "b": ["d", "e"], "c": [], "d": [], "e": []} vertices = ["a", "b", "c", "d", "e"] def topological_sort(start, visited, sort): """Perform topolical sort on a directed acyclic graph.""" current = start # add current to visited visited.append(current) neighbors = edges[current] for neighbor in neighbors: # if neighbor not in visited, visit if neighbor not in visited: sort = topological_sort(neighbor, visited, sort) # if all neighbors visited add current to sort sort.append(current) # if all vertices haven't been visited select a new one to visit if len(visited) != len(vertices): for vertice in vertices: if vertice not in visited: sort = topological_sort(vertice, visited, sort) # return sort return sort if __name__ == "__main__": sort = topological_sort("a", [], []) print(sort)
"""Topological Sort.""" # a # / \ # b c # / \ # d e edges = {"a": ["c", "b"], "b": ["d", "e"], "c": [], "d": [], "e": []} vertices = ["a", "b", "c", "d", "e"] def topological_sort(start, visited, sort): """Perform topological sort on a directed acyclic graph.""" current = start # add current to visited visited.append(current) neighbors = edges[current] for neighbor in neighbors: # if neighbor not in visited, visit if neighbor not in visited: sort = topological_sort(neighbor, visited, sort) # if all neighbors visited add current to sort sort.append(current) # if all vertices haven't been visited select a new one to visit if len(visited) != len(vertices): for vertice in vertices: if vertice not in visited: sort = topological_sort(vertice, visited, sort) # return sort return sort if __name__ == "__main__": sort = topological_sort("a", [], []) print(sort)
1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" https://cp-algorithms.com/string/prefix-function.html Prefix function Knuth–Morris–Pratt algorithm Different algorithm than Knuth-Morris-Pratt pattern finding E.x. Finding longest prefix which is also suffix Time Complexity: O(n) - where n is the length of the string """ def prefix_function(input_string: str) -> list: """ For the given string this function computes value for each index(i), which represents the longest coincidence of prefix and sufix for given substring (input_str[0...i]) For the value of the first element the algorithm always returns 0 >>> prefix_function("aabcdaabc") [0, 1, 0, 0, 0, 1, 2, 3, 4] >>> prefix_function("asdasdad") [0, 0, 0, 1, 2, 3, 4, 0] """ # list for the result values prefix_result = [0] * len(input_string) for i in range(1, len(input_string)): # use last results for better performance - dynamic programming j = prefix_result[i - 1] while j > 0 and input_string[i] != input_string[j]: j = prefix_result[j - 1] if input_string[i] == input_string[j]: j += 1 prefix_result[i] = j return prefix_result def longest_prefix(input_str: str) -> int: """ Prefix-function use case Finding longest prefix which is sufix as well >>> longest_prefix("aabcdaabc") 4 >>> longest_prefix("asdasdad") 4 >>> longest_prefix("abcab") 2 """ # just returning maximum value of the array gives us answer return max(prefix_function(input_str)) if __name__ == "__main__": import doctest doctest.testmod()
""" https://cp-algorithms.com/string/prefix-function.html Prefix function Knuth–Morris–Pratt algorithm Different algorithm than Knuth-Morris-Pratt pattern finding E.x. Finding longest prefix which is also suffix Time Complexity: O(n) - where n is the length of the string """ def prefix_function(input_string: str) -> list: """ For the given string this function computes value for each index(i), which represents the longest coincidence of prefix and suffix for given substring (input_str[0...i]) For the value of the first element the algorithm always returns 0 >>> prefix_function("aabcdaabc") [0, 1, 0, 0, 0, 1, 2, 3, 4] >>> prefix_function("asdasdad") [0, 0, 0, 1, 2, 3, 4, 0] """ # list for the result values prefix_result = [0] * len(input_string) for i in range(1, len(input_string)): # use last results for better performance - dynamic programming j = prefix_result[i - 1] while j > 0 and input_string[i] != input_string[j]: j = prefix_result[j - 1] if input_string[i] == input_string[j]: j += 1 prefix_result[i] = j return prefix_result def longest_prefix(input_str: str) -> int: """ Prefix-function use case Finding longest prefix which is suffix as well >>> longest_prefix("aabcdaabc") 4 >>> longest_prefix("asdasdad") 4 >>> longest_prefix("abcab") 2 """ # just returning maximum value of the array gives us answer return max(prefix_function(input_str)) if __name__ == "__main__": import doctest doctest.testmod()
1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Pure Python implementations of a Fixed Priority Queue and an Element Priority Queue using Python lists. """ class OverFlowError(Exception): pass class UnderFlowError(Exception): pass class FixedPriorityQueue: """ Tasks can be added to a Priority Queue at any time and in any order but when Tasks are removed then the Task with the highest priority is removed in FIFO order. In code we will use three levels of priority with priority zero Tasks being the most urgent (high priority) and priority 2 tasks being the least urgent. Examples >>> fpq = FixedPriorityQueue() >>> fpq.enqueue(0, 10) >>> fpq.enqueue(1, 70) >>> fpq.enqueue(0, 100) >>> fpq.enqueue(2, 1) >>> fpq.enqueue(2, 5) >>> fpq.enqueue(1, 7) >>> fpq.enqueue(2, 4) >>> fpq.enqueue(1, 64) >>> fpq.enqueue(0, 128) >>> print(fpq) Priority 0: [10, 100, 128] Priority 1: [70, 7, 64] Priority 2: [1, 5, 4] >>> fpq.dequeue() 10 >>> fpq.dequeue() 100 >>> fpq.dequeue() 128 >>> fpq.dequeue() 70 >>> fpq.dequeue() 7 >>> print(fpq) Priority 0: [] Priority 1: [64] Priority 2: [1, 5, 4] >>> fpq.dequeue() 64 >>> fpq.dequeue() 1 >>> fpq.dequeue() 5 >>> fpq.dequeue() 4 >>> fpq.dequeue() Traceback (most recent call last): ... data_structures.queue.priority_queue_using_list.UnderFlowError: All queues are empty >>> print(fpq) Priority 0: [] Priority 1: [] Priority 2: [] """ def __init__(self): self.queues = [ [], [], [], ] def enqueue(self, priority: int, data: int) -> None: """ Add an element to a queue based on its priority. If the priority is invalid ValueError is raised. If the queue is full an OverFlowError is raised. """ try: if len(self.queues[priority]) >= 100: raise OverflowError("Maximum queue size is 100") self.queues[priority].append(data) except IndexError: raise ValueError("Valid priorities are 0, 1, and 2") def dequeue(self) -> int: """ Return the highest priority element in FIFO order. If the queue is empty then an under flow exception is raised. """ for queue in self.queues: if queue: return queue.pop(0) raise UnderFlowError("All queues are empty") def __str__(self) -> str: return "\n".join(f"Priority {i}: {q}" for i, q in enumerate(self.queues)) class ElementPriorityQueue: """ Element Priority Queue is the same as Fixed Priority Queue except that the value of the element itself is the priority. The rules for priorities are the same the as Fixed Priority Queue. >>> epq = ElementPriorityQueue() >>> epq.enqueue(10) >>> epq.enqueue(70) >>> epq.enqueue(4) >>> epq.enqueue(1) >>> epq.enqueue(5) >>> epq.enqueue(7) >>> epq.enqueue(4) >>> epq.enqueue(64) >>> epq.enqueue(128) >>> print(epq) [10, 70, 4, 1, 5, 7, 4, 64, 128] >>> epq.dequeue() 1 >>> epq.dequeue() 4 >>> epq.dequeue() 4 >>> epq.dequeue() 5 >>> epq.dequeue() 7 >>> epq.dequeue() 10 >>> print(epq) [70, 64, 128] >>> epq.dequeue() 64 >>> epq.dequeue() 70 >>> epq.dequeue() 128 >>> epq.dequeue() Traceback (most recent call last): ... data_structures.queue.priority_queue_using_list.UnderFlowError: The queue is empty >>> print(epq) [] """ def __init__(self): self.queue = [] def enqueue(self, data: int) -> None: """ This function enters the element into the queue If the queue is full an Exception is raised saying Over Flow! """ if len(self.queue) == 100: raise OverFlowError("Maximum queue size is 100") self.queue.append(data) def dequeue(self) -> int: """ Return the highest priority element in FIFO order. If the queue is empty then an under flow exception is raised. """ if not self.queue: raise UnderFlowError("The queue is empty") else: data = min(self.queue) self.queue.remove(data) return data def __str__(self) -> str: """ Prints all the elements within the Element Priority Queue """ return str(self.queue) def fixed_priority_queue(): fpq = FixedPriorityQueue() fpq.enqueue(0, 10) fpq.enqueue(1, 70) fpq.enqueue(0, 100) fpq.enqueue(2, 1) fpq.enqueue(2, 5) fpq.enqueue(1, 7) fpq.enqueue(2, 4) fpq.enqueue(1, 64) fpq.enqueue(0, 128) print(fpq) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) def element_priority_queue(): epq = ElementPriorityQueue() epq.enqueue(10) epq.enqueue(70) epq.enqueue(100) epq.enqueue(1) epq.enqueue(5) epq.enqueue(7) epq.enqueue(4) epq.enqueue(64) epq.enqueue(128) print(epq) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) if __name__ == "__main__": fixed_priority_queue() element_priority_queue()
""" Pure Python implementations of a Fixed Priority Queue and an Element Priority Queue using Python lists. """ class OverFlowError(Exception): pass class UnderFlowError(Exception): pass class FixedPriorityQueue: """ Tasks can be added to a Priority Queue at any time and in any order but when Tasks are removed then the Task with the highest priority is removed in FIFO order. In code we will use three levels of priority with priority zero Tasks being the most urgent (high priority) and priority 2 tasks being the least urgent. Examples >>> fpq = FixedPriorityQueue() >>> fpq.enqueue(0, 10) >>> fpq.enqueue(1, 70) >>> fpq.enqueue(0, 100) >>> fpq.enqueue(2, 1) >>> fpq.enqueue(2, 5) >>> fpq.enqueue(1, 7) >>> fpq.enqueue(2, 4) >>> fpq.enqueue(1, 64) >>> fpq.enqueue(0, 128) >>> print(fpq) Priority 0: [10, 100, 128] Priority 1: [70, 7, 64] Priority 2: [1, 5, 4] >>> fpq.dequeue() 10 >>> fpq.dequeue() 100 >>> fpq.dequeue() 128 >>> fpq.dequeue() 70 >>> fpq.dequeue() 7 >>> print(fpq) Priority 0: [] Priority 1: [64] Priority 2: [1, 5, 4] >>> fpq.dequeue() 64 >>> fpq.dequeue() 1 >>> fpq.dequeue() 5 >>> fpq.dequeue() 4 >>> fpq.dequeue() Traceback (most recent call last): ... data_structures.queue.priority_queue_using_list.UnderFlowError: All queues are empty >>> print(fpq) Priority 0: [] Priority 1: [] Priority 2: [] """ def __init__(self): self.queues = [ [], [], [], ] def enqueue(self, priority: int, data: int) -> None: """ Add an element to a queue based on its priority. If the priority is invalid ValueError is raised. If the queue is full an OverFlowError is raised. """ try: if len(self.queues[priority]) >= 100: raise OverflowError("Maximum queue size is 100") self.queues[priority].append(data) except IndexError: raise ValueError("Valid priorities are 0, 1, and 2") def dequeue(self) -> int: """ Return the highest priority element in FIFO order. If the queue is empty then an under flow exception is raised. """ for queue in self.queues: if queue: return queue.pop(0) raise UnderFlowError("All queues are empty") def __str__(self) -> str: return "\n".join(f"Priority {i}: {q}" for i, q in enumerate(self.queues)) class ElementPriorityQueue: """ Element Priority Queue is the same as Fixed Priority Queue except that the value of the element itself is the priority. The rules for priorities are the same the as Fixed Priority Queue. >>> epq = ElementPriorityQueue() >>> epq.enqueue(10) >>> epq.enqueue(70) >>> epq.enqueue(4) >>> epq.enqueue(1) >>> epq.enqueue(5) >>> epq.enqueue(7) >>> epq.enqueue(4) >>> epq.enqueue(64) >>> epq.enqueue(128) >>> print(epq) [10, 70, 4, 1, 5, 7, 4, 64, 128] >>> epq.dequeue() 1 >>> epq.dequeue() 4 >>> epq.dequeue() 4 >>> epq.dequeue() 5 >>> epq.dequeue() 7 >>> epq.dequeue() 10 >>> print(epq) [70, 64, 128] >>> epq.dequeue() 64 >>> epq.dequeue() 70 >>> epq.dequeue() 128 >>> epq.dequeue() Traceback (most recent call last): ... data_structures.queue.priority_queue_using_list.UnderFlowError: The queue is empty >>> print(epq) [] """ def __init__(self): self.queue = [] def enqueue(self, data: int) -> None: """ This function enters the element into the queue If the queue is full an Exception is raised saying Over Flow! """ if len(self.queue) == 100: raise OverFlowError("Maximum queue size is 100") self.queue.append(data) def dequeue(self) -> int: """ Return the highest priority element in FIFO order. If the queue is empty then an under flow exception is raised. """ if not self.queue: raise UnderFlowError("The queue is empty") else: data = min(self.queue) self.queue.remove(data) return data def __str__(self) -> str: """ Prints all the elements within the Element Priority Queue """ return str(self.queue) def fixed_priority_queue(): fpq = FixedPriorityQueue() fpq.enqueue(0, 10) fpq.enqueue(1, 70) fpq.enqueue(0, 100) fpq.enqueue(2, 1) fpq.enqueue(2, 5) fpq.enqueue(1, 7) fpq.enqueue(2, 4) fpq.enqueue(1, 64) fpq.enqueue(0, 128) print(fpq) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) print(fpq.dequeue()) def element_priority_queue(): epq = ElementPriorityQueue() epq.enqueue(10) epq.enqueue(70) epq.enqueue(100) epq.enqueue(1) epq.enqueue(5) epq.enqueue(7) epq.enqueue(4) epq.enqueue(64) epq.enqueue(128) print(epq) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) print(epq.dequeue()) if __name__ == "__main__": fixed_priority_queue() element_priority_queue()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
"""Convert a Decimal Number to an Octal Number.""" import math # Modified from: # https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/DecimalToOctal.js def decimal_to_octal(num: int) -> str: """Convert a Decimal Number to an Octal Number. >>> all(decimal_to_octal(i) == oct(i) for i ... in (0, 2, 8, 64, 65, 216, 255, 256, 512)) True """ octal = 0 counter = 0 while num > 0: remainder = num % 8 octal = octal + (remainder * math.floor(math.pow(10, counter))) counter += 1 num = math.floor(num / 8) # basically /= 8 without remainder if any # This formatting removes trailing '.0' from `octal`. return f"0o{int(octal)}" def main() -> None: """Print octal equivalents of decimal numbers.""" print("\n2 in octal is:") print(decimal_to_octal(2)) # = 2 print("\n8 in octal is:") print(decimal_to_octal(8)) # = 10 print("\n65 in octal is:") print(decimal_to_octal(65)) # = 101 print("\n216 in octal is:") print(decimal_to_octal(216)) # = 330 print("\n512 in octal is:") print(decimal_to_octal(512)) # = 1000 print("\n") if __name__ == "__main__": main()
"""Convert a Decimal Number to an Octal Number.""" import math # Modified from: # https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/DecimalToOctal.js def decimal_to_octal(num: int) -> str: """Convert a Decimal Number to an Octal Number. >>> all(decimal_to_octal(i) == oct(i) for i ... in (0, 2, 8, 64, 65, 216, 255, 256, 512)) True """ octal = 0 counter = 0 while num > 0: remainder = num % 8 octal = octal + (remainder * math.floor(math.pow(10, counter))) counter += 1 num = math.floor(num / 8) # basically /= 8 without remainder if any # This formatting removes trailing '.0' from `octal`. return f"0o{int(octal)}" def main() -> None: """Print octal equivalents of decimal numbers.""" print("\n2 in octal is:") print(decimal_to_octal(2)) # = 2 print("\n8 in octal is:") print(decimal_to_octal(8)) # = 10 print("\n65 in octal is:") print(decimal_to_octal(65)) # = 101 print("\n216 in octal is:") print(decimal_to_octal(216)) # = 330 print("\n512 in octal is:") print(decimal_to_octal(512)) # = 1000 print("\n") if __name__ == "__main__": main()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
class Matrix: """ <class Matrix> Matrix structure. """ def __init__(self, row: int, column: int, default_value: float = 0): """ <method Matrix.__init__> Initialize matrix with given size and default value. Example: >>> a = Matrix(2, 3, 1) >>> a Matrix consist of 2 rows and 3 columns [1, 1, 1] [1, 1, 1] """ self.row, self.column = row, column self.array = [[default_value for c in range(column)] for r in range(row)] def __str__(self): """ <method Matrix.__str__> Return string representation of this matrix. """ # Prefix s = "Matrix consist of %d rows and %d columns\n" % (self.row, self.column) # Make string identifier max_element_length = 0 for row_vector in self.array: for obj in row_vector: max_element_length = max(max_element_length, len(str(obj))) string_format_identifier = "%%%ds" % (max_element_length,) # Make string and return def single_line(row_vector): nonlocal string_format_identifier line = "[" line += ", ".join(string_format_identifier % (obj,) for obj in row_vector) line += "]" return line s += "\n".join(single_line(row_vector) for row_vector in self.array) return s def __repr__(self): return str(self) def validateIndices(self, loc: tuple): """ <method Matrix.validateIndices> Check if given indices are valid to pick element from matrix. Example: >>> a = Matrix(2, 6, 0) >>> a.validateIndices((2, 7)) False >>> a.validateIndices((0, 0)) True """ if not (isinstance(loc, (list, tuple)) and len(loc) == 2): return False elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column): return False else: return True def __getitem__(self, loc: tuple): """ <method Matrix.__getitem__> Return array[row][column] where loc = (row, column). Example: >>> a = Matrix(3, 2, 7) >>> a[1, 0] 7 """ assert self.validateIndices(loc) return self.array[loc[0]][loc[1]] def __setitem__(self, loc: tuple, value: float): """ <method Matrix.__setitem__> Set array[row][column] = value where loc = (row, column). Example: >>> a = Matrix(2, 3, 1) >>> a[1, 2] = 51 >>> a Matrix consist of 2 rows and 3 columns [ 1, 1, 1] [ 1, 1, 51] """ assert self.validateIndices(loc) self.array[loc[0]][loc[1]] = value def __add__(self, another): """ <method Matrix.__add__> Return self + another. Example: >>> a = Matrix(2, 1, -4) >>> b = Matrix(2, 1, 3) >>> a+b Matrix consist of 2 rows and 1 columns [-1] [-1] """ # Validation assert isinstance(another, Matrix) assert self.row == another.row and self.column == another.column # Add result = Matrix(self.row, self.column) for r in range(self.row): for c in range(self.column): result[r, c] = self[r, c] + another[r, c] return result def __neg__(self): """ <method Matrix.__neg__> Return -self. Example: >>> a = Matrix(2, 2, 3) >>> a[0, 1] = a[1, 0] = -2 >>> -a Matrix consist of 2 rows and 2 columns [-3, 2] [ 2, -3] """ result = Matrix(self.row, self.column) for r in range(self.row): for c in range(self.column): result[r, c] = -self[r, c] return result def __sub__(self, another): return self + (-another) def __mul__(self, another): """ <method Matrix.__mul__> Return self * another. Example: >>> a = Matrix(2, 3, 1) >>> a[0,2] = a[1,2] = 3 >>> a * -2 Matrix consist of 2 rows and 3 columns [-2, -2, -6] [-2, -2, -6] """ if isinstance(another, (int, float)): # Scalar multiplication result = Matrix(self.row, self.column) for r in range(self.row): for c in range(self.column): result[r, c] = self[r, c] * another return result elif isinstance(another, Matrix): # Matrix multiplication assert self.column == another.row result = Matrix(self.row, another.column) for r in range(self.row): for c in range(another.column): for i in range(self.column): result[r, c] += self[r, i] * another[i, c] return result else: raise TypeError(f"Unsupported type given for another ({type(another)})") def transpose(self): """ <method Matrix.transpose> Return self^T. Example: >>> a = Matrix(2, 3) >>> for r in range(2): ... for c in range(3): ... a[r,c] = r*c ... >>> a.transpose() Matrix consist of 3 rows and 2 columns [0, 0] [0, 1] [0, 2] """ result = Matrix(self.column, self.row) for r in range(self.row): for c in range(self.column): result[c, r] = self[r, c] return result def ShermanMorrison(self, u, v): """ <method Matrix.ShermanMorrison> Apply Sherman-Morrison formula in O(n^2). To learn this formula, please look this: https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula This method returns (A + uv^T)^(-1) where A^(-1) is self. Returns None if it's impossible to calculate. Warning: This method doesn't check if self is invertible. Make sure self is invertible before execute this method. Example: >>> ainv = Matrix(3, 3, 0) >>> for i in range(3): ainv[i,i] = 1 ... >>> u = Matrix(3, 1, 0) >>> u[0,0], u[1,0], u[2,0] = 1, 2, -3 >>> v = Matrix(3, 1, 0) >>> v[0,0], v[1,0], v[2,0] = 4, -2, 5 >>> ainv.ShermanMorrison(u, v) Matrix consist of 3 rows and 3 columns [ 1.2857142857142856, -0.14285714285714285, 0.3571428571428571] [ 0.5714285714285714, 0.7142857142857143, 0.7142857142857142] [ -0.8571428571428571, 0.42857142857142855, -0.0714285714285714] """ # Size validation assert isinstance(u, Matrix) and isinstance(v, Matrix) assert self.row == self.column == u.row == v.row # u, v should be column vector assert u.column == v.column == 1 # u, v should be column vector # Calculate vT = v.transpose() numerator_factor = (vT * self * u)[0, 0] + 1 if numerator_factor == 0: return None # It's not invertable return self - ((self * u) * (vT * self) * (1.0 / numerator_factor)) # Testing if __name__ == "__main__": def test1(): # a^(-1) ainv = Matrix(3, 3, 0) for i in range(3): ainv[i, i] = 1 print(f"a^(-1) is {ainv}") # u, v u = Matrix(3, 1, 0) u[0, 0], u[1, 0], u[2, 0] = 1, 2, -3 v = Matrix(3, 1, 0) v[0, 0], v[1, 0], v[2, 0] = 4, -2, 5 print(f"u is {u}") print(f"v is {v}") print("uv^T is %s" % (u * v.transpose())) # Sherman Morrison print(f"(a + uv^T)^(-1) is {ainv.ShermanMorrison(u, v)}") def test2(): import doctest doctest.testmod() test2()
class Matrix: """ <class Matrix> Matrix structure. """ def __init__(self, row: int, column: int, default_value: float = 0): """ <method Matrix.__init__> Initialize matrix with given size and default value. Example: >>> a = Matrix(2, 3, 1) >>> a Matrix consist of 2 rows and 3 columns [1, 1, 1] [1, 1, 1] """ self.row, self.column = row, column self.array = [[default_value for c in range(column)] for r in range(row)] def __str__(self): """ <method Matrix.__str__> Return string representation of this matrix. """ # Prefix s = "Matrix consist of %d rows and %d columns\n" % (self.row, self.column) # Make string identifier max_element_length = 0 for row_vector in self.array: for obj in row_vector: max_element_length = max(max_element_length, len(str(obj))) string_format_identifier = "%%%ds" % (max_element_length,) # Make string and return def single_line(row_vector): nonlocal string_format_identifier line = "[" line += ", ".join(string_format_identifier % (obj,) for obj in row_vector) line += "]" return line s += "\n".join(single_line(row_vector) for row_vector in self.array) return s def __repr__(self): return str(self) def validateIndices(self, loc: tuple): """ <method Matrix.validateIndices> Check if given indices are valid to pick element from matrix. Example: >>> a = Matrix(2, 6, 0) >>> a.validateIndices((2, 7)) False >>> a.validateIndices((0, 0)) True """ if not (isinstance(loc, (list, tuple)) and len(loc) == 2): return False elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column): return False else: return True def __getitem__(self, loc: tuple): """ <method Matrix.__getitem__> Return array[row][column] where loc = (row, column). Example: >>> a = Matrix(3, 2, 7) >>> a[1, 0] 7 """ assert self.validateIndices(loc) return self.array[loc[0]][loc[1]] def __setitem__(self, loc: tuple, value: float): """ <method Matrix.__setitem__> Set array[row][column] = value where loc = (row, column). Example: >>> a = Matrix(2, 3, 1) >>> a[1, 2] = 51 >>> a Matrix consist of 2 rows and 3 columns [ 1, 1, 1] [ 1, 1, 51] """ assert self.validateIndices(loc) self.array[loc[0]][loc[1]] = value def __add__(self, another): """ <method Matrix.__add__> Return self + another. Example: >>> a = Matrix(2, 1, -4) >>> b = Matrix(2, 1, 3) >>> a+b Matrix consist of 2 rows and 1 columns [-1] [-1] """ # Validation assert isinstance(another, Matrix) assert self.row == another.row and self.column == another.column # Add result = Matrix(self.row, self.column) for r in range(self.row): for c in range(self.column): result[r, c] = self[r, c] + another[r, c] return result def __neg__(self): """ <method Matrix.__neg__> Return -self. Example: >>> a = Matrix(2, 2, 3) >>> a[0, 1] = a[1, 0] = -2 >>> -a Matrix consist of 2 rows and 2 columns [-3, 2] [ 2, -3] """ result = Matrix(self.row, self.column) for r in range(self.row): for c in range(self.column): result[r, c] = -self[r, c] return result def __sub__(self, another): return self + (-another) def __mul__(self, another): """ <method Matrix.__mul__> Return self * another. Example: >>> a = Matrix(2, 3, 1) >>> a[0,2] = a[1,2] = 3 >>> a * -2 Matrix consist of 2 rows and 3 columns [-2, -2, -6] [-2, -2, -6] """ if isinstance(another, (int, float)): # Scalar multiplication result = Matrix(self.row, self.column) for r in range(self.row): for c in range(self.column): result[r, c] = self[r, c] * another return result elif isinstance(another, Matrix): # Matrix multiplication assert self.column == another.row result = Matrix(self.row, another.column) for r in range(self.row): for c in range(another.column): for i in range(self.column): result[r, c] += self[r, i] * another[i, c] return result else: raise TypeError(f"Unsupported type given for another ({type(another)})") def transpose(self): """ <method Matrix.transpose> Return self^T. Example: >>> a = Matrix(2, 3) >>> for r in range(2): ... for c in range(3): ... a[r,c] = r*c ... >>> a.transpose() Matrix consist of 3 rows and 2 columns [0, 0] [0, 1] [0, 2] """ result = Matrix(self.column, self.row) for r in range(self.row): for c in range(self.column): result[c, r] = self[r, c] return result def ShermanMorrison(self, u, v): """ <method Matrix.ShermanMorrison> Apply Sherman-Morrison formula in O(n^2). To learn this formula, please look this: https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula This method returns (A + uv^T)^(-1) where A^(-1) is self. Returns None if it's impossible to calculate. Warning: This method doesn't check if self is invertible. Make sure self is invertible before execute this method. Example: >>> ainv = Matrix(3, 3, 0) >>> for i in range(3): ainv[i,i] = 1 ... >>> u = Matrix(3, 1, 0) >>> u[0,0], u[1,0], u[2,0] = 1, 2, -3 >>> v = Matrix(3, 1, 0) >>> v[0,0], v[1,0], v[2,0] = 4, -2, 5 >>> ainv.ShermanMorrison(u, v) Matrix consist of 3 rows and 3 columns [ 1.2857142857142856, -0.14285714285714285, 0.3571428571428571] [ 0.5714285714285714, 0.7142857142857143, 0.7142857142857142] [ -0.8571428571428571, 0.42857142857142855, -0.0714285714285714] """ # Size validation assert isinstance(u, Matrix) and isinstance(v, Matrix) assert self.row == self.column == u.row == v.row # u, v should be column vector assert u.column == v.column == 1 # u, v should be column vector # Calculate vT = v.transpose() numerator_factor = (vT * self * u)[0, 0] + 1 if numerator_factor == 0: return None # It's not invertable return self - ((self * u) * (vT * self) * (1.0 / numerator_factor)) # Testing if __name__ == "__main__": def test1(): # a^(-1) ainv = Matrix(3, 3, 0) for i in range(3): ainv[i, i] = 1 print(f"a^(-1) is {ainv}") # u, v u = Matrix(3, 1, 0) u[0, 0], u[1, 0], u[2, 0] = 1, 2, -3 v = Matrix(3, 1, 0) v[0, 0], v[1, 0], v[2, 0] = 4, -2, 5 print(f"u is {u}") print(f"v is {v}") print("uv^T is %s" % (u * v.transpose())) # Sherman Morrison print(f"(a + uv^T)^(-1) is {ainv.ShermanMorrison(u, v)}") def test2(): import doctest doctest.testmod() test2()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from collections import deque def tarjan(g): """ Tarjan's algo for finding strongly connected components in a directed graph Uses two main attributes of each node to track reachability, the index of that node within a component(index), and the lowest index reachable from that node(lowlink). We then perform a dfs of the each component making sure to update these parameters for each node and saving the nodes we visit on the way. If ever we find that the lowest reachable node from a current node is equal to the index of the current node then it must be the root of a strongly connected component and so we save it and it's equireachable vertices as a strongly connected component. Complexity: strong_connect() is called at most once for each node and has a complexity of O(|E|) as it is DFS. Therefore this has complexity O(|V| + |E|) for a graph G = (V, E) """ n = len(g) stack = deque() on_stack = [False for _ in range(n)] index_of = [-1 for _ in range(n)] lowlink_of = index_of[:] def strong_connect(v, index, components): index_of[v] = index # the number when this node is seen lowlink_of[v] = index # lowest rank node reachable from here index += 1 stack.append(v) on_stack[v] = True for w in g[v]: if index_of[w] == -1: index = strong_connect(w, index, components) lowlink_of[v] = ( lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v] ) elif on_stack[w]: lowlink_of[v] = ( lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v] ) if lowlink_of[v] == index_of[v]: component = [] w = stack.pop() on_stack[w] = False component.append(w) while w != v: w = stack.pop() on_stack[w] = False component.append(w) components.append(component) return index components = [] for v in range(n): if index_of[v] == -1: strong_connect(v, 0, components) return components def create_graph(n, edges): g = [[] for _ in range(n)] for u, v in edges: g[u].append(v) return g if __name__ == "__main__": # Test n_vertices = 7 source = [0, 0, 1, 2, 3, 3, 4, 4, 6] target = [1, 3, 2, 0, 1, 4, 5, 6, 5] edges = [(u, v) for u, v in zip(source, target)] g = create_graph(n_vertices, edges) assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)
from collections import deque def tarjan(g): """ Tarjan's algo for finding strongly connected components in a directed graph Uses two main attributes of each node to track reachability, the index of that node within a component(index), and the lowest index reachable from that node(lowlink). We then perform a dfs of the each component making sure to update these parameters for each node and saving the nodes we visit on the way. If ever we find that the lowest reachable node from a current node is equal to the index of the current node then it must be the root of a strongly connected component and so we save it and it's equireachable vertices as a strongly connected component. Complexity: strong_connect() is called at most once for each node and has a complexity of O(|E|) as it is DFS. Therefore this has complexity O(|V| + |E|) for a graph G = (V, E) """ n = len(g) stack = deque() on_stack = [False for _ in range(n)] index_of = [-1 for _ in range(n)] lowlink_of = index_of[:] def strong_connect(v, index, components): index_of[v] = index # the number when this node is seen lowlink_of[v] = index # lowest rank node reachable from here index += 1 stack.append(v) on_stack[v] = True for w in g[v]: if index_of[w] == -1: index = strong_connect(w, index, components) lowlink_of[v] = ( lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v] ) elif on_stack[w]: lowlink_of[v] = ( lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v] ) if lowlink_of[v] == index_of[v]: component = [] w = stack.pop() on_stack[w] = False component.append(w) while w != v: w = stack.pop() on_stack[w] = False component.append(w) components.append(component) return index components = [] for v in range(n): if index_of[v] == -1: strong_connect(v, 0, components) return components def create_graph(n, edges): g = [[] for _ in range(n)] for u, v in edges: g[u].append(v) return g if __name__ == "__main__": # Test n_vertices = 7 source = [0, 0, 1, 2, 3, 3, 4, 4, 6] target = [1, 3, 2, 0, 1, 4, 5, 6, 5] edges = [(u, v) for u, v in zip(source, target)] g = create_graph(n_vertices, edges) assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
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 Cryptography(CRC Press, ISBN : 0-8493-8523-7, October 1996) # and it seems to run nicely! def primitive_root(p_val: int) -> int: print("Generating primitive root of p") while True: g = random.randrange(3, p_val) if pow(g, 2, p_val) == 1: continue if pow(g, p_val, p_val) == 1: continue return g def generate_key(key_size: int) -> tuple[tuple[int, int, int, int], tuple[int, int]]: print("Generating prime p...") p = rabin_miller.generateLargePrime(key_size) # select large prime number. e_1 = primitive_root(p) # one primitive root on modulo p. d = random.randrange(3, p) # private_key -> have to be greater than 2 for safety. e_2 = cryptomath.find_mod_inverse(pow(e_1, d, p), p) public_key = (key_size, e_1, e_2, p) private_key = (key_size, d) return public_key, private_key def make_key_files(name: str, keySize: int) -> None: if os.path.exists("%s_pubkey.txt" % name) or os.path.exists( "%s_privkey.txt" % name ): print("\nWARNING:") print( '"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n' "Use a different name or delete these files and re-run this program." % (name, name) ) sys.exit() publicKey, privateKey = generate_key(keySize) print("\nWriting public key to file %s_pubkey.txt..." % name) with open("%s_pubkey.txt" % name, "w") as fo: fo.write( "%d,%d,%d,%d" % (publicKey[0], publicKey[1], publicKey[2], publicKey[3]) ) print("Writing private key to file %s_privkey.txt..." % name) with open("%s_privkey.txt" % name, "w") as fo: fo.write("%d,%d" % (privateKey[0], privateKey[1])) def main() -> None: print("Making key files...") make_key_files("elgamal", 2048) print("Key files generation successful") if __name__ == "__main__": main()
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 Cryptography(CRC Press, ISBN : 0-8493-8523-7, October 1996) # and it seems to run nicely! def primitive_root(p_val: int) -> int: print("Generating primitive root of p") while True: g = random.randrange(3, p_val) if pow(g, 2, p_val) == 1: continue if pow(g, p_val, p_val) == 1: continue return g def generate_key(key_size: int) -> tuple[tuple[int, int, int, int], tuple[int, int]]: print("Generating prime p...") p = rabin_miller.generateLargePrime(key_size) # select large prime number. e_1 = primitive_root(p) # one primitive root on modulo p. d = random.randrange(3, p) # private_key -> have to be greater than 2 for safety. e_2 = cryptomath.find_mod_inverse(pow(e_1, d, p), p) public_key = (key_size, e_1, e_2, p) private_key = (key_size, d) return public_key, private_key def make_key_files(name: str, keySize: int) -> None: if os.path.exists("%s_pubkey.txt" % name) or os.path.exists( "%s_privkey.txt" % name ): print("\nWARNING:") print( '"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n' "Use a different name or delete these files and re-run this program." % (name, name) ) sys.exit() publicKey, privateKey = generate_key(keySize) print("\nWriting public key to file %s_pubkey.txt..." % name) with open("%s_pubkey.txt" % name, "w") as fo: fo.write( "%d,%d,%d,%d" % (publicKey[0], publicKey[1], publicKey[2], publicKey[3]) ) print("Writing private key to file %s_privkey.txt..." % name) with open("%s_privkey.txt" % name, "w") as fo: fo.write("%d,%d" % (privateKey[0], privateKey[1])) def main() -> None: print("Making key files...") make_key_files("elgamal", 2048) print("Key files generation successful") if __name__ == "__main__": main()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
# Check whether Graph is Bipartite or Not using BFS # 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, # or u belongs to V and v to U. We can also say that there is no edge that connects # vertices of same set. def checkBipartite(graph): queue = [] visited = [False] * len(graph) color = [-1] * len(graph) def bfs(): while queue: u = queue.pop(0) visited[u] = True for neighbour in graph[u]: if neighbour == u: return False if color[neighbour] == -1: color[neighbour] = 1 - color[u] queue.append(neighbour) elif color[neighbour] == color[u]: return False return True for i in range(len(graph)): if not visited[i]: queue.append(i) color[i] = 0 if bfs() is False: return False return True if __name__ == "__main__": # Adjacency List of graph print(checkBipartite({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2]}))
# Check whether Graph is Bipartite or Not using BFS # 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, # or u belongs to V and v to U. We can also say that there is no edge that connects # vertices of same set. def checkBipartite(graph): queue = [] visited = [False] * len(graph) color = [-1] * len(graph) def bfs(): while queue: u = queue.pop(0) visited[u] = True for neighbour in graph[u]: if neighbour == u: return False if color[neighbour] == -1: color[neighbour] = 1 - color[u] queue.append(neighbour) elif color[neighbour] == color[u]: return False return True for i in range(len(graph)): if not visited[i]: queue.append(i) color[i] = 0 if bfs() is False: return False return True if __name__ == "__main__": # Adjacency List of graph print(checkBipartite({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2]}))
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
"""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, m, t # Choosing Dynamical Systems (All) for key, value in enumerate(buffer_space): # Evolution Parameter e = float(seed / value) # Control Theory: Orbit Change value = (buffer_space[(key + 1) % m] + e) % 1 # Control Theory: Trajectory Change r = (params_space[key] + e) % 1 + 3 # Modification (Transition Function) - Jumps buffer_space[key] = round(float(r * value * (1 - value)), 10) params_space[key] = r # Saving to Parameters Space # Logistic Map assert max(buffer_space) < 1 assert max(params_space) < 4 # Machine Time machine_time += 1 def pull(): global buffer_space, params_space, machine_time, K, m, t # PRNG (Xorshift by George Marsaglia) def xorshift(X, Y): X ^= Y >> 13 Y ^= X << 17 X ^= Y >> 5 return X # Choosing Dynamical Systems (Increment) key = machine_time % m # Evolution (Time Length) for i in range(0, t): # Variables (Position + Parameters) r = params_space[key] value = buffer_space[key] # Modification (Transition Function) - Flow buffer_space[key] = round(float(r * value * (1 - value)), 10) params_space[key] = (machine_time * 0.01 + r * 1.01) % 1 + 3 # Choosing Chaotic Data X = int(buffer_space[(key + 2) % m] * (10 ** 10)) Y = int(buffer_space[(key - 2) % m] * (10 ** 10)) # Machine Time machine_time += 1 return xorshift(X, Y) % 0xFFFFFFFF def reset(): global buffer_space, params_space, machine_time, K, m, t buffer_space = K params_space = [0] * m machine_time = 0 if __name__ == "__main__": # Initialization reset() # Pushing Data (Input) import random message = random.sample(range(0xFFFFFFFF), 100) for chunk in message: push(chunk) # for controlling inp = "" # Pulling Data (Output) while inp in ("e", "E"): print("%s" % format(pull(), "#04x")) print(buffer_space) print(params_space) inp = input("(e)exit? ").strip()
"""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, m, t # Choosing Dynamical Systems (All) for key, value in enumerate(buffer_space): # Evolution Parameter e = float(seed / value) # Control Theory: Orbit Change value = (buffer_space[(key + 1) % m] + e) % 1 # Control Theory: Trajectory Change r = (params_space[key] + e) % 1 + 3 # Modification (Transition Function) - Jumps buffer_space[key] = round(float(r * value * (1 - value)), 10) params_space[key] = r # Saving to Parameters Space # Logistic Map assert max(buffer_space) < 1 assert max(params_space) < 4 # Machine Time machine_time += 1 def pull(): global buffer_space, params_space, machine_time, K, m, t # PRNG (Xorshift by George Marsaglia) def xorshift(X, Y): X ^= Y >> 13 Y ^= X << 17 X ^= Y >> 5 return X # Choosing Dynamical Systems (Increment) key = machine_time % m # Evolution (Time Length) for i in range(0, t): # Variables (Position + Parameters) r = params_space[key] value = buffer_space[key] # Modification (Transition Function) - Flow buffer_space[key] = round(float(r * value * (1 - value)), 10) params_space[key] = (machine_time * 0.01 + r * 1.01) % 1 + 3 # Choosing Chaotic Data X = int(buffer_space[(key + 2) % m] * (10 ** 10)) Y = int(buffer_space[(key - 2) % m] * (10 ** 10)) # Machine Time machine_time += 1 return xorshift(X, Y) % 0xFFFFFFFF def reset(): global buffer_space, params_space, machine_time, K, m, t buffer_space = K params_space = [0] * m machine_time = 0 if __name__ == "__main__": # Initialization reset() # Pushing Data (Input) import random message = random.sample(range(0xFFFFFFFF), 100) for chunk in message: push(chunk) # for controlling inp = "" # Pulling Data (Output) while inp in ("e", "E"): print("%s" % format(pull(), "#04x")) print(buffer_space) print(params_space) inp = input("(e)exit? ").strip()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
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(self): return self.name def get_weight(self): return self.weight def value_Weight(self): return self.value / self.weight def build_menu(name, value, weight): menu = [] for i in range(len(value)): menu.append(things(name[i], value[i], weight[i])) return menu def greedy(item, maxCost, keyFunc): itemsCopy = sorted(item, key=keyFunc, reverse=True) result = [] totalValue, total_cost = 0.0, 0.0 for i in range(len(itemsCopy)): if (total_cost + itemsCopy[i].get_weight()) <= maxCost: result.append(itemsCopy[i]) total_cost += itemsCopy[i].get_weight() totalValue += itemsCopy[i].get_value() return (result, totalValue) def test_greedy(): """ >>> food = ["Burger", "Pizza", "Coca Cola", "Rice", ... "Sambhar", "Chicken", "Fries", "Milk"] >>> value = [80, 100, 60, 70, 50, 110, 90, 60] >>> weight = [40, 60, 40, 70, 100, 85, 55, 70] >>> foods = build_menu(food, value, weight) >>> foods # doctest: +NORMALIZE_WHITESPACE [things(Burger, 80, 40), things(Pizza, 100, 60), things(Coca Cola, 60, 40), things(Rice, 70, 70), things(Sambhar, 50, 100), things(Chicken, 110, 85), things(Fries, 90, 55), things(Milk, 60, 70)] >>> greedy(foods, 500, things.get_value) # doctest: +NORMALIZE_WHITESPACE ([things(Chicken, 110, 85), things(Pizza, 100, 60), things(Fries, 90, 55), things(Burger, 80, 40), things(Rice, 70, 70), things(Coca Cola, 60, 40), things(Milk, 60, 70)], 570.0) """ if __name__ == "__main__": import doctest doctest.testmod()
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(self): return self.name def get_weight(self): return self.weight def value_Weight(self): return self.value / self.weight def build_menu(name, value, weight): menu = [] for i in range(len(value)): menu.append(things(name[i], value[i], weight[i])) return menu def greedy(item, maxCost, keyFunc): itemsCopy = sorted(item, key=keyFunc, reverse=True) result = [] totalValue, total_cost = 0.0, 0.0 for i in range(len(itemsCopy)): if (total_cost + itemsCopy[i].get_weight()) <= maxCost: result.append(itemsCopy[i]) total_cost += itemsCopy[i].get_weight() totalValue += itemsCopy[i].get_value() return (result, totalValue) def test_greedy(): """ >>> food = ["Burger", "Pizza", "Coca Cola", "Rice", ... "Sambhar", "Chicken", "Fries", "Milk"] >>> value = [80, 100, 60, 70, 50, 110, 90, 60] >>> weight = [40, 60, 40, 70, 100, 85, 55, 70] >>> foods = build_menu(food, value, weight) >>> foods # doctest: +NORMALIZE_WHITESPACE [things(Burger, 80, 40), things(Pizza, 100, 60), things(Coca Cola, 60, 40), things(Rice, 70, 70), things(Sambhar, 50, 100), things(Chicken, 110, 85), things(Fries, 90, 55), things(Milk, 60, 70)] >>> greedy(foods, 500, things.get_value) # doctest: +NORMALIZE_WHITESPACE ([things(Chicken, 110, 85), things(Pizza, 100, 60), things(Fries, 90, 55), things(Burger, 80, 40), things(Rice, 70, 70), things(Coca Cola, 60, 40), things(Milk, 60, 70)], 570.0) """ if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
END = "#" class Trie: def __init__(self): self._trie = {} def insert_word(self, text): trie = self._trie for char in text: if char not in trie: trie[char] = {} trie = trie[char] trie[END] = True def find_word(self, prefix): trie = self._trie for char in prefix: if char in trie: trie = trie[char] else: return [] return self._elements(trie) def _elements(self, d): result = [] for c, v in d.items(): if c == END: sub_result = [" "] else: sub_result = [c + s for s in self._elements(v)] result.extend(sub_result) return tuple(result) trie = Trie() words = ("depart", "detergent", "daring", "dog", "deer", "deal") for word in words: trie.insert_word(word) def autocomplete_using_trie(s): """ >>> trie = Trie() >>> for word in words: ... trie.insert_word(word) ... >>> matches = autocomplete_using_trie("de") "detergent " in matches True "dog " in matches False """ suffixes = trie.find_word(s) return tuple(s + w for w in suffixes) def main(): print(autocomplete_using_trie("de")) if __name__ == "__main__": main()
END = "#" class Trie: def __init__(self): self._trie = {} def insert_word(self, text): trie = self._trie for char in text: if char not in trie: trie[char] = {} trie = trie[char] trie[END] = True def find_word(self, prefix): trie = self._trie for char in prefix: if char in trie: trie = trie[char] else: return [] return self._elements(trie) def _elements(self, d): result = [] for c, v in d.items(): if c == END: sub_result = [" "] else: sub_result = [c + s for s in self._elements(v)] result.extend(sub_result) return tuple(result) trie = Trie() words = ("depart", "detergent", "daring", "dog", "deer", "deal") for word in words: trie.insert_word(word) def autocomplete_using_trie(s): """ >>> trie = Trie() >>> for word in words: ... trie.insert_word(word) ... >>> matches = autocomplete_using_trie("de") "detergent " in matches True "dog " in matches False """ suffixes = trie.find_word(s) return tuple(s + w for w in suffixes) def main(): print(autocomplete_using_trie("de")) if __name__ == "__main__": main()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
import argparse import datetime def zeller(date_input: str) -> str: """ Zellers Congruence Algorithm Find the day of the week for nearly any Gregorian or Julian calendar date >>> zeller('01-31-2010') 'Your date 01-31-2010, is a Sunday!' Validate out of range month >>> zeller('13-31-2010') Traceback (most recent call last): ... ValueError: Month must be between 1 - 12 >>> zeller('.2-31-2010') Traceback (most recent call last): ... ValueError: invalid literal for int() with base 10: '.2' Validate out of range date: >>> zeller('01-33-2010') Traceback (most recent call last): ... ValueError: Date must be between 1 - 31 >>> zeller('01-.4-2010') Traceback (most recent call last): ... ValueError: invalid literal for int() with base 10: '.4' Validate second separator: >>> zeller('01-31*2010') Traceback (most recent call last): ... ValueError: Date separator must be '-' or '/' Validate first separator: >>> zeller('01^31-2010') Traceback (most recent call last): ... ValueError: Date separator must be '-' or '/' Validate out of range year: >>> zeller('01-31-8999') Traceback (most recent call last): ... ValueError: Year out of range. There has to be some sort of limit...right? Test null input: >>> zeller() Traceback (most recent call last): ... TypeError: zeller() missing 1 required positional argument: 'date_input' Test length of date_input: >>> zeller('') Traceback (most recent call last): ... ValueError: Must be 10 characters long >>> zeller('01-31-19082939') Traceback (most recent call last): ... ValueError: Must be 10 characters long""" # Days of the week for response days = { "0": "Sunday", "1": "Monday", "2": "Tuesday", "3": "Wednesday", "4": "Thursday", "5": "Friday", "6": "Saturday", } convert_datetime_days = {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 0} # Validate if not 0 < len(date_input) < 11: raise ValueError("Must be 10 characters long") # Get month m: int = int(date_input[0] + date_input[1]) # Validate if not 0 < m < 13: raise ValueError("Month must be between 1 - 12") sep_1: str = date_input[2] # Validate if sep_1 not in ["-", "/"]: raise ValueError("Date separator must be '-' or '/'") # Get day d: int = int(date_input[3] + date_input[4]) # Validate if not 0 < d < 32: raise ValueError("Date must be between 1 - 31") # Get second separator sep_2: str = date_input[5] # Validate if sep_2 not in ["-", "/"]: raise ValueError("Date separator must be '-' or '/'") # Get year y: int = int(date_input[6] + date_input[7] + date_input[8] + date_input[9]) # Arbitrary year range if not 45 < y < 8500: raise ValueError( "Year out of range. There has to be some sort of limit...right?" ) # Get datetime obj for validation dt_ck = datetime.date(int(y), int(m), int(d)) # Start math if m <= 2: y = y - 1 m = m + 12 # maths var c: int = int(str(y)[:2]) k: int = int(str(y)[2:]) t: int = int(2.6 * m - 5.39) u: int = int(c / 4) v: int = int(k / 4) x: int = int(d + k) z: int = int(t + u + v + x) w: int = int(z - (2 * c)) f: int = round(w % 7) # End math # Validate math if f != convert_datetime_days[dt_ck.weekday()]: raise AssertionError("The date was evaluated incorrectly. Contact developer.") # Response response: str = f"Your date {date_input}, is a {days[str(f)]}!" return response if __name__ == "__main__": import doctest doctest.testmod() parser = argparse.ArgumentParser( description=( "Find out what day of the week nearly any date is or was. Enter " "date as a string in the mm-dd-yyyy or mm/dd/yyyy format" ) ) parser.add_argument( "date_input", type=str, help="Date as a string (mm-dd-yyyy or mm/dd/yyyy)" ) args = parser.parse_args() zeller(args.date_input)
import argparse import datetime def zeller(date_input: str) -> str: """ Zellers Congruence Algorithm Find the day of the week for nearly any Gregorian or Julian calendar date >>> zeller('01-31-2010') 'Your date 01-31-2010, is a Sunday!' Validate out of range month >>> zeller('13-31-2010') Traceback (most recent call last): ... ValueError: Month must be between 1 - 12 >>> zeller('.2-31-2010') Traceback (most recent call last): ... ValueError: invalid literal for int() with base 10: '.2' Validate out of range date: >>> zeller('01-33-2010') Traceback (most recent call last): ... ValueError: Date must be between 1 - 31 >>> zeller('01-.4-2010') Traceback (most recent call last): ... ValueError: invalid literal for int() with base 10: '.4' Validate second separator: >>> zeller('01-31*2010') Traceback (most recent call last): ... ValueError: Date separator must be '-' or '/' Validate first separator: >>> zeller('01^31-2010') Traceback (most recent call last): ... ValueError: Date separator must be '-' or '/' Validate out of range year: >>> zeller('01-31-8999') Traceback (most recent call last): ... ValueError: Year out of range. There has to be some sort of limit...right? Test null input: >>> zeller() Traceback (most recent call last): ... TypeError: zeller() missing 1 required positional argument: 'date_input' Test length of date_input: >>> zeller('') Traceback (most recent call last): ... ValueError: Must be 10 characters long >>> zeller('01-31-19082939') Traceback (most recent call last): ... ValueError: Must be 10 characters long""" # Days of the week for response days = { "0": "Sunday", "1": "Monday", "2": "Tuesday", "3": "Wednesday", "4": "Thursday", "5": "Friday", "6": "Saturday", } convert_datetime_days = {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 0} # Validate if not 0 < len(date_input) < 11: raise ValueError("Must be 10 characters long") # Get month m: int = int(date_input[0] + date_input[1]) # Validate if not 0 < m < 13: raise ValueError("Month must be between 1 - 12") sep_1: str = date_input[2] # Validate if sep_1 not in ["-", "/"]: raise ValueError("Date separator must be '-' or '/'") # Get day d: int = int(date_input[3] + date_input[4]) # Validate if not 0 < d < 32: raise ValueError("Date must be between 1 - 31") # Get second separator sep_2: str = date_input[5] # Validate if sep_2 not in ["-", "/"]: raise ValueError("Date separator must be '-' or '/'") # Get year y: int = int(date_input[6] + date_input[7] + date_input[8] + date_input[9]) # Arbitrary year range if not 45 < y < 8500: raise ValueError( "Year out of range. There has to be some sort of limit...right?" ) # Get datetime obj for validation dt_ck = datetime.date(int(y), int(m), int(d)) # Start math if m <= 2: y = y - 1 m = m + 12 # maths var c: int = int(str(y)[:2]) k: int = int(str(y)[2:]) t: int = int(2.6 * m - 5.39) u: int = int(c / 4) v: int = int(k / 4) x: int = int(d + k) z: int = int(t + u + v + x) w: int = int(z - (2 * c)) f: int = round(w % 7) # End math # Validate math if f != convert_datetime_days[dt_ck.weekday()]: raise AssertionError("The date was evaluated incorrectly. Contact developer.") # Response response: str = f"Your date {date_input}, is a {days[str(f)]}!" return response if __name__ == "__main__": import doctest doctest.testmod() parser = argparse.ArgumentParser( description=( "Find out what day of the week nearly any date is or was. Enter " "date as a string in the mm-dd-yyyy or mm/dd/yyyy format" ) ) parser.add_argument( "date_input", type=str, help="Date as a string (mm-dd-yyyy or mm/dd/yyyy)" ) args = parser.parse_args() zeller(args.date_input)
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
"""https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance""" def jaro_winkler(str1: str, str2: str) -> float: """ Jaro–Winkler distance is a string metric measuring an edit distance between two sequences. Output value is between 0.0 and 1.0. >>> jaro_winkler("martha", "marhta") 0.9611111111111111 >>> jaro_winkler("CRATE", "TRACE") 0.7333333333333334 >>> jaro_winkler("test", "dbdbdbdb") 0.0 >>> jaro_winkler("test", "test") 1.0 >>> jaro_winkler("hello world", "HeLLo W0rlD") 0.6363636363636364 >>> jaro_winkler("test", "") 0.0 >>> jaro_winkler("hello", "world") 0.4666666666666666 >>> jaro_winkler("hell**o", "*world") 0.4365079365079365 """ def get_matched_characters(_str1: str, _str2: str) -> str: matched = [] limit = min(len(_str1), len(_str2)) // 2 for i, l in enumerate(_str1): left = int(max(0, i - limit)) right = int(min(i + limit + 1, len(_str2))) if l in _str2[left:right]: matched.append(l) _str2 = f"{_str2[0:_str2.index(l)]} {_str2[_str2.index(l) + 1:]}" return "".join(matched) # matching characters matching_1 = get_matched_characters(str1, str2) matching_2 = get_matched_characters(str2, str1) match_count = len(matching_1) # transposition transpositions = ( len([(c1, c2) for c1, c2 in zip(matching_1, matching_2) if c1 != c2]) // 2 ) if not match_count: jaro = 0.0 else: jaro = ( 1 / 3 * ( match_count / len(str1) + match_count / len(str2) + (match_count - transpositions) / match_count ) ) # common prefix up to 4 characters prefix_len = 0 for c1, c2 in zip(str1[:4], str2[:4]): if c1 == c2: prefix_len += 1 else: break return jaro + 0.1 * prefix_len * (1 - jaro) if __name__ == "__main__": import doctest doctest.testmod() print(jaro_winkler("hello", "world"))
"""https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance""" def jaro_winkler(str1: str, str2: str) -> float: """ Jaro–Winkler distance is a string metric measuring an edit distance between two sequences. Output value is between 0.0 and 1.0. >>> jaro_winkler("martha", "marhta") 0.9611111111111111 >>> jaro_winkler("CRATE", "TRACE") 0.7333333333333334 >>> jaro_winkler("test", "dbdbdbdb") 0.0 >>> jaro_winkler("test", "test") 1.0 >>> jaro_winkler("hello world", "HeLLo W0rlD") 0.6363636363636364 >>> jaro_winkler("test", "") 0.0 >>> jaro_winkler("hello", "world") 0.4666666666666666 >>> jaro_winkler("hell**o", "*world") 0.4365079365079365 """ def get_matched_characters(_str1: str, _str2: str) -> str: matched = [] limit = min(len(_str1), len(_str2)) // 2 for i, l in enumerate(_str1): left = int(max(0, i - limit)) right = int(min(i + limit + 1, len(_str2))) if l in _str2[left:right]: matched.append(l) _str2 = f"{_str2[0:_str2.index(l)]} {_str2[_str2.index(l) + 1:]}" return "".join(matched) # matching characters matching_1 = get_matched_characters(str1, str2) matching_2 = get_matched_characters(str2, str1) match_count = len(matching_1) # transposition transpositions = ( len([(c1, c2) for c1, c2 in zip(matching_1, matching_2) if c1 != c2]) // 2 ) if not match_count: jaro = 0.0 else: jaro = ( 1 / 3 * ( match_count / len(str1) + match_count / len(str2) + (match_count - transpositions) / match_count ) ) # common prefix up to 4 characters prefix_len = 0 for c1, c2 in zip(str1[:4], str2[:4]): if c1 == c2: prefix_len += 1 else: break return jaro + 0.1 * prefix_len * (1 - jaro) if __name__ == "__main__": import doctest doctest.testmod() print(jaro_winkler("hello", "world"))
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Introspective Sort is hybrid sort (Quick Sort + Heap Sort + Insertion Sort) if the size of the list is under 16, use insertion sort https://en.wikipedia.org/wiki/Introsort """ import math def insertion_sort(array: list, start: int = 0, end: int = 0) -> list: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> insertion_sort(array, 0, len(array)) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] """ end = end or len(array) for i in range(start, end): temp_index = i temp_index_value = array[i] while temp_index != start and temp_index_value < array[temp_index - 1]: array[temp_index] = array[temp_index - 1] temp_index -= 1 array[temp_index] = temp_index_value return array def heapify(array: list, index: int, heap_size: int) -> None: # Max Heap """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> heapify(array, len(array) // 2 ,len(array)) """ largest = index left_index = 2 * index + 1 # Left Node right_index = 2 * index + 2 # Right Node if left_index < heap_size and array[largest] < array[left_index]: largest = left_index if right_index < heap_size and array[largest] < array[right_index]: largest = right_index if largest != index: array[index], array[largest] = array[largest], array[index] heapify(array, largest, heap_size) def heap_sort(array: list) -> list: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> heap_sort(array) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] """ n = len(array) for i in range(n // 2, -1, -1): heapify(array, i, n) for i in range(n - 1, 0, -1): array[i], array[0] = array[0], array[i] heapify(array, 0, i) return array def median_of_3( array: list, first_index: int, middle_index: int, last_index: int ) -> int: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> median_of_3(array, 0, 0 + ((len(array) - 0) // 2) + 1, len(array) - 1) 12 """ if (array[first_index] > array[middle_index]) != ( array[first_index] > array[last_index] ): return array[first_index] elif (array[middle_index] > array[first_index]) != ( array[middle_index] > array[last_index] ): return array[middle_index] else: return array[last_index] def partition(array: list, low: int, high: int, pivot: int) -> int: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> partition(array, 0, len(array), 12) 8 """ i = low j = high while True: while array[i] < pivot: i += 1 j -= 1 while pivot < array[j]: j -= 1 if i >= j: return i array[i], array[j] = array[j], array[i] i += 1 def sort(array: list) -> list: """ :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] >>> sort([-1, -5, -3, -13, -44]) [-44, -13, -5, -3, -1] >>> sort([]) [] >>> sort([5]) [5] >>> sort([-3, 0, -7, 6, 23, -34]) [-34, -7, -3, 0, 6, 23] >>> sort([1.7, 1.0, 3.3, 2.1, 0.3 ]) [0.3, 1.0, 1.7, 2.1, 3.3] >>> sort(['d', 'a', 'b', 'e', 'c']) ['a', 'b', 'c', 'd', 'e'] """ if len(array) == 0: return array max_depth = 2 * math.ceil(math.log2(len(array))) size_threshold = 16 return intro_sort(array, 0, len(array), size_threshold, max_depth) def intro_sort( array: list, start: int, end: int, size_threshold: int, max_depth: int ) -> list: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> max_depth = 2 * math.ceil(math.log2(len(array))) >>> intro_sort(array, 0, len(array), 16, max_depth) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] """ while end - start > size_threshold: if max_depth == 0: return heap_sort(array) max_depth -= 1 pivot = median_of_3(array, start, start + ((end - start) // 2) + 1, end - 1) p = partition(array, start, end, pivot) intro_sort(array, p, end, size_threshold, max_depth) end = p return insertion_sort(array, start, end) if __name__ == "__main__": import doctest doctest.testmod() user_input = input("Enter numbers separated by a comma : ").strip() unsorted = [float(item) for item in user_input.split(",")] print(sort(unsorted))
""" Introspective Sort is hybrid sort (Quick Sort + Heap Sort + Insertion Sort) if the size of the list is under 16, use insertion sort https://en.wikipedia.org/wiki/Introsort """ import math def insertion_sort(array: list, start: int = 0, end: int = 0) -> list: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> insertion_sort(array, 0, len(array)) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] """ end = end or len(array) for i in range(start, end): temp_index = i temp_index_value = array[i] while temp_index != start and temp_index_value < array[temp_index - 1]: array[temp_index] = array[temp_index - 1] temp_index -= 1 array[temp_index] = temp_index_value return array def heapify(array: list, index: int, heap_size: int) -> None: # Max Heap """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> heapify(array, len(array) // 2 ,len(array)) """ largest = index left_index = 2 * index + 1 # Left Node right_index = 2 * index + 2 # Right Node if left_index < heap_size and array[largest] < array[left_index]: largest = left_index if right_index < heap_size and array[largest] < array[right_index]: largest = right_index if largest != index: array[index], array[largest] = array[largest], array[index] heapify(array, largest, heap_size) def heap_sort(array: list) -> list: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> heap_sort(array) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] """ n = len(array) for i in range(n // 2, -1, -1): heapify(array, i, n) for i in range(n - 1, 0, -1): array[i], array[0] = array[0], array[i] heapify(array, 0, i) return array def median_of_3( array: list, first_index: int, middle_index: int, last_index: int ) -> int: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> median_of_3(array, 0, 0 + ((len(array) - 0) // 2) + 1, len(array) - 1) 12 """ if (array[first_index] > array[middle_index]) != ( array[first_index] > array[last_index] ): return array[first_index] elif (array[middle_index] > array[first_index]) != ( array[middle_index] > array[last_index] ): return array[middle_index] else: return array[last_index] def partition(array: list, low: int, high: int, pivot: int) -> int: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> partition(array, 0, len(array), 12) 8 """ i = low j = high while True: while array[i] < pivot: i += 1 j -= 1 while pivot < array[j]: j -= 1 if i >= j: return i array[i], array[j] = array[j], array[i] i += 1 def sort(array: list) -> list: """ :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] >>> sort([-1, -5, -3, -13, -44]) [-44, -13, -5, -3, -1] >>> sort([]) [] >>> sort([5]) [5] >>> sort([-3, 0, -7, 6, 23, -34]) [-34, -7, -3, 0, 6, 23] >>> sort([1.7, 1.0, 3.3, 2.1, 0.3 ]) [0.3, 1.0, 1.7, 2.1, 3.3] >>> sort(['d', 'a', 'b', 'e', 'c']) ['a', 'b', 'c', 'd', 'e'] """ if len(array) == 0: return array max_depth = 2 * math.ceil(math.log2(len(array))) size_threshold = 16 return intro_sort(array, 0, len(array), size_threshold, max_depth) def intro_sort( array: list, start: int, end: int, size_threshold: int, max_depth: int ) -> list: """ >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> max_depth = 2 * math.ceil(math.log2(len(array))) >>> intro_sort(array, 0, len(array), 16, max_depth) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] """ while end - start > size_threshold: if max_depth == 0: return heap_sort(array) max_depth -= 1 pivot = median_of_3(array, start, start + ((end - start) // 2) + 1, end - 1) p = partition(array, start, end, pivot) intro_sort(array, p, end, size_threshold, max_depth) end = p return insertion_sort(array, start, end) if __name__ == "__main__": import doctest doctest.testmod() user_input = input("Enter numbers separated by a comma : ").strip() unsorted = [float(item) for item in user_input.split(",")] print(sort(unsorted))
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from collections import defaultdict from graphs.minimum_spanning_tree_prims import PrimsAlgorithm as mst def test_prim_successful_result(): num_nodes, num_edges = 9, 14 # noqa: F841 edges = [ [0, 1, 4], [0, 7, 8], [1, 2, 8], [7, 8, 7], [7, 6, 1], [2, 8, 2], [8, 6, 6], [2, 3, 7], [2, 5, 4], [6, 5, 2], [3, 5, 14], [3, 4, 9], [5, 4, 10], [1, 7, 11], ] adjancency = defaultdict(list) for node1, node2, cost in edges: adjancency[node1].append([node2, cost]) adjancency[node2].append([node1, cost]) result = mst(adjancency) expected = [ [7, 6, 1], [2, 8, 2], [6, 5, 2], [0, 1, 4], [2, 5, 4], [2, 3, 7], [0, 7, 8], [3, 4, 9], ] for answer in expected: edge = tuple(answer[:2]) reverse = tuple(edge[::-1]) assert edge in result or reverse in result
from collections import defaultdict from graphs.minimum_spanning_tree_prims import PrimsAlgorithm as mst def test_prim_successful_result(): num_nodes, num_edges = 9, 14 # noqa: F841 edges = [ [0, 1, 4], [0, 7, 8], [1, 2, 8], [7, 8, 7], [7, 6, 1], [2, 8, 2], [8, 6, 6], [2, 3, 7], [2, 5, 4], [6, 5, 2], [3, 5, 14], [3, 4, 9], [5, 4, 10], [1, 7, 11], ] adjancency = defaultdict(list) for node1, node2, cost in edges: adjancency[node1].append([node2, cost]) adjancency[node2].append([node1, cost]) result = mst(adjancency) expected = [ [7, 6, 1], [2, 8, 2], [6, 5, 2], [0, 1, 4], [2, 5, 4], [2, 3, 7], [0, 7, 8], [3, 4, 9], ] for answer in expected: edge = tuple(answer[:2]) reverse = tuple(edge[::-1]) assert edge in result or reverse in result
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Project Euler Problem 91: https://projecteuler.net/problem=91 The points P (x1, y1) and Q (x2, y2) are plotted at integer coordinates and are joined to the origin, O(0,0), to form ΔOPQ.  There are exactly fourteen triangles containing a right angle that can be formed when each coordinate lies between 0 and 2 inclusive; that is, 0 ≤ x1, y1, x2, y2 ≤ 2.  Given that 0 ≤ x1, y1, x2, y2 ≤ 50, how many right triangles can be formed? """ from itertools import combinations, product def is_right(x1: int, y1: int, x2: int, y2: int) -> bool: """ Check if the triangle described by P(x1,y1), Q(x2,y2) and O(0,0) is right-angled. Note: this doesn't check if P and Q are equal, but that's handled by the use of itertools.combinations in the solution function. >>> is_right(0, 1, 2, 0) True >>> is_right(1, 0, 2, 2) False """ if x1 == y1 == 0 or x2 == y2 == 0: return False a_square = x1 * x1 + y1 * y1 b_square = x2 * x2 + y2 * y2 c_square = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) return ( a_square + b_square == c_square or a_square + c_square == b_square or b_square + c_square == a_square ) def solution(limit: int = 50) -> int: """ Return the number of right triangles OPQ that can be formed by two points P, Q which have both x- and y- coordinates between 0 and limit inclusive. >>> solution(2) 14 >>> solution(10) 448 """ return sum( 1 for pt1, pt2 in combinations(product(range(limit + 1), repeat=2), 2) if is_right(*pt1, *pt2) ) if __name__ == "__main__": print(f"{solution() = }")
""" Project Euler Problem 91: https://projecteuler.net/problem=91 The points P (x1, y1) and Q (x2, y2) are plotted at integer coordinates and are joined to the origin, O(0,0), to form ΔOPQ.  There are exactly fourteen triangles containing a right angle that can be formed when each coordinate lies between 0 and 2 inclusive; that is, 0 ≤ x1, y1, x2, y2 ≤ 2.  Given that 0 ≤ x1, y1, x2, y2 ≤ 50, how many right triangles can be formed? """ from itertools import combinations, product def is_right(x1: int, y1: int, x2: int, y2: int) -> bool: """ Check if the triangle described by P(x1,y1), Q(x2,y2) and O(0,0) is right-angled. Note: this doesn't check if P and Q are equal, but that's handled by the use of itertools.combinations in the solution function. >>> is_right(0, 1, 2, 0) True >>> is_right(1, 0, 2, 2) False """ if x1 == y1 == 0 or x2 == y2 == 0: return False a_square = x1 * x1 + y1 * y1 b_square = x2 * x2 + y2 * y2 c_square = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) return ( a_square + b_square == c_square or a_square + c_square == b_square or b_square + c_square == a_square ) def solution(limit: int = 50) -> int: """ Return the number of right triangles OPQ that can be formed by two points P, Q which have both x- and y- coordinates between 0 and limit inclusive. >>> solution(2) 14 >>> solution(10) 448 """ return sum( 1 for pt1, pt2 in combinations(product(range(limit + 1), repeat=2), 2) if is_right(*pt1, *pt2) ) if __name__ == "__main__": print(f"{solution() = }")
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Counting Sundays Problem 19 You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alone, Which has twenty-eight, rain or shine. And on leap years, twenty-nine. A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400. How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? """ def solution(): """Returns the number of mondays that fall on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? >>> solution() 171 """ days_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] day = 6 month = 1 year = 1901 sundays = 0 while year < 2001: day += 7 if (year % 4 == 0 and not year % 100 == 0) or (year % 400 == 0): if day > days_per_month[month - 1] and month != 2: month += 1 day = day - days_per_month[month - 2] elif day > 29 and month == 2: month += 1 day = day - 29 else: if day > days_per_month[month - 1]: month += 1 day = day - days_per_month[month - 2] if month > 12: year += 1 month = 1 if year < 2001 and day == 1: sundays += 1 return sundays if __name__ == "__main__": print(solution())
""" Counting Sundays Problem 19 You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alone, Which has twenty-eight, rain or shine. And on leap years, twenty-nine. A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400. How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? """ def solution(): """Returns the number of mondays that fall on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? >>> solution() 171 """ days_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] day = 6 month = 1 year = 1901 sundays = 0 while year < 2001: day += 7 if (year % 4 == 0 and not year % 100 == 0) or (year % 400 == 0): if day > days_per_month[month - 1] and month != 2: month += 1 day = day - days_per_month[month - 2] elif day > 29 and month == 2: month += 1 day = day - 29 else: if day > days_per_month[month - 1]: month += 1 day = day - days_per_month[month - 2] if month > 12: year += 1 month = 1 if year < 2001 and day == 1: sundays += 1 return sundays if __name__ == "__main__": print(solution())
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power. How many n-digit positive integers exist which are also an nth power? """ """ The maximum base can be 9 because all n-digit numbers < 10^n. Now 9**23 has 22 digits so the maximum power can be 22. Using these conclusions, we will calculate the result. """ def solution(max_base: int = 10, max_power: int = 22) -> int: """ Returns the count of all n-digit numbers which are nth power >>> solution(10, 22) 49 >>> solution(0, 0) 0 >>> solution(1, 1) 0 >>> solution(-1, -1) 0 """ bases = range(1, max_base) powers = range(1, max_power) return sum( 1 for power in powers for base in bases if len(str(base ** power)) == power ) if __name__ == "__main__": print(f"{solution(10, 22) = }")
""" The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power. How many n-digit positive integers exist which are also an nth power? """ """ The maximum base can be 9 because all n-digit numbers < 10^n. Now 9**23 has 22 digits so the maximum power can be 22. Using these conclusions, we will calculate the result. """ def solution(max_base: int = 10, max_power: int = 22) -> int: """ Returns the count of all n-digit numbers which are nth power >>> solution(10, 22) 49 >>> solution(0, 0) 0 >>> solution(1, 1) 0 >>> solution(-1, -1) 0 """ bases = range(1, max_base) powers = range(1, max_power) return sum( 1 for power in powers for base in bases if len(str(base ** power)) == power ) if __name__ == "__main__": print(f"{solution(10, 22) = }")
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
#
#
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Author: Alexander Joslin GitHub: github.com/echoaj Explanation: https://medium.com/@haleesammar/implemented-in-js-dijkstras-2-stack- algorithm-for-evaluating-mathematical-expressions-fc0837dae1ea We can use Dijkstra's two stack algorithm to solve an equation such as: (5 + ((4 * 2) * (2 + 3))) THESE ARE THE ALGORITHM'S RULES: RULE 1: Scan the expression from left to right. When an operand is encountered, push it onto the the operand stack. RULE 2: When an operator is encountered in the expression, push it onto the operator stack. RULE 3: When a left parenthesis is encountered in the expression, ignore it. RULE 4: When a right parenthesis is encountered in the expression, pop an operator off the operator stack. The two operands it must operate on must be the last two operands pushed onto the operand stack. We therefore pop the operand stack twice, perform the operation, and push the result back onto the operand stack so it will be available for use as an operand of the next operator popped off the operator stack. RULE 5: When the entire infix expression has been scanned, the value left on the operand stack represents the value of the expression. NOTE: It only works with whole numbers. """ __author__ = "Alexander Joslin" import operator as op from .stack import Stack def dijkstras_two_stack_algorithm(equation: str) -> int: """ DocTests >>> dijkstras_two_stack_algorithm("(5 + 3)") 8 >>> dijkstras_two_stack_algorithm("((9 - (2 + 9)) + (8 - 1))") 5 >>> dijkstras_two_stack_algorithm("((((3 - 2) - (2 + 3)) + (2 - 4)) + 3)") -3 :param equation: a string :return: result: an integer """ operators = {"*": op.mul, "/": op.truediv, "+": op.add, "-": op.sub} operand_stack = Stack() operator_stack = Stack() for i in equation: if i.isdigit(): # RULE 1 operand_stack.push(int(i)) elif i in operators: # RULE 2 operator_stack.push(i) elif i == ")": # RULE 4 opr = operator_stack.peek() operator_stack.pop() num1 = operand_stack.peek() operand_stack.pop() num2 = operand_stack.peek() operand_stack.pop() total = operators[opr](num2, num1) operand_stack.push(total) # RULE 5 return operand_stack.peek() if __name__ == "__main__": equation = "(5 + ((4 * 2) * (2 + 3)))" # answer = 45 print(f"{equation} = {dijkstras_two_stack_algorithm(equation)}")
""" Author: Alexander Joslin GitHub: github.com/echoaj Explanation: https://medium.com/@haleesammar/implemented-in-js-dijkstras-2-stack- algorithm-for-evaluating-mathematical-expressions-fc0837dae1ea We can use Dijkstra's two stack algorithm to solve an equation such as: (5 + ((4 * 2) * (2 + 3))) THESE ARE THE ALGORITHM'S RULES: RULE 1: Scan the expression from left to right. When an operand is encountered, push it onto the the operand stack. RULE 2: When an operator is encountered in the expression, push it onto the operator stack. RULE 3: When a left parenthesis is encountered in the expression, ignore it. RULE 4: When a right parenthesis is encountered in the expression, pop an operator off the operator stack. The two operands it must operate on must be the last two operands pushed onto the operand stack. We therefore pop the operand stack twice, perform the operation, and push the result back onto the operand stack so it will be available for use as an operand of the next operator popped off the operator stack. RULE 5: When the entire infix expression has been scanned, the value left on the operand stack represents the value of the expression. NOTE: It only works with whole numbers. """ __author__ = "Alexander Joslin" import operator as op from .stack import Stack def dijkstras_two_stack_algorithm(equation: str) -> int: """ DocTests >>> dijkstras_two_stack_algorithm("(5 + 3)") 8 >>> dijkstras_two_stack_algorithm("((9 - (2 + 9)) + (8 - 1))") 5 >>> dijkstras_two_stack_algorithm("((((3 - 2) - (2 + 3)) + (2 - 4)) + 3)") -3 :param equation: a string :return: result: an integer """ operators = {"*": op.mul, "/": op.truediv, "+": op.add, "-": op.sub} operand_stack = Stack() operator_stack = Stack() for i in equation: if i.isdigit(): # RULE 1 operand_stack.push(int(i)) elif i in operators: # RULE 2 operator_stack.push(i) elif i == ")": # RULE 4 opr = operator_stack.peek() operator_stack.pop() num1 = operand_stack.peek() operand_stack.pop() num2 = operand_stack.peek() operand_stack.pop() total = operators[opr](num2, num1) operand_stack.push(total) # RULE 5 return operand_stack.peek() if __name__ == "__main__": equation = "(5 + ((4 * 2) * (2 + 3)))" # answer = 45 print(f"{equation} = {dijkstras_two_stack_algorithm(equation)}")
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from __future__ import annotations def stable_matching( donor_pref: list[list[int]], recipient_pref: list[list[int]] ) -> list[int]: """ Finds the stable match in any bipartite graph, i.e a pairing where no 2 objects prefer each other over their partner. The function accepts the preferences of oegan donors and recipients (where both are assigned numbers from 0 to n-1) and returns a list where the index position corresponds to the donor and value at the index is the organ recipient. To better understand the algorithm, see also: https://github.com/akashvshroff/Gale_Shapley_Stable_Matching (README). https://www.youtube.com/watch?v=Qcv1IqHWAzg&t=13s (Numberphile YouTube). >>> donor_pref = [[0, 1, 3, 2], [0, 2, 3, 1], [1, 0, 2, 3], [0, 3, 1, 2]] >>> recipient_pref = [[3, 1, 2, 0], [3, 1, 0, 2], [0, 3, 1, 2], [1, 0, 3, 2]] >>> print(stable_matching(donor_pref, recipient_pref)) [1, 2, 3, 0] """ assert len(donor_pref) == len(recipient_pref) n = len(donor_pref) unmatched_donors = list(range(n)) donor_record = [-1] * n # who the donor has donated to rec_record = [-1] * n # who the recipient has received from num_donations = [0] * n while unmatched_donors: donor = unmatched_donors[0] donor_preference = donor_pref[donor] recipient = donor_preference[num_donations[donor]] num_donations[donor] += 1 rec_preference = recipient_pref[recipient] prev_donor = rec_record[recipient] if prev_donor != -1: if rec_preference.index(prev_donor) > rec_preference.index(donor): rec_record[recipient] = donor donor_record[donor] = recipient unmatched_donors.append(prev_donor) unmatched_donors.remove(donor) else: rec_record[recipient] = donor donor_record[donor] = recipient unmatched_donors.remove(donor) return donor_record
from __future__ import annotations def stable_matching( donor_pref: list[list[int]], recipient_pref: list[list[int]] ) -> list[int]: """ Finds the stable match in any bipartite graph, i.e a pairing where no 2 objects prefer each other over their partner. The function accepts the preferences of oegan donors and recipients (where both are assigned numbers from 0 to n-1) and returns a list where the index position corresponds to the donor and value at the index is the organ recipient. To better understand the algorithm, see also: https://github.com/akashvshroff/Gale_Shapley_Stable_Matching (README). https://www.youtube.com/watch?v=Qcv1IqHWAzg&t=13s (Numberphile YouTube). >>> donor_pref = [[0, 1, 3, 2], [0, 2, 3, 1], [1, 0, 2, 3], [0, 3, 1, 2]] >>> recipient_pref = [[3, 1, 2, 0], [3, 1, 0, 2], [0, 3, 1, 2], [1, 0, 3, 2]] >>> print(stable_matching(donor_pref, recipient_pref)) [1, 2, 3, 0] """ assert len(donor_pref) == len(recipient_pref) n = len(donor_pref) unmatched_donors = list(range(n)) donor_record = [-1] * n # who the donor has donated to rec_record = [-1] * n # who the recipient has received from num_donations = [0] * n while unmatched_donors: donor = unmatched_donors[0] donor_preference = donor_pref[donor] recipient = donor_preference[num_donations[donor]] num_donations[donor] += 1 rec_preference = recipient_pref[recipient] prev_donor = rec_record[recipient] if prev_donor != -1: if rec_preference.index(prev_donor) > rec_preference.index(donor): rec_record[recipient] = donor donor_record[donor] = recipient unmatched_donors.append(prev_donor) unmatched_donors.remove(donor) else: rec_record[recipient] = donor donor_record[donor] = recipient unmatched_donors.remove(donor) return donor_record
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Print all the Catalan numbers from 0 to n, n being the user input. * The Catalan numbers are a sequence of positive integers that * appear in many counting problems in combinatorics [1]. Such * problems include counting [2]: * - The number of Dyck words of length 2n * - The number well-formed expressions with n pairs of parentheses * (e.g., `()()` is valid but `())(` is not) * - The number of different ways n + 1 factors can be completely * parenthesized (e.g., for n = 2, C(n) = 2 and (ab)c and a(bc) * are the two valid ways to parenthesize. * - The number of full binary trees with n + 1 leaves * A Catalan number satisfies the following recurrence relation * which we will use in this algorithm [1]. * C(0) = C(1) = 1 * C(n) = sum(C(i).C(n-i-1)), from i = 0 to n-1 * In addition, the n-th Catalan number can be calculated using * the closed form formula below [1]: * C(n) = (1 / (n + 1)) * (2n choose n) * Sources: * [1] https://brilliant.org/wiki/catalan-numbers/ * [2] https://en.wikipedia.org/wiki/Catalan_number """ def catalan_numbers(upper_limit: int) -> "list[int]": """ Return a list of the Catalan number sequence from 0 through `upper_limit`. >>> catalan_numbers(5) [1, 1, 2, 5, 14, 42] >>> catalan_numbers(2) [1, 1, 2] >>> catalan_numbers(-1) Traceback (most recent call last): ValueError: Limit for the Catalan sequence must be ≥ 0 """ if upper_limit < 0: raise ValueError("Limit for the Catalan sequence must be ≥ 0") catalan_list = [0] * (upper_limit + 1) # Base case: C(0) = C(1) = 1 catalan_list[0] = 1 if upper_limit > 0: catalan_list[1] = 1 # Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i for i in range(2, upper_limit + 1): for j in range(i): catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1] return catalan_list if __name__ == "__main__": print("\n********* Catalan Numbers Using Dynamic Programming ************\n") print("\n*** Enter -1 at any time to quit ***") print("\nEnter the upper limit (≥ 0) for the Catalan number sequence: ", end="") try: while True: N = int(input().strip()) if N < 0: print("\n********* Goodbye!! ************") break else: print(f"The Catalan numbers from 0 through {N} are:") print(catalan_numbers(N)) print("Try another upper limit for the sequence: ", end="") except (NameError, ValueError): print("\n********* Invalid input, goodbye! ************\n") import doctest doctest.testmod()
""" Print all the Catalan numbers from 0 to n, n being the user input. * The Catalan numbers are a sequence of positive integers that * appear in many counting problems in combinatorics [1]. Such * problems include counting [2]: * - The number of Dyck words of length 2n * - The number well-formed expressions with n pairs of parentheses * (e.g., `()()` is valid but `())(` is not) * - The number of different ways n + 1 factors can be completely * parenthesized (e.g., for n = 2, C(n) = 2 and (ab)c and a(bc) * are the two valid ways to parenthesize. * - The number of full binary trees with n + 1 leaves * A Catalan number satisfies the following recurrence relation * which we will use in this algorithm [1]. * C(0) = C(1) = 1 * C(n) = sum(C(i).C(n-i-1)), from i = 0 to n-1 * In addition, the n-th Catalan number can be calculated using * the closed form formula below [1]: * C(n) = (1 / (n + 1)) * (2n choose n) * Sources: * [1] https://brilliant.org/wiki/catalan-numbers/ * [2] https://en.wikipedia.org/wiki/Catalan_number """ def catalan_numbers(upper_limit: int) -> "list[int]": """ Return a list of the Catalan number sequence from 0 through `upper_limit`. >>> catalan_numbers(5) [1, 1, 2, 5, 14, 42] >>> catalan_numbers(2) [1, 1, 2] >>> catalan_numbers(-1) Traceback (most recent call last): ValueError: Limit for the Catalan sequence must be ≥ 0 """ if upper_limit < 0: raise ValueError("Limit for the Catalan sequence must be ≥ 0") catalan_list = [0] * (upper_limit + 1) # Base case: C(0) = C(1) = 1 catalan_list[0] = 1 if upper_limit > 0: catalan_list[1] = 1 # Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i for i in range(2, upper_limit + 1): for j in range(i): catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1] return catalan_list if __name__ == "__main__": print("\n********* Catalan Numbers Using Dynamic Programming ************\n") print("\n*** Enter -1 at any time to quit ***") print("\nEnter the upper limit (≥ 0) for the Catalan number sequence: ", end="") try: while True: N = int(input().strip()) if N < 0: print("\n********* Goodbye!! ************") break else: print(f"The Catalan numbers from 0 through {N} are:") print(catalan_numbers(N)) print("Try another upper limit for the sequence: ", end="") except (NameError, ValueError): print("\n********* Invalid input, goodbye! ************\n") import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Project Euler Problem 8: https://projecteuler.net/problem=8 Largest product in a series The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450 Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? """ import sys N = """73167176531330624919225119674426574742355349194934\ 96983520312774506326239578318016984801869478851843\ 85861560789112949495459501737958331952853208805511\ 12540698747158523863050715693290963295227443043557\ 66896648950445244523161731856403098711121722383113\ 62229893423380308135336276614282806444486645238749\ 30358907296290491560440772390713810515859307960866\ 70172427121883998797908792274921901699720888093776\ 65727333001053367881220235421809751254540594752243\ 52584907711670556013604839586446706324415722155397\ 53697817977846174064955149290862569321978468622482\ 83972241375657056057490261407972968652414535100474\ 82166370484403199890008895243450658541227588666881\ 16427171479924442928230863465674813919123162824586\ 17866458359124566529476545682848912883142607690042\ 24219022671055626321111109370544217506941658960408\ 07198403850962455444362981230987879927244284909188\ 84580156166097919133875499200524063689912560717606\ 05886116467109405077541002256983155200055935729725\ 71636269561882670428252483600823257530420752963450""" def str_eval(s: str) -> int: """ Returns product of digits in given string n >>> str_eval("987654321") 362880 >>> str_eval("22222222") 256 """ product = 1 for digit in s: product *= int(digit) return product def solution(n: str = N) -> int: """ Find the thirteen adjacent digits in the 1000-digit number n that have the greatest product and returns it. """ largest_product = -sys.maxsize - 1 substr = n[:13] cur_index = 13 while cur_index < len(n) - 13: if int(n[cur_index]) >= int(substr[0]): substr = substr[1:] + n[cur_index] cur_index += 1 else: largest_product = max(largest_product, str_eval(substr)) substr = n[cur_index : cur_index + 13] cur_index += 13 return largest_product if __name__ == "__main__": print(f"{solution() = }")
""" Project Euler Problem 8: https://projecteuler.net/problem=8 Largest product in a series The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450 Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? """ import sys N = """73167176531330624919225119674426574742355349194934\ 96983520312774506326239578318016984801869478851843\ 85861560789112949495459501737958331952853208805511\ 12540698747158523863050715693290963295227443043557\ 66896648950445244523161731856403098711121722383113\ 62229893423380308135336276614282806444486645238749\ 30358907296290491560440772390713810515859307960866\ 70172427121883998797908792274921901699720888093776\ 65727333001053367881220235421809751254540594752243\ 52584907711670556013604839586446706324415722155397\ 53697817977846174064955149290862569321978468622482\ 83972241375657056057490261407972968652414535100474\ 82166370484403199890008895243450658541227588666881\ 16427171479924442928230863465674813919123162824586\ 17866458359124566529476545682848912883142607690042\ 24219022671055626321111109370544217506941658960408\ 07198403850962455444362981230987879927244284909188\ 84580156166097919133875499200524063689912560717606\ 05886116467109405077541002256983155200055935729725\ 71636269561882670428252483600823257530420752963450""" def str_eval(s: str) -> int: """ Returns product of digits in given string n >>> str_eval("987654321") 362880 >>> str_eval("22222222") 256 """ product = 1 for digit in s: product *= int(digit) return product def solution(n: str = N) -> int: """ Find the thirteen adjacent digits in the 1000-digit number n that have the greatest product and returns it. """ largest_product = -sys.maxsize - 1 substr = n[:13] cur_index = 13 while cur_index < len(n) - 13: if int(n[cur_index]) >= int(substr[0]): substr = substr[1:] + n[cur_index] cur_index += 1 else: largest_product = max(largest_product, str_eval(substr)) substr = n[cur_index : cur_index + 13] cur_index += 13 return largest_product if __name__ == "__main__": print(f"{solution() = }")
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
import cv2 import numpy as np from digital_image_processing.filters.convolve import img_convolve from digital_image_processing.filters.sobel_filter import sobel_filter PI = 180 def gen_gaussian_kernel(k_size, sigma): center = k_size // 2 x, y = np.mgrid[0 - center : k_size - center, 0 - center : k_size - center] g = ( 1 / (2 * np.pi * sigma) * np.exp(-(np.square(x) + np.square(y)) / (2 * np.square(sigma))) ) return g def canny(image, threshold_low=15, threshold_high=30, weak=128, strong=255): image_row, image_col = image.shape[0], image.shape[1] # gaussian_filter gaussian_out = img_convolve(image, gen_gaussian_kernel(9, sigma=1.4)) # get the gradient and degree by sobel_filter sobel_grad, sobel_theta = sobel_filter(gaussian_out) gradient_direction = np.rad2deg(sobel_theta) gradient_direction += PI dst = np.zeros((image_row, image_col)) """ Non-maximum suppression. If the edge strength of the current pixel is the largest compared to the other pixels in the mask with the same direction, the value will be preserved. Otherwise, the value will be suppressed. """ for row in range(1, image_row - 1): for col in range(1, image_col - 1): direction = gradient_direction[row, col] if ( 0 <= direction < 22.5 or 15 * PI / 8 <= direction <= 2 * PI or 7 * PI / 8 <= direction <= 9 * PI / 8 ): W = sobel_grad[row, col - 1] E = sobel_grad[row, col + 1] if sobel_grad[row, col] >= W and sobel_grad[row, col] >= E: dst[row, col] = sobel_grad[row, col] elif (PI / 8 <= direction < 3 * PI / 8) or ( 9 * PI / 8 <= direction < 11 * PI / 8 ): SW = sobel_grad[row + 1, col - 1] NE = sobel_grad[row - 1, col + 1] if sobel_grad[row, col] >= SW and sobel_grad[row, col] >= NE: dst[row, col] = sobel_grad[row, col] elif (3 * PI / 8 <= direction < 5 * PI / 8) or ( 11 * PI / 8 <= direction < 13 * PI / 8 ): N = sobel_grad[row - 1, col] S = sobel_grad[row + 1, col] if sobel_grad[row, col] >= N and sobel_grad[row, col] >= S: dst[row, col] = sobel_grad[row, col] elif (5 * PI / 8 <= direction < 7 * PI / 8) or ( 13 * PI / 8 <= direction < 15 * PI / 8 ): NW = sobel_grad[row - 1, col - 1] SE = sobel_grad[row + 1, col + 1] if sobel_grad[row, col] >= NW and sobel_grad[row, col] >= SE: dst[row, col] = sobel_grad[row, col] """ High-Low threshold detection. If an edge pixel’s gradient value is higher than the high threshold value, it is marked as a strong edge pixel. If an edge pixel’s gradient value is smaller than the high threshold value and larger than the low threshold value, it is marked as a weak edge pixel. If an edge pixel's value is smaller than the low threshold value, it will be suppressed. """ if dst[row, col] >= threshold_high: dst[row, col] = strong elif dst[row, col] <= threshold_low: dst[row, col] = 0 else: dst[row, col] = weak """ Edge tracking. Usually a weak edge pixel caused from true edges will be connected to a strong edge pixel while noise responses are unconnected. As long as there is one strong edge pixel that is involved in its 8-connected neighborhood, that weak edge point can be identified as one that should be preserved. """ for row in range(1, image_row): for col in range(1, image_col): if dst[row, col] == weak: if 255 in ( dst[row, col + 1], dst[row, col - 1], dst[row - 1, col], dst[row + 1, col], dst[row - 1, col - 1], dst[row + 1, col - 1], dst[row - 1, col + 1], dst[row + 1, col + 1], ): dst[row, col] = strong else: dst[row, col] = 0 return dst if __name__ == "__main__": # read original image in gray mode lena = cv2.imread(r"../image_data/lena.jpg", 0) # canny edge detection canny_dst = canny(lena) cv2.imshow("canny", canny_dst) cv2.waitKey(0)
import cv2 import numpy as np from digital_image_processing.filters.convolve import img_convolve from digital_image_processing.filters.sobel_filter import sobel_filter PI = 180 def gen_gaussian_kernel(k_size, sigma): center = k_size // 2 x, y = np.mgrid[0 - center : k_size - center, 0 - center : k_size - center] g = ( 1 / (2 * np.pi * sigma) * np.exp(-(np.square(x) + np.square(y)) / (2 * np.square(sigma))) ) return g def canny(image, threshold_low=15, threshold_high=30, weak=128, strong=255): image_row, image_col = image.shape[0], image.shape[1] # gaussian_filter gaussian_out = img_convolve(image, gen_gaussian_kernel(9, sigma=1.4)) # get the gradient and degree by sobel_filter sobel_grad, sobel_theta = sobel_filter(gaussian_out) gradient_direction = np.rad2deg(sobel_theta) gradient_direction += PI dst = np.zeros((image_row, image_col)) """ Non-maximum suppression. If the edge strength of the current pixel is the largest compared to the other pixels in the mask with the same direction, the value will be preserved. Otherwise, the value will be suppressed. """ for row in range(1, image_row - 1): for col in range(1, image_col - 1): direction = gradient_direction[row, col] if ( 0 <= direction < 22.5 or 15 * PI / 8 <= direction <= 2 * PI or 7 * PI / 8 <= direction <= 9 * PI / 8 ): W = sobel_grad[row, col - 1] E = sobel_grad[row, col + 1] if sobel_grad[row, col] >= W and sobel_grad[row, col] >= E: dst[row, col] = sobel_grad[row, col] elif (PI / 8 <= direction < 3 * PI / 8) or ( 9 * PI / 8 <= direction < 11 * PI / 8 ): SW = sobel_grad[row + 1, col - 1] NE = sobel_grad[row - 1, col + 1] if sobel_grad[row, col] >= SW and sobel_grad[row, col] >= NE: dst[row, col] = sobel_grad[row, col] elif (3 * PI / 8 <= direction < 5 * PI / 8) or ( 11 * PI / 8 <= direction < 13 * PI / 8 ): N = sobel_grad[row - 1, col] S = sobel_grad[row + 1, col] if sobel_grad[row, col] >= N and sobel_grad[row, col] >= S: dst[row, col] = sobel_grad[row, col] elif (5 * PI / 8 <= direction < 7 * PI / 8) or ( 13 * PI / 8 <= direction < 15 * PI / 8 ): NW = sobel_grad[row - 1, col - 1] SE = sobel_grad[row + 1, col + 1] if sobel_grad[row, col] >= NW and sobel_grad[row, col] >= SE: dst[row, col] = sobel_grad[row, col] """ High-Low threshold detection. If an edge pixel’s gradient value is higher than the high threshold value, it is marked as a strong edge pixel. If an edge pixel’s gradient value is smaller than the high threshold value and larger than the low threshold value, it is marked as a weak edge pixel. If an edge pixel's value is smaller than the low threshold value, it will be suppressed. """ if dst[row, col] >= threshold_high: dst[row, col] = strong elif dst[row, col] <= threshold_low: dst[row, col] = 0 else: dst[row, col] = weak """ Edge tracking. Usually a weak edge pixel caused from true edges will be connected to a strong edge pixel while noise responses are unconnected. As long as there is one strong edge pixel that is involved in its 8-connected neighborhood, that weak edge point can be identified as one that should be preserved. """ for row in range(1, image_row): for col in range(1, image_col): if dst[row, col] == weak: if 255 in ( dst[row, col + 1], dst[row, col - 1], dst[row - 1, col], dst[row + 1, col], dst[row - 1, col - 1], dst[row + 1, col - 1], dst[row - 1, col + 1], dst[row + 1, col + 1], ): dst[row, col] = strong else: dst[row, col] = 0 return dst if __name__ == "__main__": # read original image in gray mode lena = cv2.imread(r"../image_data/lena.jpg", 0) # canny edge detection canny_dst = canny(lena) cv2.imshow("canny", canny_dst) cv2.waitKey(0)
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Project Euler Problem 5: https://projecteuler.net/problem=5 Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is _evenly divisible_ by all of the numbers from 1 to 20? References: - https://en.wiktionary.org/wiki/evenly_divisible - https://en.wikipedia.org/wiki/Euclidean_algorithm - https://en.wikipedia.org/wiki/Least_common_multiple """ def gcd(x: int, y: int) -> int: """ Euclidean GCD algorithm (Greatest Common Divisor) >>> gcd(0, 0) 0 >>> gcd(23, 42) 1 >>> gcd(15, 33) 3 >>> gcd(12345, 67890) 15 """ return x if y == 0 else gcd(y, x % y) def lcm(x: int, y: int) -> int: """ Least Common Multiple. Using the property that lcm(a, b) * gcd(a, b) = a*b >>> lcm(3, 15) 15 >>> lcm(1, 27) 27 >>> lcm(13, 27) 351 >>> lcm(64, 48) 192 """ return (x * y) // gcd(x, y) def solution(n: int = 20) -> int: """ Returns the smallest positive number that is evenly divisible (divisible with no remainder) by all of the numbers from 1 to n. >>> solution(10) 2520 >>> solution(15) 360360 >>> solution(22) 232792560 """ g = 1 for i in range(1, n + 1): g = lcm(g, i) return g if __name__ == "__main__": print(f"{solution() = }")
""" Project Euler Problem 5: https://projecteuler.net/problem=5 Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is _evenly divisible_ by all of the numbers from 1 to 20? References: - https://en.wiktionary.org/wiki/evenly_divisible - https://en.wikipedia.org/wiki/Euclidean_algorithm - https://en.wikipedia.org/wiki/Least_common_multiple """ def gcd(x: int, y: int) -> int: """ Euclidean GCD algorithm (Greatest Common Divisor) >>> gcd(0, 0) 0 >>> gcd(23, 42) 1 >>> gcd(15, 33) 3 >>> gcd(12345, 67890) 15 """ return x if y == 0 else gcd(y, x % y) def lcm(x: int, y: int) -> int: """ Least Common Multiple. Using the property that lcm(a, b) * gcd(a, b) = a*b >>> lcm(3, 15) 15 >>> lcm(1, 27) 27 >>> lcm(13, 27) 351 >>> lcm(64, 48) 192 """ return (x * y) // gcd(x, y) def solution(n: int = 20) -> int: """ Returns the smallest positive number that is evenly divisible (divisible with no remainder) by all of the numbers from 1 to n. >>> solution(10) 2520 >>> solution(15) 360360 >>> solution(22) 232792560 """ g = 1 for i in range(1, n + 1): g = lcm(g, i) return g if __name__ == "__main__": print(f"{solution() = }")
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Hey, we are going to find an exciting number called Catalan number which is use to find the number of possible binary search trees from tree of a given number of nodes. We will use the formula: t(n) = SUMMATION(i = 1 to n)t(i-1)t(n-i) Further details at Wikipedia: https://en.wikipedia.org/wiki/Catalan_number """ """ Our Contribution: Basically we Create the 2 function: 1. catalan_number(node_count: int) -> int Returns the number of possible binary search trees for n nodes. 2. binary_tree_count(node_count: int) -> int Returns the number of possible binary trees for n nodes. """ def binomial_coefficient(n: int, k: int) -> int: """ Since Here we Find the Binomial Coefficient: https://en.wikipedia.org/wiki/Binomial_coefficient C(n,k) = n! / k!(n-k)! :param n: 2 times of Number of nodes :param k: Number of nodes :return: Integer Value >>> binomial_coefficient(4, 2) 6 """ result = 1 # To kept the Calculated Value # Since C(n, k) = C(n, n-k) if k > (n - k): k = n - k # Calculate C(n,k) for i in range(k): result *= n - i result //= i + 1 return result def catalan_number(node_count: int) -> int: """ We can find Catalan number many ways but here we use Binomial Coefficient because it does the job in O(n) return the Catalan number of n using 2nCn/(n+1). :param n: number of nodes :return: Catalan number of n nodes >>> catalan_number(5) 42 >>> catalan_number(6) 132 """ return binomial_coefficient(2 * node_count, node_count) // (node_count + 1) def factorial(n: int) -> int: """ Return the factorial of a number. :param n: Number to find the Factorial of. :return: Factorial of n. >>> import math >>> all(factorial(i) == math.factorial(i) for i in range(10)) True >>> factorial(-5) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: factorial() not defined for negative values """ if n < 0: raise ValueError("factorial() not defined for negative values") result = 1 for i in range(1, n + 1): result *= i return result def binary_tree_count(node_count: int) -> int: """ Return the number of possible of binary trees. :param n: number of nodes :return: Number of possible binary trees >>> binary_tree_count(5) 5040 >>> binary_tree_count(6) 95040 """ return catalan_number(node_count) * factorial(node_count) if __name__ == "__main__": node_count = int(input("Enter the number of nodes: ").strip() or 0) if node_count <= 0: raise ValueError("We need some nodes to work with.") print( f"Given {node_count} nodes, there are {binary_tree_count(node_count)} " f"binary trees and {catalan_number(node_count)} binary search trees." )
""" Hey, we are going to find an exciting number called Catalan number which is use to find the number of possible binary search trees from tree of a given number of nodes. We will use the formula: t(n) = SUMMATION(i = 1 to n)t(i-1)t(n-i) Further details at Wikipedia: https://en.wikipedia.org/wiki/Catalan_number """ """ Our Contribution: Basically we Create the 2 function: 1. catalan_number(node_count: int) -> int Returns the number of possible binary search trees for n nodes. 2. binary_tree_count(node_count: int) -> int Returns the number of possible binary trees for n nodes. """ def binomial_coefficient(n: int, k: int) -> int: """ Since Here we Find the Binomial Coefficient: https://en.wikipedia.org/wiki/Binomial_coefficient C(n,k) = n! / k!(n-k)! :param n: 2 times of Number of nodes :param k: Number of nodes :return: Integer Value >>> binomial_coefficient(4, 2) 6 """ result = 1 # To kept the Calculated Value # Since C(n, k) = C(n, n-k) if k > (n - k): k = n - k # Calculate C(n,k) for i in range(k): result *= n - i result //= i + 1 return result def catalan_number(node_count: int) -> int: """ We can find Catalan number many ways but here we use Binomial Coefficient because it does the job in O(n) return the Catalan number of n using 2nCn/(n+1). :param n: number of nodes :return: Catalan number of n nodes >>> catalan_number(5) 42 >>> catalan_number(6) 132 """ return binomial_coefficient(2 * node_count, node_count) // (node_count + 1) def factorial(n: int) -> int: """ Return the factorial of a number. :param n: Number to find the Factorial of. :return: Factorial of n. >>> import math >>> all(factorial(i) == math.factorial(i) for i in range(10)) True >>> factorial(-5) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: factorial() not defined for negative values """ if n < 0: raise ValueError("factorial() not defined for negative values") result = 1 for i in range(1, n + 1): result *= i return result def binary_tree_count(node_count: int) -> int: """ Return the number of possible of binary trees. :param n: number of nodes :return: Number of possible binary trees >>> binary_tree_count(5) 5040 >>> binary_tree_count(6) 95040 """ return catalan_number(node_count) * factorial(node_count) if __name__ == "__main__": node_count = int(input("Enter the number of nodes: ").strip() or 0) if node_count <= 0: raise ValueError("We need some nodes to work with.") print( f"Given {node_count} nodes, there are {binary_tree_count(node_count)} " f"binary trees and {catalan_number(node_count)} binary search trees." )
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" This algorithm helps you to swap cases. User will give input and then program will perform swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa. For example: 1. Please input sentence: Algorithm.Python@89 aLGORITHM.pYTHON@89 2. Please input sentence: github.com/mayur200 GITHUB.COM/MAYUR200 """ def swap_case(sentence: str) -> str: """ This function will convert all lowercase letters to uppercase letters and vice versa. >>> swap_case('Algorithm.Python@89') 'aLGORITHM.pYTHON@89' """ new_string = "" for char in sentence: if char.isupper(): new_string += char.lower() elif char.islower(): new_string += char.upper() else: new_string += char return new_string if __name__ == "__main__": print(swap_case(input("Please input sentence: ")))
""" This algorithm helps you to swap cases. User will give input and then program will perform swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa. For example: 1. Please input sentence: Algorithm.Python@89 aLGORITHM.pYTHON@89 2. Please input sentence: github.com/mayur200 GITHUB.COM/MAYUR200 """ def swap_case(sentence: str) -> str: """ This function will convert all lowercase letters to uppercase letters and vice versa. >>> swap_case('Algorithm.Python@89') 'aLGORITHM.pYTHON@89' """ new_string = "" for char in sentence: if char.isupper(): new_string += char.lower() elif char.islower(): new_string += char.upper() else: new_string += char return new_string if __name__ == "__main__": print(swap_case(input("Please input sentence: ")))
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Problem 28 Url: https://projecteuler.net/problem=28 Statement: Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 It can be verified that the sum of the numbers on the diagonals is 101. What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way? """ from math import ceil def solution(n: int = 1001) -> int: """Returns the sum of the numbers on the diagonals in a n by n spiral formed in the same way. >>> solution(1001) 669171001 >>> solution(500) 82959497 >>> solution(100) 651897 >>> solution(50) 79697 >>> solution(10) 537 """ total = 1 for i in range(1, int(ceil(n / 2.0))): odd = 2 * i + 1 even = 2 * i total = total + 4 * odd ** 2 - 6 * even return total if __name__ == "__main__": import sys if len(sys.argv) == 1: print(solution()) else: try: n = int(sys.argv[1]) print(solution(n)) except ValueError: print("Invalid entry - please enter a number")
""" Problem 28 Url: https://projecteuler.net/problem=28 Statement: Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 It can be verified that the sum of the numbers on the diagonals is 101. What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way? """ from math import ceil def solution(n: int = 1001) -> int: """Returns the sum of the numbers on the diagonals in a n by n spiral formed in the same way. >>> solution(1001) 669171001 >>> solution(500) 82959497 >>> solution(100) 651897 >>> solution(50) 79697 >>> solution(10) 537 """ total = 1 for i in range(1, int(ceil(n / 2.0))): odd = 2 * i + 1 even = 2 * i total = total + 4 * odd ** 2 - 6 * even return total if __name__ == "__main__": import sys if len(sys.argv) == 1: print(solution()) else: try: n = int(sys.argv[1]) print(solution(n)) except ValueError: print("Invalid entry - please enter a number")
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from collections import deque from .hash_table import HashTable class HashTableWithLinkedList(HashTable): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _set_value(self, key, data): self.values[key] = deque([]) if self.values[key] is None else self.values[key] self.values[key].appendleft(data) self._keys[key] = self.values[key] def balanced_factor(self): return ( sum(self.charge_factor - len(slot) for slot in self.values) / self.size_table * self.charge_factor ) def _collision_resolution(self, key, data=None): if not ( len(self.values[key]) == self.charge_factor and self.values.count(None) == 0 ): return key return super()._collision_resolution(key, data)
from collections import deque from .hash_table import HashTable class HashTableWithLinkedList(HashTable): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _set_value(self, key, data): self.values[key] = deque([]) if self.values[key] is None else self.values[key] self.values[key].appendleft(data) self._keys[key] = self.values[key] def balanced_factor(self): return ( sum(self.charge_factor - len(slot) for slot in self.values) / self.size_table * self.charge_factor ) def _collision_resolution(self, key, data=None): if not ( len(self.values[key]) == self.charge_factor and self.values.count(None) == 0 ): return key return super()._collision_resolution(key, data)
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Problem 125: https://projecteuler.net/problem=125 The palindromic number 595 is interesting because it can be written as the sum of consecutive squares: 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2. There are exactly eleven palindromes below one-thousand that can be written as consecutive square sums, and the sum of these palindromes is 4164. Note that 1 = 0^2 + 1^2 has not been included as this problem is concerned with the squares of positive integers. Find the sum of all the numbers less than 10^8 that are both palindromic and can be written as the sum of consecutive squares. """ def is_palindrome(n: int) -> bool: """ Check if an integer is palindromic. >>> is_palindrome(12521) True >>> is_palindrome(12522) False >>> is_palindrome(12210) False """ if n % 10 == 0: return False s = str(n) return s == s[::-1] def solution() -> int: """ Returns the sum of all numbers less than 1e8 that are both palindromic and can be written as the sum of consecutive squares. """ LIMIT = 10 ** 8 answer = set() first_square = 1 sum_squares = 5 while sum_squares < LIMIT: last_square = first_square + 1 while sum_squares < LIMIT: if is_palindrome(sum_squares): answer.add(sum_squares) last_square += 1 sum_squares += last_square ** 2 first_square += 1 sum_squares = first_square ** 2 + (first_square + 1) ** 2 return sum(answer) if __name__ == "__main__": print(solution())
""" Problem 125: https://projecteuler.net/problem=125 The palindromic number 595 is interesting because it can be written as the sum of consecutive squares: 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2. There are exactly eleven palindromes below one-thousand that can be written as consecutive square sums, and the sum of these palindromes is 4164. Note that 1 = 0^2 + 1^2 has not been included as this problem is concerned with the squares of positive integers. Find the sum of all the numbers less than 10^8 that are both palindromic and can be written as the sum of consecutive squares. """ def is_palindrome(n: int) -> bool: """ Check if an integer is palindromic. >>> is_palindrome(12521) True >>> is_palindrome(12522) False >>> is_palindrome(12210) False """ if n % 10 == 0: return False s = str(n) return s == s[::-1] def solution() -> int: """ Returns the sum of all numbers less than 1e8 that are both palindromic and can be written as the sum of consecutive squares. """ LIMIT = 10 ** 8 answer = set() first_square = 1 sum_squares = 5 while sum_squares < LIMIT: last_square = first_square + 1 while sum_squares < LIMIT: if is_palindrome(sum_squares): answer.add(sum_squares) last_square += 1 sum_squares += last_square ** 2 first_square += 1 sum_squares = first_square ** 2 + (first_square + 1) ** 2 return sum(answer) if __name__ == "__main__": print(solution())
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
# https://en.wikipedia.org/wiki/Hill_climbing import math class SearchProblem: """ An interface to define search problems. The interface will be illustrated using the example of mathematical function. """ def __init__(self, x: int, y: int, step_size: int, function_to_optimize): """ The constructor of the search problem. x: the x coordinate of the current search state. y: the y coordinate of the current search state. step_size: size of the step to take when looking for neighbors. function_to_optimize: a function to optimize having the signature f(x, y). """ self.x = x self.y = y self.step_size = step_size self.function = function_to_optimize def score(self) -> int: """ Returns the output of the function called with current x and y coordinates. >>> def test_function(x, y): ... return x + y >>> SearchProblem(0, 0, 1, test_function).score() # 0 + 0 = 0 0 >>> SearchProblem(5, 7, 1, test_function).score() # 5 + 7 = 12 12 """ return self.function(self.x, self.y) def get_neighbors(self): """ Returns a list of coordinates of neighbors adjacent to the current coordinates. Neighbors: | 0 | 1 | 2 | | 3 | _ | 4 | | 5 | 6 | 7 | """ step_size = self.step_size return [ SearchProblem(x, y, step_size, self.function) for x, y in ( (self.x - step_size, self.y - step_size), (self.x - step_size, self.y), (self.x - step_size, self.y + step_size), (self.x, self.y - step_size), (self.x, self.y + step_size), (self.x + step_size, self.y - step_size), (self.x + step_size, self.y), (self.x + step_size, self.y + step_size), ) ] def __hash__(self): """ hash the string representation of the current search state. """ return hash(str(self)) def __eq__(self, obj): """ Check if the 2 objects are equal. """ if isinstance(obj, SearchProblem): return hash(str(self)) == hash(str(obj)) return False def __str__(self): """ string representation of the current search state. >>> str(SearchProblem(0, 0, 1, None)) 'x: 0 y: 0' >>> str(SearchProblem(2, 5, 1, None)) 'x: 2 y: 5' """ return f"x: {self.x} y: {self.y}" def hill_climbing( search_prob, find_max: bool = True, max_x: float = math.inf, min_x: float = -math.inf, max_y: float = math.inf, min_y: float = -math.inf, visualization: bool = False, max_iter: int = 10000, ) -> SearchProblem: """ Implementation of the hill climbling algorithm. We start with a given state, find all its neighbors, move towards the neighbor which provides the maximum (or minimum) change. We keep doing this until we are at a state where we do not have any neighbors which can improve the solution. Args: search_prob: The search state at the start. find_max: If True, the algorithm should find the maximum else the minimum. max_x, min_x, max_y, min_y: the maximum and minimum bounds of x and y. visualization: If True, a matplotlib graph is displayed. max_iter: number of times to run the iteration. Returns a search state having the maximum (or minimum) score. """ current_state = search_prob scores = [] # list to store the current score at each iteration iterations = 0 solution_found = False visited = set() while not solution_found and iterations < max_iter: visited.add(current_state) iterations += 1 current_score = current_state.score() scores.append(current_score) neighbors = current_state.get_neighbors() max_change = -math.inf min_change = math.inf next_state = None # to hold the next best neighbor for neighbor in neighbors: if neighbor in visited: continue # do not want to visit the same state again if ( neighbor.x > max_x or neighbor.x < min_x or neighbor.y > max_y or neighbor.y < min_y ): continue # neighbor outside our bounds change = neighbor.score() - current_score if find_max: # finding max # going to direction with greatest ascent if change > max_change and change > 0: max_change = change next_state = neighbor else: # finding min # to direction with greatest descent if change < min_change and change < 0: min_change = change next_state = neighbor if next_state is not None: # we found at least one neighbor which improved the current state current_state = next_state else: # since we have no neighbor that improves the solution we stop the search solution_found = True if visualization: from matplotlib import pyplot as plt plt.plot(range(iterations), scores) plt.xlabel("Iterations") plt.ylabel("Function values") plt.show() return current_state if __name__ == "__main__": import doctest doctest.testmod() def test_f1(x, y): return (x ** 2) + (y ** 2) # starting the problem with initial coordinates (3, 4) prob = SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_f1) local_min = hill_climbing(prob, find_max=False) print( "The minimum score for f(x, y) = x^2 + y^2 found via hill climbing: " f"{local_min.score()}" ) # starting the problem with initial coordinates (12, 47) prob = SearchProblem(x=12, y=47, step_size=1, function_to_optimize=test_f1) local_min = hill_climbing( prob, find_max=False, max_x=100, min_x=5, max_y=50, min_y=-5, visualization=True ) print( "The minimum score for f(x, y) = x^2 + y^2 with the domain 100 > x > 5 " f"and 50 > y > - 5 found via hill climbing: {local_min.score()}" ) def test_f2(x, y): return (3 * x ** 2) - (6 * y) prob = SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_f1) local_min = hill_climbing(prob, find_max=True) print( "The maximum score for f(x, y) = x^2 + y^2 found via hill climbing: " f"{local_min.score()}" )
# https://en.wikipedia.org/wiki/Hill_climbing import math class SearchProblem: """ An interface to define search problems. The interface will be illustrated using the example of mathematical function. """ def __init__(self, x: int, y: int, step_size: int, function_to_optimize): """ The constructor of the search problem. x: the x coordinate of the current search state. y: the y coordinate of the current search state. step_size: size of the step to take when looking for neighbors. function_to_optimize: a function to optimize having the signature f(x, y). """ self.x = x self.y = y self.step_size = step_size self.function = function_to_optimize def score(self) -> int: """ Returns the output of the function called with current x and y coordinates. >>> def test_function(x, y): ... return x + y >>> SearchProblem(0, 0, 1, test_function).score() # 0 + 0 = 0 0 >>> SearchProblem(5, 7, 1, test_function).score() # 5 + 7 = 12 12 """ return self.function(self.x, self.y) def get_neighbors(self): """ Returns a list of coordinates of neighbors adjacent to the current coordinates. Neighbors: | 0 | 1 | 2 | | 3 | _ | 4 | | 5 | 6 | 7 | """ step_size = self.step_size return [ SearchProblem(x, y, step_size, self.function) for x, y in ( (self.x - step_size, self.y - step_size), (self.x - step_size, self.y), (self.x - step_size, self.y + step_size), (self.x, self.y - step_size), (self.x, self.y + step_size), (self.x + step_size, self.y - step_size), (self.x + step_size, self.y), (self.x + step_size, self.y + step_size), ) ] def __hash__(self): """ hash the string representation of the current search state. """ return hash(str(self)) def __eq__(self, obj): """ Check if the 2 objects are equal. """ if isinstance(obj, SearchProblem): return hash(str(self)) == hash(str(obj)) return False def __str__(self): """ string representation of the current search state. >>> str(SearchProblem(0, 0, 1, None)) 'x: 0 y: 0' >>> str(SearchProblem(2, 5, 1, None)) 'x: 2 y: 5' """ return f"x: {self.x} y: {self.y}" def hill_climbing( search_prob, find_max: bool = True, max_x: float = math.inf, min_x: float = -math.inf, max_y: float = math.inf, min_y: float = -math.inf, visualization: bool = False, max_iter: int = 10000, ) -> SearchProblem: """ Implementation of the hill climbling algorithm. We start with a given state, find all its neighbors, move towards the neighbor which provides the maximum (or minimum) change. We keep doing this until we are at a state where we do not have any neighbors which can improve the solution. Args: search_prob: The search state at the start. find_max: If True, the algorithm should find the maximum else the minimum. max_x, min_x, max_y, min_y: the maximum and minimum bounds of x and y. visualization: If True, a matplotlib graph is displayed. max_iter: number of times to run the iteration. Returns a search state having the maximum (or minimum) score. """ current_state = search_prob scores = [] # list to store the current score at each iteration iterations = 0 solution_found = False visited = set() while not solution_found and iterations < max_iter: visited.add(current_state) iterations += 1 current_score = current_state.score() scores.append(current_score) neighbors = current_state.get_neighbors() max_change = -math.inf min_change = math.inf next_state = None # to hold the next best neighbor for neighbor in neighbors: if neighbor in visited: continue # do not want to visit the same state again if ( neighbor.x > max_x or neighbor.x < min_x or neighbor.y > max_y or neighbor.y < min_y ): continue # neighbor outside our bounds change = neighbor.score() - current_score if find_max: # finding max # going to direction with greatest ascent if change > max_change and change > 0: max_change = change next_state = neighbor else: # finding min # to direction with greatest descent if change < min_change and change < 0: min_change = change next_state = neighbor if next_state is not None: # we found at least one neighbor which improved the current state current_state = next_state else: # since we have no neighbor that improves the solution we stop the search solution_found = True if visualization: from matplotlib import pyplot as plt plt.plot(range(iterations), scores) plt.xlabel("Iterations") plt.ylabel("Function values") plt.show() return current_state if __name__ == "__main__": import doctest doctest.testmod() def test_f1(x, y): return (x ** 2) + (y ** 2) # starting the problem with initial coordinates (3, 4) prob = SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_f1) local_min = hill_climbing(prob, find_max=False) print( "The minimum score for f(x, y) = x^2 + y^2 found via hill climbing: " f"{local_min.score()}" ) # starting the problem with initial coordinates (12, 47) prob = SearchProblem(x=12, y=47, step_size=1, function_to_optimize=test_f1) local_min = hill_climbing( prob, find_max=False, max_x=100, min_x=5, max_y=50, min_y=-5, visualization=True ) print( "The minimum score for f(x, y) = x^2 + y^2 with the domain 100 > x > 5 " f"and 50 > y > - 5 found via hill climbing: {local_min.score()}" ) def test_f2(x, y): return (3 * x ** 2) - (6 * y) prob = SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_f1) local_min = hill_climbing(prob, find_max=True) print( "The maximum score for f(x, y) = x^2 + y^2 found via hill climbing: " f"{local_min.score()}" )
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" == Krishnamurthy Number == It is also known as Peterson Number A Krishnamurthy Number is a number whose sum of the factorial of the digits equals to the original number itself. For example: 145 = 1! + 4! + 5! So, 145 is a Krishnamurthy Number """ def factorial(digit: int) -> int: """ >>> factorial(3) 6 >>> factorial(0) 1 >>> factorial(5) 120 """ return 1 if digit in (0, 1) else (digit * factorial(digit - 1)) def krishnamurthy(number: int) -> bool: """ >>> krishnamurthy(145) True >>> krishnamurthy(240) False >>> krishnamurthy(1) True """ factSum = 0 duplicate = number while duplicate > 0: duplicate, digit = divmod(duplicate, 10) factSum += factorial(digit) return factSum == number if __name__ == "__main__": print("Program to check whether a number is a Krisnamurthy Number or not.") number = int(input("Enter number: ").strip()) print( f"{number} is {'' if krishnamurthy(number) else 'not '}a Krishnamurthy Number." )
""" == Krishnamurthy Number == It is also known as Peterson Number A Krishnamurthy Number is a number whose sum of the factorial of the digits equals to the original number itself. For example: 145 = 1! + 4! + 5! So, 145 is a Krishnamurthy Number """ def factorial(digit: int) -> int: """ >>> factorial(3) 6 >>> factorial(0) 1 >>> factorial(5) 120 """ return 1 if digit in (0, 1) else (digit * factorial(digit - 1)) def krishnamurthy(number: int) -> bool: """ >>> krishnamurthy(145) True >>> krishnamurthy(240) False >>> krishnamurthy(1) True """ factSum = 0 duplicate = number while duplicate > 0: duplicate, digit = divmod(duplicate, 10) factSum += factorial(digit) return factSum == number if __name__ == "__main__": print("Program to check whether a number is a Krisnamurthy Number or not.") number = int(input("Enter number: ").strip()) print( f"{number} is {'' if krishnamurthy(number) else 'not '}a Krishnamurthy Number." )
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" 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 system resolution for triangular matrix Examples: 2x1 + 2x2 - 1x3 = 5 2x1 + 2x2 = -1 0x1 - 2x2 - 1x3 = -7 0x1 - 2x2 = -1 0x1 + 0x2 + 5x3 = 15 >>> gaussian_elimination([[2, 2, -1], [0, -2, -1], [0, 0, 5]], [[5], [-7], [15]]) array([[2.], [2.], [3.]]) >>> gaussian_elimination([[2, 2], [0, -2]], [[-1], [-1]]) array([[-1. ], [ 0.5]]) """ rows, columns = np.shape(coefficients) x = np.zeros((rows, 1), dtype=float) for row in reversed(range(rows)): sum = 0 for col in range(row + 1, columns): sum += coefficients[row, col] * x[col] x[row, 0] = (vector[row] - sum) / coefficients[row, row] return x def gaussian_elimination(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray: """ This function performs Gaussian elimination method Examples: 1x1 - 4x2 - 2x3 = -2 1x1 + 2x2 = 5 5x1 + 2x2 - 2x3 = -3 5x1 + 2x2 = 5 1x1 - 1x2 + 0x3 = 4 >>> gaussian_elimination([[1, -4, -2], [5, 2, -2], [1, -1, 0]], [[-2], [-3], [4]]) array([[ 2.3 ], [-1.7 ], [ 5.55]]) >>> gaussian_elimination([[1, 2], [5, 2]], [[5], [5]]) array([[0. ], [2.5]]) """ # coefficients must to be a square matrix so we need to check first rows, columns = np.shape(coefficients) if rows != columns: return np.array((), dtype=float) # augmented matrix augmented_mat = np.concatenate((coefficients, vector), axis=1) augmented_mat = augmented_mat.astype("float64") # scale the matrix leaving it triangular for row in range(rows - 1): pivot = augmented_mat[row, row] for col in range(row + 1, columns): factor = augmented_mat[col, row] / pivot augmented_mat[col, :] -= factor * augmented_mat[row, :] x = retroactive_resolution( augmented_mat[:, 0:columns], augmented_mat[:, columns : columns + 1] ) return x if __name__ == "__main__": import doctest doctest.testmod()
""" 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 system resolution for triangular matrix Examples: 2x1 + 2x2 - 1x3 = 5 2x1 + 2x2 = -1 0x1 - 2x2 - 1x3 = -7 0x1 - 2x2 = -1 0x1 + 0x2 + 5x3 = 15 >>> gaussian_elimination([[2, 2, -1], [0, -2, -1], [0, 0, 5]], [[5], [-7], [15]]) array([[2.], [2.], [3.]]) >>> gaussian_elimination([[2, 2], [0, -2]], [[-1], [-1]]) array([[-1. ], [ 0.5]]) """ rows, columns = np.shape(coefficients) x = np.zeros((rows, 1), dtype=float) for row in reversed(range(rows)): sum = 0 for col in range(row + 1, columns): sum += coefficients[row, col] * x[col] x[row, 0] = (vector[row] - sum) / coefficients[row, row] return x def gaussian_elimination(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray: """ This function performs Gaussian elimination method Examples: 1x1 - 4x2 - 2x3 = -2 1x1 + 2x2 = 5 5x1 + 2x2 - 2x3 = -3 5x1 + 2x2 = 5 1x1 - 1x2 + 0x3 = 4 >>> gaussian_elimination([[1, -4, -2], [5, 2, -2], [1, -1, 0]], [[-2], [-3], [4]]) array([[ 2.3 ], [-1.7 ], [ 5.55]]) >>> gaussian_elimination([[1, 2], [5, 2]], [[5], [5]]) array([[0. ], [2.5]]) """ # coefficients must to be a square matrix so we need to check first rows, columns = np.shape(coefficients) if rows != columns: return np.array((), dtype=float) # augmented matrix augmented_mat = np.concatenate((coefficients, vector), axis=1) augmented_mat = augmented_mat.astype("float64") # scale the matrix leaving it triangular for row in range(rows - 1): pivot = augmented_mat[row, row] for col in range(row + 1, columns): factor = augmented_mat[col, row] / pivot augmented_mat[col, :] -= factor * augmented_mat[row, :] x = retroactive_resolution( augmented_mat[:, 0:columns], augmented_mat[:, columns : columns + 1] ) return x if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Functions useful for doing molecular chemistry: * molarity_to_normality * moles_to_pressure * moles_to_volume * pressure_and_volume_to_temperature """ def molarity_to_normality(nfactor: int, moles: float, volume: float) -> float: """ Convert molarity to normality. Volume is taken in litres. Wikipedia reference: https://en.wikipedia.org/wiki/Equivalent_concentration Wikipedia reference: https://en.wikipedia.org/wiki/Molar_concentration >>> molarity_to_normality(2, 3.1, 0.31) 20 >>> molarity_to_normality(4, 11.4, 5.7) 8 """ return round(float(moles / volume) * nfactor) def moles_to_pressure(volume: float, moles: float, temperature: float) -> float: """ Convert moles to pressure. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure has atm as SI unit. Wikipedia reference: https://en.wikipedia.org/wiki/Gas_laws Wikipedia reference: https://en.wikipedia.org/wiki/Pressure Wikipedia reference: https://en.wikipedia.org/wiki/Temperature >>> moles_to_pressure(0.82, 3, 300) 90 >>> moles_to_pressure(8.2, 5, 200) 10 """ return round(float((moles * 0.0821 * temperature) / (volume))) def moles_to_volume(pressure: float, moles: float, temperature: float) -> float: """ Convert moles to volume. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure has atm as SI unit. Wikipedia reference: https://en.wikipedia.org/wiki/Gas_laws Wikipedia reference: https://en.wikipedia.org/wiki/Pressure Wikipedia reference: https://en.wikipedia.org/wiki/Temperature >>> moles_to_volume(0.82, 3, 300) 90 >>> moles_to_volume(8.2, 5, 200) 10 """ return round(float((moles * 0.0821 * temperature) / (pressure))) def pressure_and_volume_to_temperature( pressure: float, moles: float, volume: float ) -> float: """ Convert pressure and volume to temperature. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure has atm as SI unit. Wikipedia reference: https://en.wikipedia.org/wiki/Gas_laws Wikipedia reference: https://en.wikipedia.org/wiki/Pressure Wikipedia reference: https://en.wikipedia.org/wiki/Temperature >>> pressure_and_volume_to_temperature(0.82, 1, 2) 20 >>> pressure_and_volume_to_temperature(8.2, 5, 3) 60 """ return round(float((pressure * volume) / (0.0821 * moles))) if __name__ == "__main__": import doctest doctest.testmod()
""" Functions useful for doing molecular chemistry: * molarity_to_normality * moles_to_pressure * moles_to_volume * pressure_and_volume_to_temperature """ def molarity_to_normality(nfactor: int, moles: float, volume: float) -> float: """ Convert molarity to normality. Volume is taken in litres. Wikipedia reference: https://en.wikipedia.org/wiki/Equivalent_concentration Wikipedia reference: https://en.wikipedia.org/wiki/Molar_concentration >>> molarity_to_normality(2, 3.1, 0.31) 20 >>> molarity_to_normality(4, 11.4, 5.7) 8 """ return round(float(moles / volume) * nfactor) def moles_to_pressure(volume: float, moles: float, temperature: float) -> float: """ Convert moles to pressure. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure has atm as SI unit. Wikipedia reference: https://en.wikipedia.org/wiki/Gas_laws Wikipedia reference: https://en.wikipedia.org/wiki/Pressure Wikipedia reference: https://en.wikipedia.org/wiki/Temperature >>> moles_to_pressure(0.82, 3, 300) 90 >>> moles_to_pressure(8.2, 5, 200) 10 """ return round(float((moles * 0.0821 * temperature) / (volume))) def moles_to_volume(pressure: float, moles: float, temperature: float) -> float: """ Convert moles to volume. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure has atm as SI unit. Wikipedia reference: https://en.wikipedia.org/wiki/Gas_laws Wikipedia reference: https://en.wikipedia.org/wiki/Pressure Wikipedia reference: https://en.wikipedia.org/wiki/Temperature >>> moles_to_volume(0.82, 3, 300) 90 >>> moles_to_volume(8.2, 5, 200) 10 """ return round(float((moles * 0.0821 * temperature) / (pressure))) def pressure_and_volume_to_temperature( pressure: float, moles: float, volume: float ) -> float: """ Convert pressure and volume to temperature. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure has atm as SI unit. Wikipedia reference: https://en.wikipedia.org/wiki/Gas_laws Wikipedia reference: https://en.wikipedia.org/wiki/Pressure Wikipedia reference: https://en.wikipedia.org/wiki/Temperature >>> pressure_and_volume_to_temperature(0.82, 1, 2) 20 >>> pressure_and_volume_to_temperature(8.2, 5, 3) 60 """ return round(float((pressure * volume) / (0.0821 * moles))) if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
"""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(password_generator(257)) 257 >>> len(password_generator(length=0)) 0 >>> len(password_generator(-1)) 0 """ chars = ascii_letters + digits + punctuation return "".join(choice(chars) for x in range(length)) # ALTERNATIVE METHODS # ctbi= characters that must be in password # i= how many letters or characters the password length will be def alternative_password_generator(ctbi, i): # Password generator = full boot with random_number, random_letters, and # random_character FUNCTIONS # Put your code here... i = i - len(ctbi) quotient = int(i / 3) remainder = i % 3 # chars = ctbi + random_letters(ascii_letters, i / 3 + remainder) + # random_number(digits, i / 3) + random_characters(punctuation, i / 3) chars = ( ctbi + random(ascii_letters, quotient + remainder) + random(digits, quotient) + random(punctuation, quotient) ) chars = list(chars) shuffle(chars) return "".join(chars) # random is a generalised function for letters, characters and numbers def random(ctbi, i): return "".join(choice(ctbi) for x in range(i)) def random_number(ctbi, i): pass # Put your code here... def random_letters(ctbi, i): pass # Put your code here... def random_characters(ctbi, i): pass # Put your code here... def main(): length = int(input("Please indicate the max length of your password: ").strip()) ctbi = input( "Please indicate the characters that must be in your password: " ).strip() print("Password generated:", password_generator(length)) print( "Alternative Password generated:", alternative_password_generator(ctbi, length) ) print("[If you are thinking of using this passsword, You better save it.]") if __name__ == "__main__": main()
"""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(password_generator(257)) 257 >>> len(password_generator(length=0)) 0 >>> len(password_generator(-1)) 0 """ chars = ascii_letters + digits + punctuation return "".join(choice(chars) for x in range(length)) # ALTERNATIVE METHODS # ctbi= characters that must be in password # i= how many letters or characters the password length will be def alternative_password_generator(ctbi, i): # Password generator = full boot with random_number, random_letters, and # random_character FUNCTIONS # Put your code here... i = i - len(ctbi) quotient = int(i / 3) remainder = i % 3 # chars = ctbi + random_letters(ascii_letters, i / 3 + remainder) + # random_number(digits, i / 3) + random_characters(punctuation, i / 3) chars = ( ctbi + random(ascii_letters, quotient + remainder) + random(digits, quotient) + random(punctuation, quotient) ) chars = list(chars) shuffle(chars) return "".join(chars) # random is a generalised function for letters, characters and numbers def random(ctbi, i): return "".join(choice(ctbi) for x in range(i)) def random_number(ctbi, i): pass # Put your code here... def random_letters(ctbi, i): pass # Put your code here... def random_characters(ctbi, i): pass # Put your code here... def main(): length = int(input("Please indicate the max length of your password: ").strip()) ctbi = input( "Please indicate the characters that must be in your password: " ).strip() print("Password generated:", password_generator(length)) print( "Alternative Password generated:", alternative_password_generator(ctbi, length) ) print("[If you are thinking of using this passsword, You better save it.]") if __name__ == "__main__": main()
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" This is pure Python implementation of linear search algorithm For doctests run following command: python3 -m doctest -v linear_search.py For manual testing run: python3 linear_search.py """ def linear_search(sequence: list, target: int) -> int: """A pure Python implementation of a linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param target: item value to search :return: index of found item or None if item is not found Examples: >>> linear_search([0, 5, 7, 10, 15], 0) 0 >>> linear_search([0, 5, 7, 10, 15], 15) 4 >>> linear_search([0, 5, 7, 10, 15], 5) 1 >>> linear_search([0, 5, 7, 10, 15], 6) -1 """ for index, item in enumerate(sequence): if item == target: return index return -1 def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int: """ A pure Python implementation of a recursive linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param low: Lower bound of the array :param high: Higher bound of the array :param target: The element to be found :return: Index of the key or -1 if key not found Examples: >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 0) 0 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 700) 4 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 30) 1 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, -6) -1 """ if not (0 <= high < len(sequence) and 0 <= low < len(sequence)): raise Exception("Invalid upper or lower bound!") if high < low: return -1 if sequence[low] == target: return low if sequence[high] == target: return high return rec_linear_search(sequence, low + 1, high - 1, target) if __name__ == "__main__": user_input = input("Enter numbers separated by comma:\n").strip() sequence = [int(item.strip()) for item in user_input.split(",")] target = int(input("Enter a single number to be found in the list:\n").strip()) result = linear_search(sequence, target) if result != -1: print(f"linear_search({sequence}, {target}) = {result}") else: print(f"{target} was not found in {sequence}")
""" This is pure Python implementation of linear search algorithm For doctests run following command: python3 -m doctest -v linear_search.py For manual testing run: python3 linear_search.py """ def linear_search(sequence: list, target: int) -> int: """A pure Python implementation of a linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param target: item value to search :return: index of found item or None if item is not found Examples: >>> linear_search([0, 5, 7, 10, 15], 0) 0 >>> linear_search([0, 5, 7, 10, 15], 15) 4 >>> linear_search([0, 5, 7, 10, 15], 5) 1 >>> linear_search([0, 5, 7, 10, 15], 6) -1 """ for index, item in enumerate(sequence): if item == target: return index return -1 def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int: """ A pure Python implementation of a recursive linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param low: Lower bound of the array :param high: Higher bound of the array :param target: The element to be found :return: Index of the key or -1 if key not found Examples: >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 0) 0 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 700) 4 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 30) 1 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, -6) -1 """ if not (0 <= high < len(sequence) and 0 <= low < len(sequence)): raise Exception("Invalid upper or lower bound!") if high < low: return -1 if sequence[low] == target: return low if sequence[high] == target: return high return rec_linear_search(sequence, low + 1, high - 1, target) if __name__ == "__main__": user_input = input("Enter numbers separated by comma:\n").strip() sequence = [int(item.strip()) for item in user_input.split(",")] target = int(input("Enter a single number to be found in the list:\n").strip()) result = linear_search(sequence, target) if result != -1: print(f"linear_search({sequence}, {target}) = {result}") else: print(f"{target} was not found in {sequence}")
-1
TheAlgorithms/Python
4,928
Fix word typos in comments
### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
sarvesh4396
2021-10-02T18:54:17Z
2021-10-04T04:07:58Z
d530d2bcf42391a8172c720e8d7c7d354a748abf
90db98304e06a60a3c578e9f55fe139524a4c3f8
Fix word typos in comments. ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" 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 the product a*b*c. References: - https://en.wikipedia.org/wiki/Pythagorean_triple """ def solution(n: int = 1000) -> int: """ Return the product of a,b,c which are Pythagorean Triplet that satisfies the following: 1. a < b < c 2. a**2 + b**2 = c**2 3. a + b + c = n >>> solution(36) 1620 >>> solution(126) 66780 """ product = -1 candidate = 0 for a in range(1, n // 3): # Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c b = (n * n - 2 * a * n) // (2 * n - 2 * a) c = n - a - b if c * c == (a * a + b * b): candidate = a * b * c if candidate >= product: product = candidate return product if __name__ == "__main__": print(f"{solution() = }")
""" 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 the product a*b*c. References: - https://en.wikipedia.org/wiki/Pythagorean_triple """ def solution(n: int = 1000) -> int: """ Return the product of a,b,c which are Pythagorean Triplet that satisfies the following: 1. a < b < c 2. a**2 + b**2 = c**2 3. a + b + c = n >>> solution(36) 1620 >>> solution(126) 66780 """ product = -1 candidate = 0 for a in range(1, n // 3): # Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c b = (n * n - 2 * a * n) // (2 * n - 2 * a) c = n - a - b if c * c == (a * a + b * b): candidate = a * b * c if candidate >= product: product = candidate return product if __name__ == "__main__": print(f"{solution() = }")
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Linked Lists consists of Nodes. Nodes contain data and also may link to other nodes: - Head Node: First node, the address of the head node gives us access of the complete list - Last node: points to null """ from typing import Any class Node: def __init__(self, item: Any, next: Any) -> None: self.item = item self.next = next class LinkedList: def __init__(self) -> None: self.head = None self.size = 0 def add(self, item: Any) -> None: self.head = Node(item, self.head) self.size += 1 def remove(self) -> Any: if self.is_empty(): return None else: item = self.head.item self.head = self.head.next self.size -= 1 return item def is_empty(self) -> bool: return self.head is None def __str__(self) -> str: """ >>> linked_list = LinkedList() >>> linked_list.add(23) >>> linked_list.add(14) >>> linked_list.add(9) >>> print(linked_list) 9 --> 14 --> 23 """ if not self.is_empty: return "" else: iterate = self.head item_str = "" item_list = [] while iterate: item_list.append(str(iterate.item)) iterate = iterate.next item_str = " --> ".join(item_list) return item_str def __len__(self) -> int: """ >>> linked_list = LinkedList() >>> len(linked_list) 0 >>> linked_list.add("a") >>> len(linked_list) 1 >>> linked_list.add("b") >>> len(linked_list) 2 >>> _ = linked_list.remove() >>> len(linked_list) 1 >>> _ = linked_list.remove() >>> len(linked_list) 0 """ return self.size
""" Linked Lists consists of Nodes. Nodes contain data and also may link to other nodes: - Head Node: First node, the address of the head node gives us access of the complete list - Last node: points to null """ from typing import Any, Optional class Node: def __init__(self, item: Any, next: Any) -> None: self.item = item self.next = next class LinkedList: def __init__(self) -> None: self.head: Optional[Node] = None self.size = 0 def add(self, item: Any) -> None: self.head = Node(item, self.head) self.size += 1 def remove(self) -> Any: # Switched 'self.is_empty()' to 'self.head is None' # because mypy was considering the possibility that 'self.head' # can be None in below else part and giving error if self.head is None: return None else: item = self.head.item self.head = self.head.next self.size -= 1 return item def is_empty(self) -> bool: return self.head is None def __str__(self) -> str: """ >>> linked_list = LinkedList() >>> linked_list.add(23) >>> linked_list.add(14) >>> linked_list.add(9) >>> print(linked_list) 9 --> 14 --> 23 """ if not self.is_empty: return "" else: iterate = self.head item_str = "" item_list: list[str] = [] while iterate: item_list.append(str(iterate.item)) iterate = iterate.next item_str = " --> ".join(item_list) return item_str def __len__(self) -> int: """ >>> linked_list = LinkedList() >>> len(linked_list) 0 >>> linked_list.add("a") >>> len(linked_list) 1 >>> linked_list.add("b") >>> len(linked_list) 2 >>> _ = linked_list.remove() >>> len(linked_list) 1 >>> _ = linked_list.remove() >>> len(linked_list) 0 """ return self.size
1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from typing import Any class Node: def __init__(self, data: Any): self.data = data self.next = None class CircularLinkedList: def __init__(self): self.head = None self.tail = None def __iter__(self): node = self.head while self.head: yield node.data node = node.next if node == self.head: break def __len__(self) -> int: return len(tuple(iter(self))) def __repr__(self): return "->".join(str(item) for item in iter(self)) def insert_tail(self, data: Any) -> None: self.insert_nth(len(self), data) def insert_head(self, data: Any) -> None: self.insert_nth(0, data) def insert_nth(self, index: int, data: Any) -> None: if index < 0 or index > len(self): raise IndexError("list index out of range.") new_node = Node(data) if self.head is None: new_node.next = new_node # first node points itself self.tail = self.head = new_node elif index == 0: # insert at head new_node.next = self.head self.head = self.tail.next = new_node else: temp = self.head for _ in range(index - 1): temp = temp.next new_node.next = temp.next temp.next = new_node if index == len(self) - 1: # insert at tail self.tail = new_node def delete_front(self): return self.delete_nth(0) def delete_tail(self) -> None: return self.delete_nth(len(self) - 1) def delete_nth(self, index: int = 0): if not 0 <= index < len(self): raise IndexError("list index out of range.") delete_node = self.head if self.head == self.tail: # just one node self.head = self.tail = None elif index == 0: # delete head node self.tail.next = self.tail.next.next self.head = self.head.next else: temp = self.head for _ in range(index - 1): temp = temp.next delete_node = temp.next temp.next = temp.next.next if index == len(self) - 1: # delete at tail self.tail = temp return delete_node.data def is_empty(self): return len(self) == 0 def test_circular_linked_list() -> None: """ >>> test_circular_linked_list() """ circular_linked_list = CircularLinkedList() assert len(circular_linked_list) == 0 assert circular_linked_list.is_empty() is True assert str(circular_linked_list) == "" try: circular_linked_list.delete_front() assert False # This should not happen except IndexError: assert True # This should happen try: circular_linked_list.delete_tail() assert False # This should not happen except IndexError: assert True # This should happen try: circular_linked_list.delete_nth(-1) assert False except IndexError: assert True try: circular_linked_list.delete_nth(0) assert False except IndexError: assert True assert circular_linked_list.is_empty() is True for i in range(5): assert len(circular_linked_list) == i circular_linked_list.insert_nth(i, i + 1) assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 6)) circular_linked_list.insert_tail(6) assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 7)) circular_linked_list.insert_head(0) assert str(circular_linked_list) == "->".join(str(i) for i in range(0, 7)) assert circular_linked_list.delete_front() == 0 assert circular_linked_list.delete_tail() == 6 assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 6)) assert circular_linked_list.delete_nth(2) == 3 circular_linked_list.insert_nth(2, 3) assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 6)) assert circular_linked_list.is_empty() is False if __name__ == "__main__": import doctest doctest.testmod()
from typing import Any, Iterator, Optional class Node: def __init__(self, data: Any): self.data: Any = data self.next: Optional[Node] = None class CircularLinkedList: def __init__(self): self.head = None self.tail = None def __iter__(self) -> Iterator[Any]: node = self.head while self.head: yield node.data node = node.next if node == self.head: break def __len__(self) -> int: return len(tuple(iter(self))) def __repr__(self): return "->".join(str(item) for item in iter(self)) def insert_tail(self, data: Any) -> None: self.insert_nth(len(self), data) def insert_head(self, data: Any) -> None: self.insert_nth(0, data) def insert_nth(self, index: int, data: Any) -> None: if index < 0 or index > len(self): raise IndexError("list index out of range.") new_node = Node(data) if self.head is None: new_node.next = new_node # first node points itself self.tail = self.head = new_node elif index == 0: # insert at head new_node.next = self.head self.head = self.tail.next = new_node else: temp = self.head for _ in range(index - 1): temp = temp.next new_node.next = temp.next temp.next = new_node if index == len(self) - 1: # insert at tail self.tail = new_node def delete_front(self): return self.delete_nth(0) def delete_tail(self) -> Any: return self.delete_nth(len(self) - 1) def delete_nth(self, index: int = 0) -> Any: if not 0 <= index < len(self): raise IndexError("list index out of range.") delete_node = self.head if self.head == self.tail: # just one node self.head = self.tail = None elif index == 0: # delete head node self.tail.next = self.tail.next.next self.head = self.head.next else: temp = self.head for _ in range(index - 1): temp = temp.next delete_node = temp.next temp.next = temp.next.next if index == len(self) - 1: # delete at tail self.tail = temp return delete_node.data def is_empty(self) -> bool: return len(self) == 0 def test_circular_linked_list() -> None: """ >>> test_circular_linked_list() """ circular_linked_list = CircularLinkedList() assert len(circular_linked_list) == 0 assert circular_linked_list.is_empty() is True assert str(circular_linked_list) == "" try: circular_linked_list.delete_front() assert False # This should not happen except IndexError: assert True # This should happen try: circular_linked_list.delete_tail() assert False # This should not happen except IndexError: assert True # This should happen try: circular_linked_list.delete_nth(-1) assert False except IndexError: assert True try: circular_linked_list.delete_nth(0) assert False except IndexError: assert True assert circular_linked_list.is_empty() is True for i in range(5): assert len(circular_linked_list) == i circular_linked_list.insert_nth(i, i + 1) assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 6)) circular_linked_list.insert_tail(6) assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 7)) circular_linked_list.insert_head(0) assert str(circular_linked_list) == "->".join(str(i) for i in range(0, 7)) assert circular_linked_list.delete_front() == 0 assert circular_linked_list.delete_tail() == 6 assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 6)) assert circular_linked_list.delete_nth(2) == 3 circular_linked_list.insert_nth(2, 3) assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 6)) assert circular_linked_list.is_empty() is False if __name__ == "__main__": import doctest doctest.testmod()
1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from typing import Any class ContainsLoopError(Exception): pass class Node: def __init__(self, data: Any) -> None: self.data = data self.next_node = None def __iter__(self): node = self visited = [] while node: if node in visited: raise ContainsLoopError visited.append(node) yield node.data node = node.next_node @property def has_loop(self) -> bool: """ A loop is when the exact same Node appears more than once in a linked list. >>> root_node = Node(1) >>> root_node.next_node = Node(2) >>> root_node.next_node.next_node = Node(3) >>> root_node.next_node.next_node.next_node = Node(4) >>> root_node.has_loop False >>> root_node.next_node.next_node.next_node = root_node.next_node >>> root_node.has_loop True """ try: list(self) return False except ContainsLoopError: return True if __name__ == "__main__": root_node = Node(1) root_node.next_node = Node(2) root_node.next_node.next_node = Node(3) root_node.next_node.next_node.next_node = Node(4) print(root_node.has_loop) # False root_node.next_node.next_node.next_node = root_node.next_node print(root_node.has_loop) # True root_node = Node(5) root_node.next_node = Node(6) root_node.next_node.next_node = Node(5) root_node.next_node.next_node.next_node = Node(6) print(root_node.has_loop) # False root_node = Node(1) print(root_node.has_loop) # False
from typing import Any, Optional class ContainsLoopError(Exception): pass class Node: def __init__(self, data: Any) -> None: self.data: Any = data self.next_node: Optional[Node] = None def __iter__(self): node = self visited = [] while node: if node in visited: raise ContainsLoopError visited.append(node) yield node.data node = node.next_node @property def has_loop(self) -> bool: """ A loop is when the exact same Node appears more than once in a linked list. >>> root_node = Node(1) >>> root_node.next_node = Node(2) >>> root_node.next_node.next_node = Node(3) >>> root_node.next_node.next_node.next_node = Node(4) >>> root_node.has_loop False >>> root_node.next_node.next_node.next_node = root_node.next_node >>> root_node.has_loop True """ try: list(self) return False except ContainsLoopError: return True if __name__ == "__main__": root_node = Node(1) root_node.next_node = Node(2) root_node.next_node.next_node = Node(3) root_node.next_node.next_node.next_node = Node(4) print(root_node.has_loop) # False root_node.next_node.next_node.next_node = root_node.next_node print(root_node.has_loop) # True root_node = Node(5) root_node.next_node = Node(6) root_node.next_node.next_node = Node(5) root_node.next_node.next_node.next_node = Node(6) print(root_node.has_loop) # False root_node = Node(1) print(root_node.has_loop) # False
1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
class Node: def __init__(self, data: int) -> int: self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def push(self, new_data: int) -> int: new_node = Node(new_data) new_node.next = self.head self.head = new_node return self.head.data def middle_element(self) -> int: """ >>> link = LinkedList() >>> link.middle_element() No element found. >>> link.push(5) 5 >>> link.push(6) 6 >>> link.push(8) 8 >>> link.push(8) 8 >>> link.push(10) 10 >>> link.push(12) 12 >>> link.push(17) 17 >>> link.push(7) 7 >>> link.push(3) 3 >>> link.push(20) 20 >>> link.push(-20) -20 >>> link.middle_element() 12 >>> """ slow_pointer = self.head fast_pointer = self.head if self.head: while fast_pointer and fast_pointer.next: fast_pointer = fast_pointer.next.next slow_pointer = slow_pointer.next return slow_pointer.data else: print("No element found.") if __name__ == "__main__": link = LinkedList() for i in range(int(input().strip())): data = int(input().strip()) link.push(data) print(link.middle_element())
from typing import Optional class Node: def __init__(self, data: int) -> None: self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def push(self, new_data: int) -> int: new_node = Node(new_data) new_node.next = self.head self.head = new_node return self.head.data def middle_element(self) -> Optional[int]: """ >>> link = LinkedList() >>> link.middle_element() No element found. >>> link.push(5) 5 >>> link.push(6) 6 >>> link.push(8) 8 >>> link.push(8) 8 >>> link.push(10) 10 >>> link.push(12) 12 >>> link.push(17) 17 >>> link.push(7) 7 >>> link.push(3) 3 >>> link.push(20) 20 >>> link.push(-20) -20 >>> link.middle_element() 12 >>> """ slow_pointer = self.head fast_pointer = self.head if self.head: while fast_pointer and fast_pointer.next: fast_pointer = fast_pointer.next.next slow_pointer = slow_pointer.next return slow_pointer.data else: print("No element found.") return None if __name__ == "__main__": link = LinkedList() for i in range(int(input().strip())): data = int(input().strip()) link.push(data) print(link.middle_element())
1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Based on "Skip Lists: A Probabilistic Alternative to Balanced Trees" by William Pugh https://epaperpress.com/sortsearch/download/skiplist.pdf """ from __future__ import annotations from random import random from typing import Generic, TypeVar KT = TypeVar("KT") VT = TypeVar("VT") class Node(Generic[KT, VT]): def __init__(self, key: KT, value: VT): self.key = key self.value = value self.forward: list[Node[KT, VT]] = [] def __repr__(self) -> str: """ :return: Visual representation of Node >>> node = Node("Key", 2) >>> repr(node) 'Node(Key: 2)' """ return f"Node({self.key}: {self.value})" @property def level(self) -> int: """ :return: Number of forward references >>> node = Node("Key", 2) >>> node.level 0 >>> node.forward.append(Node("Key2", 4)) >>> node.level 1 >>> node.forward.append(Node("Key3", 6)) >>> node.level 2 """ return len(self.forward) class SkipList(Generic[KT, VT]): def __init__(self, p: float = 0.5, max_level: int = 16): self.head = Node("root", None) self.level = 0 self.p = p self.max_level = max_level def __str__(self) -> str: """ :return: Visual representation of SkipList >>> skip_list = SkipList() >>> print(skip_list) SkipList(level=0) >>> skip_list.insert("Key1", "Value") >>> print(skip_list) # doctest: +ELLIPSIS SkipList(level=... [root]--... [Key1]--Key1... None *... >>> skip_list.insert("Key2", "OtherValue") >>> print(skip_list) # doctest: +ELLIPSIS SkipList(level=... [root]--... [Key1]--Key1... [Key2]--Key2... None *... """ items = list(self) if len(items) == 0: return f"SkipList(level={self.level})" label_size = max((len(str(item)) for item in items), default=4) label_size = max(label_size, 4) + 4 node = self.head lines = [] forwards = node.forward.copy() lines.append(f"[{node.key}]".ljust(label_size, "-") + "* " * len(forwards)) lines.append(" " * label_size + "| " * len(forwards)) while len(node.forward) != 0: node = node.forward[0] lines.append( f"[{node.key}]".ljust(label_size, "-") + " ".join(str(n.key) if n.key == node.key else "|" for n in forwards) ) lines.append(" " * label_size + "| " * len(forwards)) forwards[: node.level] = node.forward lines.append("None".ljust(label_size) + "* " * len(forwards)) return f"SkipList(level={self.level})\n" + "\n".join(lines) def __iter__(self): node = self.head while len(node.forward) != 0: yield node.forward[0].key node = node.forward[0] def random_level(self) -> int: """ :return: Random level from [1, self.max_level] interval. Higher values are less likely. """ level = 1 while random() < self.p and level < self.max_level: level += 1 return level def _locate_node(self, key) -> tuple[Node[KT, VT] | None, list[Node[KT, VT]]]: """ :param key: Searched key, :return: Tuple with searched node (or None if given key is not present) and list of nodes that refer (if key is present) of should refer to given node. """ # Nodes with refer or should refer to output node update_vector = [] node = self.head for i in reversed(range(self.level)): # i < node.level - When node level is lesser than `i` decrement `i`. # node.forward[i].key < key - Jumping to node with key value higher # or equal to searched key would result # in skipping searched key. while i < node.level and node.forward[i].key < key: node = node.forward[i] # Each leftmost node (relative to searched node) will potentially have to # be updated. update_vector.append(node) update_vector.reverse() # Note that we were inserting values in reverse order. # len(node.forward) != 0 - If current node doesn't contain any further # references then searched key is not present. # node.forward[0].key == key - Next node key should be equal to search key # if key is present. if len(node.forward) != 0 and node.forward[0].key == key: return node.forward[0], update_vector else: return None, update_vector def delete(self, key: KT): """ :param key: Key to remove from list. >>> skip_list = SkipList() >>> skip_list.insert(2, "Two") >>> skip_list.insert(1, "One") >>> skip_list.insert(3, "Three") >>> list(skip_list) [1, 2, 3] >>> skip_list.delete(2) >>> list(skip_list) [1, 3] """ node, update_vector = self._locate_node(key) if node is not None: for i, update_node in enumerate(update_vector): # Remove or replace all references to removed node. if update_node.level > i and update_node.forward[i].key == key: if node.level > i: update_node.forward[i] = node.forward[i] else: update_node.forward = update_node.forward[:i] def insert(self, key: KT, value: VT): """ :param key: Key to insert. :param value: Value associated with given key. >>> skip_list = SkipList() >>> skip_list.insert(2, "Two") >>> skip_list.find(2) 'Two' >>> list(skip_list) [2] """ node, update_vector = self._locate_node(key) if node is not None: node.value = value else: level = self.random_level() if level > self.level: # After level increase we have to add additional nodes to head. for i in range(self.level - 1, level): update_vector.append(self.head) self.level = level new_node = Node(key, value) for i, update_node in enumerate(update_vector[:level]): # Change references to pass through new node. if update_node.level > i: new_node.forward.append(update_node.forward[i]) if update_node.level < i + 1: update_node.forward.append(new_node) else: update_node.forward[i] = new_node def find(self, key: VT) -> VT | None: """ :param key: Search key. :return: Value associated with given key or None if given key is not present. >>> skip_list = SkipList() >>> skip_list.find(2) >>> skip_list.insert(2, "Two") >>> skip_list.find(2) 'Two' >>> skip_list.insert(2, "Three") >>> skip_list.find(2) 'Three' """ node, _ = self._locate_node(key) if node is not None: return node.value return None def test_insert(): skip_list = SkipList() skip_list.insert("Key1", 3) skip_list.insert("Key2", 12) skip_list.insert("Key3", 41) skip_list.insert("Key4", -19) node = skip_list.head all_values = {} while node.level != 0: node = node.forward[0] all_values[node.key] = node.value assert len(all_values) == 4 assert all_values["Key1"] == 3 assert all_values["Key2"] == 12 assert all_values["Key3"] == 41 assert all_values["Key4"] == -19 def test_insert_overrides_existing_value(): skip_list = SkipList() skip_list.insert("Key1", 10) skip_list.insert("Key1", 12) skip_list.insert("Key5", 7) skip_list.insert("Key7", 10) skip_list.insert("Key10", 5) skip_list.insert("Key7", 7) skip_list.insert("Key5", 5) skip_list.insert("Key10", 10) node = skip_list.head all_values = {} while node.level != 0: node = node.forward[0] all_values[node.key] = node.value if len(all_values) != 4: print() assert len(all_values) == 4 assert all_values["Key1"] == 12 assert all_values["Key7"] == 7 assert all_values["Key5"] == 5 assert all_values["Key10"] == 10 def test_searching_empty_list_returns_none(): skip_list = SkipList() assert skip_list.find("Some key") is None def test_search(): skip_list = SkipList() skip_list.insert("Key2", 20) assert skip_list.find("Key2") == 20 skip_list.insert("Some Key", 10) skip_list.insert("Key2", 8) skip_list.insert("V", 13) assert skip_list.find("Y") is None assert skip_list.find("Key2") == 8 assert skip_list.find("Some Key") == 10 assert skip_list.find("V") == 13 def test_deleting_item_from_empty_list_do_nothing(): skip_list = SkipList() skip_list.delete("Some key") assert len(skip_list.head.forward) == 0 def test_deleted_items_are_not_founded_by_find_method(): skip_list = SkipList() skip_list.insert("Key1", 12) skip_list.insert("V", 13) skip_list.insert("X", 14) skip_list.insert("Key2", 15) skip_list.delete("V") skip_list.delete("Key2") assert skip_list.find("V") is None assert skip_list.find("Key2") is None def test_delete_removes_only_given_key(): skip_list = SkipList() skip_list.insert("Key1", 12) skip_list.insert("V", 13) skip_list.insert("X", 14) skip_list.insert("Key2", 15) skip_list.delete("V") assert skip_list.find("V") is None assert skip_list.find("X") == 14 assert skip_list.find("Key1") == 12 assert skip_list.find("Key2") == 15 skip_list.delete("X") assert skip_list.find("V") is None assert skip_list.find("X") is None assert skip_list.find("Key1") == 12 assert skip_list.find("Key2") == 15 skip_list.delete("Key1") assert skip_list.find("V") is None assert skip_list.find("X") is None assert skip_list.find("Key1") is None assert skip_list.find("Key2") == 15 skip_list.delete("Key2") assert skip_list.find("V") is None assert skip_list.find("X") is None assert skip_list.find("Key1") is None assert skip_list.find("Key2") is None def test_delete_doesnt_leave_dead_nodes(): skip_list = SkipList() skip_list.insert("Key1", 12) skip_list.insert("V", 13) skip_list.insert("X", 142) skip_list.insert("Key2", 15) skip_list.delete("X") def traverse_keys(node): yield node.key for forward_node in node.forward: yield from traverse_keys(forward_node) assert len(set(traverse_keys(skip_list.head))) == 4 def test_iter_always_yields_sorted_values(): def is_sorted(lst): for item, next_item in zip(lst, lst[1:]): if next_item < item: return False return True skip_list = SkipList() for i in range(10): skip_list.insert(i, i) assert is_sorted(list(skip_list)) skip_list.delete(5) skip_list.delete(8) skip_list.delete(2) assert is_sorted(list(skip_list)) skip_list.insert(-12, -12) skip_list.insert(77, 77) assert is_sorted(list(skip_list)) def pytests(): for i in range(100): # Repeat test 100 times due to the probabilistic nature of skip list # random values == random bugs test_insert() test_insert_overrides_existing_value() test_searching_empty_list_returns_none() test_search() test_deleting_item_from_empty_list_do_nothing() test_deleted_items_are_not_founded_by_find_method() test_delete_removes_only_given_key() test_delete_doesnt_leave_dead_nodes() test_iter_always_yields_sorted_values() def main(): """ >>> pytests() """ skip_list = SkipList() skip_list.insert(2, "2") skip_list.insert(4, "4") skip_list.insert(6, "4") skip_list.insert(4, "5") skip_list.insert(8, "4") skip_list.insert(9, "4") skip_list.delete(4) print(skip_list) if __name__ == "__main__": main()
""" Based on "Skip Lists: A Probabilistic Alternative to Balanced Trees" by William Pugh https://epaperpress.com/sortsearch/download/skiplist.pdf """ from __future__ import annotations from random import random from typing import Generic, Optional, TypeVar, Union KT = TypeVar("KT") VT = TypeVar("VT") class Node(Generic[KT, VT]): def __init__(self, key: Union[KT, str] = "root", value: Optional[VT] = None): self.key = key self.value = value self.forward: list[Node[KT, VT]] = [] def __repr__(self) -> str: """ :return: Visual representation of Node >>> node = Node("Key", 2) >>> repr(node) 'Node(Key: 2)' """ return f"Node({self.key}: {self.value})" @property def level(self) -> int: """ :return: Number of forward references >>> node = Node("Key", 2) >>> node.level 0 >>> node.forward.append(Node("Key2", 4)) >>> node.level 1 >>> node.forward.append(Node("Key3", 6)) >>> node.level 2 """ return len(self.forward) class SkipList(Generic[KT, VT]): def __init__(self, p: float = 0.5, max_level: int = 16): self.head: Node[KT, VT] = Node[KT, VT]() self.level = 0 self.p = p self.max_level = max_level def __str__(self) -> str: """ :return: Visual representation of SkipList >>> skip_list = SkipList() >>> print(skip_list) SkipList(level=0) >>> skip_list.insert("Key1", "Value") >>> print(skip_list) # doctest: +ELLIPSIS SkipList(level=... [root]--... [Key1]--Key1... None *... >>> skip_list.insert("Key2", "OtherValue") >>> print(skip_list) # doctest: +ELLIPSIS SkipList(level=... [root]--... [Key1]--Key1... [Key2]--Key2... None *... """ items = list(self) if len(items) == 0: return f"SkipList(level={self.level})" label_size = max((len(str(item)) for item in items), default=4) label_size = max(label_size, 4) + 4 node = self.head lines = [] forwards = node.forward.copy() lines.append(f"[{node.key}]".ljust(label_size, "-") + "* " * len(forwards)) lines.append(" " * label_size + "| " * len(forwards)) while len(node.forward) != 0: node = node.forward[0] lines.append( f"[{node.key}]".ljust(label_size, "-") + " ".join(str(n.key) if n.key == node.key else "|" for n in forwards) ) lines.append(" " * label_size + "| " * len(forwards)) forwards[: node.level] = node.forward lines.append("None".ljust(label_size) + "* " * len(forwards)) return f"SkipList(level={self.level})\n" + "\n".join(lines) def __iter__(self): node = self.head while len(node.forward) != 0: yield node.forward[0].key node = node.forward[0] def random_level(self) -> int: """ :return: Random level from [1, self.max_level] interval. Higher values are less likely. """ level = 1 while random() < self.p and level < self.max_level: level += 1 return level def _locate_node(self, key) -> tuple[Node[KT, VT] | None, list[Node[KT, VT]]]: """ :param key: Searched key, :return: Tuple with searched node (or None if given key is not present) and list of nodes that refer (if key is present) of should refer to given node. """ # Nodes with refer or should refer to output node update_vector = [] node = self.head for i in reversed(range(self.level)): # i < node.level - When node level is lesser than `i` decrement `i`. # node.forward[i].key < key - Jumping to node with key value higher # or equal to searched key would result # in skipping searched key. while i < node.level and node.forward[i].key < key: node = node.forward[i] # Each leftmost node (relative to searched node) will potentially have to # be updated. update_vector.append(node) update_vector.reverse() # Note that we were inserting values in reverse order. # len(node.forward) != 0 - If current node doesn't contain any further # references then searched key is not present. # node.forward[0].key == key - Next node key should be equal to search key # if key is present. if len(node.forward) != 0 and node.forward[0].key == key: return node.forward[0], update_vector else: return None, update_vector def delete(self, key: KT): """ :param key: Key to remove from list. >>> skip_list = SkipList() >>> skip_list.insert(2, "Two") >>> skip_list.insert(1, "One") >>> skip_list.insert(3, "Three") >>> list(skip_list) [1, 2, 3] >>> skip_list.delete(2) >>> list(skip_list) [1, 3] """ node, update_vector = self._locate_node(key) if node is not None: for i, update_node in enumerate(update_vector): # Remove or replace all references to removed node. if update_node.level > i and update_node.forward[i].key == key: if node.level > i: update_node.forward[i] = node.forward[i] else: update_node.forward = update_node.forward[:i] def insert(self, key: KT, value: VT): """ :param key: Key to insert. :param value: Value associated with given key. >>> skip_list = SkipList() >>> skip_list.insert(2, "Two") >>> skip_list.find(2) 'Two' >>> list(skip_list) [2] """ node, update_vector = self._locate_node(key) if node is not None: node.value = value else: level = self.random_level() if level > self.level: # After level increase we have to add additional nodes to head. for i in range(self.level - 1, level): update_vector.append(self.head) self.level = level new_node = Node(key, value) for i, update_node in enumerate(update_vector[:level]): # Change references to pass through new node. if update_node.level > i: new_node.forward.append(update_node.forward[i]) if update_node.level < i + 1: update_node.forward.append(new_node) else: update_node.forward[i] = new_node def find(self, key: VT) -> VT | None: """ :param key: Search key. :return: Value associated with given key or None if given key is not present. >>> skip_list = SkipList() >>> skip_list.find(2) >>> skip_list.insert(2, "Two") >>> skip_list.find(2) 'Two' >>> skip_list.insert(2, "Three") >>> skip_list.find(2) 'Three' """ node, _ = self._locate_node(key) if node is not None: return node.value return None def test_insert(): skip_list = SkipList() skip_list.insert("Key1", 3) skip_list.insert("Key2", 12) skip_list.insert("Key3", 41) skip_list.insert("Key4", -19) node = skip_list.head all_values = {} while node.level != 0: node = node.forward[0] all_values[node.key] = node.value assert len(all_values) == 4 assert all_values["Key1"] == 3 assert all_values["Key2"] == 12 assert all_values["Key3"] == 41 assert all_values["Key4"] == -19 def test_insert_overrides_existing_value(): skip_list = SkipList() skip_list.insert("Key1", 10) skip_list.insert("Key1", 12) skip_list.insert("Key5", 7) skip_list.insert("Key7", 10) skip_list.insert("Key10", 5) skip_list.insert("Key7", 7) skip_list.insert("Key5", 5) skip_list.insert("Key10", 10) node = skip_list.head all_values = {} while node.level != 0: node = node.forward[0] all_values[node.key] = node.value if len(all_values) != 4: print() assert len(all_values) == 4 assert all_values["Key1"] == 12 assert all_values["Key7"] == 7 assert all_values["Key5"] == 5 assert all_values["Key10"] == 10 def test_searching_empty_list_returns_none(): skip_list = SkipList() assert skip_list.find("Some key") is None def test_search(): skip_list = SkipList() skip_list.insert("Key2", 20) assert skip_list.find("Key2") == 20 skip_list.insert("Some Key", 10) skip_list.insert("Key2", 8) skip_list.insert("V", 13) assert skip_list.find("Y") is None assert skip_list.find("Key2") == 8 assert skip_list.find("Some Key") == 10 assert skip_list.find("V") == 13 def test_deleting_item_from_empty_list_do_nothing(): skip_list = SkipList() skip_list.delete("Some key") assert len(skip_list.head.forward) == 0 def test_deleted_items_are_not_founded_by_find_method(): skip_list = SkipList() skip_list.insert("Key1", 12) skip_list.insert("V", 13) skip_list.insert("X", 14) skip_list.insert("Key2", 15) skip_list.delete("V") skip_list.delete("Key2") assert skip_list.find("V") is None assert skip_list.find("Key2") is None def test_delete_removes_only_given_key(): skip_list = SkipList() skip_list.insert("Key1", 12) skip_list.insert("V", 13) skip_list.insert("X", 14) skip_list.insert("Key2", 15) skip_list.delete("V") assert skip_list.find("V") is None assert skip_list.find("X") == 14 assert skip_list.find("Key1") == 12 assert skip_list.find("Key2") == 15 skip_list.delete("X") assert skip_list.find("V") is None assert skip_list.find("X") is None assert skip_list.find("Key1") == 12 assert skip_list.find("Key2") == 15 skip_list.delete("Key1") assert skip_list.find("V") is None assert skip_list.find("X") is None assert skip_list.find("Key1") is None assert skip_list.find("Key2") == 15 skip_list.delete("Key2") assert skip_list.find("V") is None assert skip_list.find("X") is None assert skip_list.find("Key1") is None assert skip_list.find("Key2") is None def test_delete_doesnt_leave_dead_nodes(): skip_list = SkipList() skip_list.insert("Key1", 12) skip_list.insert("V", 13) skip_list.insert("X", 142) skip_list.insert("Key2", 15) skip_list.delete("X") def traverse_keys(node): yield node.key for forward_node in node.forward: yield from traverse_keys(forward_node) assert len(set(traverse_keys(skip_list.head))) == 4 def test_iter_always_yields_sorted_values(): def is_sorted(lst): for item, next_item in zip(lst, lst[1:]): if next_item < item: return False return True skip_list = SkipList() for i in range(10): skip_list.insert(i, i) assert is_sorted(list(skip_list)) skip_list.delete(5) skip_list.delete(8) skip_list.delete(2) assert is_sorted(list(skip_list)) skip_list.insert(-12, -12) skip_list.insert(77, 77) assert is_sorted(list(skip_list)) def pytests(): for i in range(100): # Repeat test 100 times due to the probabilistic nature of skip list # random values == random bugs test_insert() test_insert_overrides_existing_value() test_searching_empty_list_returns_none() test_search() test_deleting_item_from_empty_list_do_nothing() test_deleted_items_are_not_founded_by_find_method() test_delete_removes_only_given_key() test_delete_doesnt_leave_dead_nodes() test_iter_always_yields_sorted_values() def main(): """ >>> pytests() """ skip_list = SkipList() skip_list.insert(2, "2") skip_list.insert(4, "4") skip_list.insert(6, "4") skip_list.insert(4, "5") skip_list.insert(8, "4") skip_list.insert(9, "4") skip_list.delete(4) print(skip_list) if __name__ == "__main__": main()
1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
"""Non recursive implementation of a DFS algorithm.""" from __future__ import annotations def depth_first_search(graph: dict, start: str) -> set[str]: """Depth First Search on Graph :param graph: directed graph in dictionary format :param start: starting vertex as a string :returns: the trace of the search >>> input_G = { "A": ["B", "C", "D"], "B": ["A", "D", "E"], ... "C": ["A", "F"], "D": ["B", "D"], "E": ["B", "F"], ... "F": ["C", "E", "G"], "G": ["F"] } >>> output_G = list({'A', 'B', 'C', 'D', 'E', 'F', 'G'}) >>> all(x in output_G for x in list(depth_first_search(input_G, "A"))) True >>> all(x in output_G for x in list(depth_first_search(input_G, "G"))) True """ explored, stack = set(start), [start] while stack: v = stack.pop() explored.add(v) # Differences from BFS: # 1) pop last element instead of first one # 2) add adjacent elements to stack without exploring them for adj in reversed(graph[v]): if adj not in explored: stack.append(adj) return explored G = { "A": ["B", "C", "D"], "B": ["A", "D", "E"], "C": ["A", "F"], "D": ["B", "D"], "E": ["B", "F"], "F": ["C", "E", "G"], "G": ["F"], } if __name__ == "__main__": import doctest doctest.testmod() print(depth_first_search(G, "A"))
"""Non recursive implementation of a DFS algorithm.""" from __future__ import annotations def depth_first_search(graph: dict, start: str) -> set[str]: """Depth First Search on Graph :param graph: directed graph in dictionary format :param start: starting vertex as a string :returns: the trace of the search >>> input_G = { "A": ["B", "C", "D"], "B": ["A", "D", "E"], ... "C": ["A", "F"], "D": ["B", "D"], "E": ["B", "F"], ... "F": ["C", "E", "G"], "G": ["F"] } >>> output_G = list({'A', 'B', 'C', 'D', 'E', 'F', 'G'}) >>> all(x in output_G for x in list(depth_first_search(input_G, "A"))) True >>> all(x in output_G for x in list(depth_first_search(input_G, "G"))) True """ explored, stack = set(start), [start] while stack: v = stack.pop() explored.add(v) # Differences from BFS: # 1) pop last element instead of first one # 2) add adjacent elements to stack without exploring them for adj in reversed(graph[v]): if adj not in explored: stack.append(adj) return explored G = { "A": ["B", "C", "D"], "B": ["A", "D", "E"], "C": ["A", "F"], "D": ["B", "D"], "E": ["B", "F"], "F": ["C", "E", "G"], "G": ["F"], } if __name__ == "__main__": import doctest doctest.testmod() print(depth_first_search(G, "A"))
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Project Euler Problem 234: https://projecteuler.net/problem=234 For any integer n, consider the three functions f1,n(x,y,z) = x^(n+1) + y^(n+1) - z^(n+1) f2,n(x,y,z) = (xy + yz + zx)*(x^(n-1) + y^(n-1) - z^(n-1)) f3,n(x,y,z) = xyz*(xn-2 + yn-2 - zn-2) and their combination fn(x,y,z) = f1,n(x,y,z) + f2,n(x,y,z) - f3,n(x,y,z) We call (x,y,z) a golden triple of order k if x, y, and z are all rational numbers of the form a / b with 0 < a < b ≤ k and there is (at least) one integer n, so that fn(x,y,z) = 0. Let s(x,y,z) = x + y + z. Let t = u / v be the sum of all distinct s(x,y,z) for all golden triples (x,y,z) of order 35. All the s(x,y,z) and t must be in reduced form. Find u + v. Solution: By expanding the brackets it is easy to show that fn(x, y, z) = (x + y + z) * (x^n + y^n - z^n). Since x,y,z are positive, the requirement fn(x, y, z) = 0 is fulfilled if and only if x^n + y^n = z^n. By Fermat's Last Theorem, this means that the absolute value of n can not exceed 2, i.e. n is in {-2, -1, 0, 1, 2}. We can eliminate n = 0 since then the equation would reduce to 1 + 1 = 1, for which there are no solutions. So all we have to do is iterate through the possible numerators and denominators of x and y, calculate the corresponding z, and check if the corresponding numerator and denominator are integer and satisfy 0 < z_num < z_den <= 0. We use a set "uniquq_s" to make sure there are no duplicates, and the fractions.Fraction class to make sure we get the right numerator and denominator. Reference: https://en.wikipedia.org/wiki/Fermat%27s_Last_Theorem """ from __future__ import annotations from fractions import Fraction from math import gcd, sqrt def is_sq(number: int) -> bool: """ Check if number is a perfect square. >>> is_sq(1) True >>> is_sq(1000001) False >>> is_sq(1000000) True """ sq: int = int(number ** 0.5) return number == sq * sq def add_three( x_num: int, x_den: int, y_num: int, y_den: int, z_num: int, z_den: int ) -> tuple[int, int]: """ Given the numerators and denominators of three fractions, return the numerator and denominator of their sum in lowest form. >>> add_three(1, 3, 1, 3, 1, 3) (1, 1) >>> add_three(2, 5, 4, 11, 12, 3) (262, 55) """ top: int = x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den bottom: int = x_den * y_den * z_den hcf: int = gcd(top, bottom) top //= hcf bottom //= hcf return top, bottom def solution(order: int = 35) -> int: """ Find the sum of the numerator and denominator of the sum of all s(x,y,z) for golden triples (x,y,z) of the given order. >>> solution(5) 296 >>> solution(10) 12519 >>> solution(20) 19408891927 """ unique_s: set = set() hcf: int total: Fraction = Fraction(0) fraction_sum: tuple[int, int] for x_num in range(1, order + 1): for x_den in range(x_num + 1, order + 1): for y_num in range(1, order + 1): for y_den in range(y_num + 1, order + 1): # n=1 z_num = x_num * y_den + x_den * y_num z_den = x_den * y_den hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) # n=2 z_num = ( x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num ) z_den = x_den * x_den * y_den * y_den if is_sq(z_num) and is_sq(z_den): z_num = int(sqrt(z_num)) z_den = int(sqrt(z_den)) hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) # n=-1 z_num = x_num * y_num z_den = x_den * y_num + x_num * y_den hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) # n=2 z_num = x_num * x_num * y_num * y_num z_den = ( x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den ) if is_sq(z_num) and is_sq(z_den): z_num = int(sqrt(z_num)) z_den = int(sqrt(z_den)) hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) for num, den in unique_s: total += Fraction(num, den) return total.denominator + total.numerator if __name__ == "__main__": print(f"{solution() = }")
""" Project Euler Problem 234: https://projecteuler.net/problem=234 For any integer n, consider the three functions f1,n(x,y,z) = x^(n+1) + y^(n+1) - z^(n+1) f2,n(x,y,z) = (xy + yz + zx)*(x^(n-1) + y^(n-1) - z^(n-1)) f3,n(x,y,z) = xyz*(xn-2 + yn-2 - zn-2) and their combination fn(x,y,z) = f1,n(x,y,z) + f2,n(x,y,z) - f3,n(x,y,z) We call (x,y,z) a golden triple of order k if x, y, and z are all rational numbers of the form a / b with 0 < a < b ≤ k and there is (at least) one integer n, so that fn(x,y,z) = 0. Let s(x,y,z) = x + y + z. Let t = u / v be the sum of all distinct s(x,y,z) for all golden triples (x,y,z) of order 35. All the s(x,y,z) and t must be in reduced form. Find u + v. Solution: By expanding the brackets it is easy to show that fn(x, y, z) = (x + y + z) * (x^n + y^n - z^n). Since x,y,z are positive, the requirement fn(x, y, z) = 0 is fulfilled if and only if x^n + y^n = z^n. By Fermat's Last Theorem, this means that the absolute value of n can not exceed 2, i.e. n is in {-2, -1, 0, 1, 2}. We can eliminate n = 0 since then the equation would reduce to 1 + 1 = 1, for which there are no solutions. So all we have to do is iterate through the possible numerators and denominators of x and y, calculate the corresponding z, and check if the corresponding numerator and denominator are integer and satisfy 0 < z_num < z_den <= 0. We use a set "uniquq_s" to make sure there are no duplicates, and the fractions.Fraction class to make sure we get the right numerator and denominator. Reference: https://en.wikipedia.org/wiki/Fermat%27s_Last_Theorem """ from __future__ import annotations from fractions import Fraction from math import gcd, sqrt def is_sq(number: int) -> bool: """ Check if number is a perfect square. >>> is_sq(1) True >>> is_sq(1000001) False >>> is_sq(1000000) True """ sq: int = int(number ** 0.5) return number == sq * sq def add_three( x_num: int, x_den: int, y_num: int, y_den: int, z_num: int, z_den: int ) -> tuple[int, int]: """ Given the numerators and denominators of three fractions, return the numerator and denominator of their sum in lowest form. >>> add_three(1, 3, 1, 3, 1, 3) (1, 1) >>> add_three(2, 5, 4, 11, 12, 3) (262, 55) """ top: int = x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den bottom: int = x_den * y_den * z_den hcf: int = gcd(top, bottom) top //= hcf bottom //= hcf return top, bottom def solution(order: int = 35) -> int: """ Find the sum of the numerator and denominator of the sum of all s(x,y,z) for golden triples (x,y,z) of the given order. >>> solution(5) 296 >>> solution(10) 12519 >>> solution(20) 19408891927 """ unique_s: set = set() hcf: int total: Fraction = Fraction(0) fraction_sum: tuple[int, int] for x_num in range(1, order + 1): for x_den in range(x_num + 1, order + 1): for y_num in range(1, order + 1): for y_den in range(y_num + 1, order + 1): # n=1 z_num = x_num * y_den + x_den * y_num z_den = x_den * y_den hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) # n=2 z_num = ( x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num ) z_den = x_den * x_den * y_den * y_den if is_sq(z_num) and is_sq(z_den): z_num = int(sqrt(z_num)) z_den = int(sqrt(z_den)) hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) # n=-1 z_num = x_num * y_num z_den = x_den * y_num + x_num * y_den hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) # n=2 z_num = x_num * x_num * y_num * y_num z_den = ( x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den ) if is_sq(z_num) and is_sq(z_den): z_num = int(sqrt(z_num)) z_den = int(sqrt(z_den)) hcf = gcd(z_num, z_den) z_num //= hcf z_den //= hcf if 0 < z_num < z_den <= order: fraction_sum = add_three( x_num, x_den, y_num, y_den, z_num, z_den ) unique_s.add(fraction_sum) for num, den in unique_s: total += Fraction(num, den) return total.denominator + total.numerator if __name__ == "__main__": print(f"{solution() = }")
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
def kruskal( num_nodes: int, edges: list[tuple[int, int, int]] ) -> list[tuple[int, int, int]]: """ >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1)]) [(2, 3, 1), (0, 1, 3), (1, 2, 5)] >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2)]) [(2, 3, 1), (0, 2, 1), (0, 1, 3)] >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2), ... (2, 1, 1)]) [(2, 3, 1), (0, 2, 1), (2, 1, 1)] """ edges = sorted(edges, key=lambda edge: edge[2]) parent = list(range(num_nodes)) def find_parent(i): if i != parent[i]: parent[i] = find_parent(parent[i]) return parent[i] minimum_spanning_tree_cost = 0 minimum_spanning_tree = [] for edge in edges: parent_a = find_parent(edge[0]) parent_b = find_parent(edge[1]) if parent_a != parent_b: minimum_spanning_tree_cost += edge[2] minimum_spanning_tree.append(edge) parent[parent_a] = parent_b return minimum_spanning_tree if __name__ == "__main__": # pragma: no cover num_nodes, num_edges = list(map(int, input().strip().split())) edges = [] for _ in range(num_edges): node1, node2, cost = (int(x) for x in input().strip().split()) edges.append((node1, node2, cost)) kruskal(num_nodes, edges)
def kruskal( num_nodes: int, edges: list[tuple[int, int, int]] ) -> list[tuple[int, int, int]]: """ >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1)]) [(2, 3, 1), (0, 1, 3), (1, 2, 5)] >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2)]) [(2, 3, 1), (0, 2, 1), (0, 1, 3)] >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2), ... (2, 1, 1)]) [(2, 3, 1), (0, 2, 1), (2, 1, 1)] """ edges = sorted(edges, key=lambda edge: edge[2]) parent = list(range(num_nodes)) def find_parent(i): if i != parent[i]: parent[i] = find_parent(parent[i]) return parent[i] minimum_spanning_tree_cost = 0 minimum_spanning_tree = [] for edge in edges: parent_a = find_parent(edge[0]) parent_b = find_parent(edge[1]) if parent_a != parent_b: minimum_spanning_tree_cost += edge[2] minimum_spanning_tree.append(edge) parent[parent_a] = parent_b return minimum_spanning_tree if __name__ == "__main__": # pragma: no cover num_nodes, num_edges = list(map(int, input().strip().split())) edges = [] for _ in range(num_edges): node1, node2, cost = (int(x) for x in input().strip().split()) edges.append((node1, node2, cost)) kruskal(num_nodes, edges)
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" 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, find ∑ r_max. Solution: On expanding the terms, we get 2 if n is even and 2an if n is odd. For maximizing the value, 2an < a*a => n <= (a - 1)/2 (integer division) """ def solution(n: int = 1000) -> int: """ Returns ∑ r_max for 3 <= a <= n as explained above >>> solution(10) 300 >>> solution(100) 330750 >>> solution(1000) 333082500 """ return sum(2 * a * ((a - 1) // 2) for a in range(3, n + 1)) if __name__ == "__main__": print(solution())
""" 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, find ∑ r_max. Solution: On expanding the terms, we get 2 if n is even and 2an if n is odd. For maximizing the value, 2an < a*a => n <= (a - 1)/2 (integer division) """ def solution(n: int = 1000) -> int: """ Returns ∑ r_max for 3 <= a <= n as explained above >>> solution(10) 300 >>> solution(100) 330750 >>> solution(1000) 333082500 """ return sum(2 * a * ((a - 1) // 2) for a in range(3, n + 1)) if __name__ == "__main__": print(solution())
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
"""Binary Exponentiation.""" # Author : Junth Basnet # Time Complexity : O(logn) def binary_exponentiation(a, n): if n == 0: return 1 elif n % 2 == 1: return binary_exponentiation(a, n - 1) * a else: b = binary_exponentiation(a, n / 2) return b * b if __name__ == "__main__": try: BASE = int(input("Enter Base : ").strip()) POWER = int(input("Enter Power : ").strip()) except ValueError: print("Invalid literal for integer") RESULT = binary_exponentiation(BASE, POWER) print(f"{BASE}^({POWER}) : {RESULT}")
"""Binary Exponentiation.""" # Author : Junth Basnet # Time Complexity : O(logn) def binary_exponentiation(a, n): if n == 0: return 1 elif n % 2 == 1: return binary_exponentiation(a, n - 1) * a else: b = binary_exponentiation(a, n / 2) return b * b if __name__ == "__main__": try: BASE = int(input("Enter Base : ").strip()) POWER = int(input("Enter Power : ").strip()) except ValueError: print("Invalid literal for integer") RESULT = binary_exponentiation(BASE, POWER) print(f"{BASE}^({POWER}) : {RESULT}")
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue. Meanwhile, the HSV representation models how colors appear under light. In it, colors are represented using three components: hue, saturation and (brightness-)value. This file provides functions for converting colors from one representation to the other. (description adapted from https://en.wikipedia.org/wiki/RGB_color_model and https://en.wikipedia.org/wiki/HSL_and_HSV). """ def hsv_to_rgb(hue: float, saturation: float, value: float) -> list[int]: """ Conversion from the HSV-representation to the RGB-representation. Expected RGB-values taken from https://www.rapidtables.com/convert/color/hsv-to-rgb.html >>> hsv_to_rgb(0, 0, 0) [0, 0, 0] >>> hsv_to_rgb(0, 0, 1) [255, 255, 255] >>> hsv_to_rgb(0, 1, 1) [255, 0, 0] >>> hsv_to_rgb(60, 1, 1) [255, 255, 0] >>> hsv_to_rgb(120, 1, 1) [0, 255, 0] >>> hsv_to_rgb(240, 1, 1) [0, 0, 255] >>> hsv_to_rgb(300, 1, 1) [255, 0, 255] >>> hsv_to_rgb(180, 0.5, 0.5) [64, 128, 128] >>> hsv_to_rgb(234, 0.14, 0.88) [193, 196, 224] >>> hsv_to_rgb(330, 0.75, 0.5) [128, 32, 80] """ if hue < 0 or hue > 360: raise Exception("hue should be between 0 and 360") if saturation < 0 or saturation > 1: raise Exception("saturation should be between 0 and 1") if value < 0 or value > 1: raise Exception("value should be between 0 and 1") chroma = value * saturation hue_section = hue / 60 second_largest_component = chroma * (1 - abs(hue_section % 2 - 1)) match_value = value - chroma if hue_section >= 0 and hue_section <= 1: red = round(255 * (chroma + match_value)) green = round(255 * (second_largest_component + match_value)) blue = round(255 * (match_value)) elif hue_section > 1 and hue_section <= 2: red = round(255 * (second_largest_component + match_value)) green = round(255 * (chroma + match_value)) blue = round(255 * (match_value)) elif hue_section > 2 and hue_section <= 3: red = round(255 * (match_value)) green = round(255 * (chroma + match_value)) blue = round(255 * (second_largest_component + match_value)) elif hue_section > 3 and hue_section <= 4: red = round(255 * (match_value)) green = round(255 * (second_largest_component + match_value)) blue = round(255 * (chroma + match_value)) elif hue_section > 4 and hue_section <= 5: red = round(255 * (second_largest_component + match_value)) green = round(255 * (match_value)) blue = round(255 * (chroma + match_value)) else: red = round(255 * (chroma + match_value)) green = round(255 * (match_value)) blue = round(255 * (second_largest_component + match_value)) return [red, green, blue] def rgb_to_hsv(red: int, green: int, blue: int) -> list[float]: """ Conversion from the RGB-representation to the HSV-representation. The tested values are the reverse values from the hsv_to_rgb-doctests. Function "approximately_equal_hsv" is needed because of small deviations due to rounding for the RGB-values. >>> approximately_equal_hsv(rgb_to_hsv(0, 0, 0), [0, 0, 0]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 255, 255), [0, 0, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 0, 0), [0, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 255, 0), [60, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(0, 255, 0), [120, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(0, 0, 255), [240, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 0, 255), [300, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(64, 128, 128), [180, 0.5, 0.5]) True >>> approximately_equal_hsv(rgb_to_hsv(193, 196, 224), [234, 0.14, 0.88]) True >>> approximately_equal_hsv(rgb_to_hsv(128, 32, 80), [330, 0.75, 0.5]) True """ if red < 0 or red > 255: raise Exception("red should be between 0 and 255") if green < 0 or green > 255: raise Exception("green should be between 0 and 255") if blue < 0 or blue > 255: raise Exception("blue should be between 0 and 255") float_red = red / 255 float_green = green / 255 float_blue = blue / 255 value = max(max(float_red, float_green), float_blue) chroma = value - min(min(float_red, float_green), float_blue) saturation = 0 if value == 0 else chroma / value if chroma == 0: hue = 0.0 elif value == float_red: hue = 60 * (0 + (float_green - float_blue) / chroma) elif value == float_green: hue = 60 * (2 + (float_blue - float_red) / chroma) else: hue = 60 * (4 + (float_red - float_green) / chroma) hue = (hue + 360) % 360 return [hue, saturation, value] def approximately_equal_hsv(hsv_1: list[float], hsv_2: list[float]) -> bool: """ Utility-function to check that two hsv-colors are approximately equal >>> approximately_equal_hsv([0, 0, 0], [0, 0, 0]) True >>> approximately_equal_hsv([180, 0.5, 0.3], [179.9999, 0.500001, 0.30001]) True >>> approximately_equal_hsv([0, 0, 0], [1, 0, 0]) False >>> approximately_equal_hsv([180, 0.5, 0.3], [179.9999, 0.6, 0.30001]) False """ check_hue = abs(hsv_1[0] - hsv_2[0]) < 0.2 check_saturation = abs(hsv_1[1] - hsv_2[1]) < 0.002 check_value = abs(hsv_1[2] - hsv_2[2]) < 0.002 return check_hue and check_saturation and check_value
""" The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue. Meanwhile, the HSV representation models how colors appear under light. In it, colors are represented using three components: hue, saturation and (brightness-)value. This file provides functions for converting colors from one representation to the other. (description adapted from https://en.wikipedia.org/wiki/RGB_color_model and https://en.wikipedia.org/wiki/HSL_and_HSV). """ def hsv_to_rgb(hue: float, saturation: float, value: float) -> list[int]: """ Conversion from the HSV-representation to the RGB-representation. Expected RGB-values taken from https://www.rapidtables.com/convert/color/hsv-to-rgb.html >>> hsv_to_rgb(0, 0, 0) [0, 0, 0] >>> hsv_to_rgb(0, 0, 1) [255, 255, 255] >>> hsv_to_rgb(0, 1, 1) [255, 0, 0] >>> hsv_to_rgb(60, 1, 1) [255, 255, 0] >>> hsv_to_rgb(120, 1, 1) [0, 255, 0] >>> hsv_to_rgb(240, 1, 1) [0, 0, 255] >>> hsv_to_rgb(300, 1, 1) [255, 0, 255] >>> hsv_to_rgb(180, 0.5, 0.5) [64, 128, 128] >>> hsv_to_rgb(234, 0.14, 0.88) [193, 196, 224] >>> hsv_to_rgb(330, 0.75, 0.5) [128, 32, 80] """ if hue < 0 or hue > 360: raise Exception("hue should be between 0 and 360") if saturation < 0 or saturation > 1: raise Exception("saturation should be between 0 and 1") if value < 0 or value > 1: raise Exception("value should be between 0 and 1") chroma = value * saturation hue_section = hue / 60 second_largest_component = chroma * (1 - abs(hue_section % 2 - 1)) match_value = value - chroma if hue_section >= 0 and hue_section <= 1: red = round(255 * (chroma + match_value)) green = round(255 * (second_largest_component + match_value)) blue = round(255 * (match_value)) elif hue_section > 1 and hue_section <= 2: red = round(255 * (second_largest_component + match_value)) green = round(255 * (chroma + match_value)) blue = round(255 * (match_value)) elif hue_section > 2 and hue_section <= 3: red = round(255 * (match_value)) green = round(255 * (chroma + match_value)) blue = round(255 * (second_largest_component + match_value)) elif hue_section > 3 and hue_section <= 4: red = round(255 * (match_value)) green = round(255 * (second_largest_component + match_value)) blue = round(255 * (chroma + match_value)) elif hue_section > 4 and hue_section <= 5: red = round(255 * (second_largest_component + match_value)) green = round(255 * (match_value)) blue = round(255 * (chroma + match_value)) else: red = round(255 * (chroma + match_value)) green = round(255 * (match_value)) blue = round(255 * (second_largest_component + match_value)) return [red, green, blue] def rgb_to_hsv(red: int, green: int, blue: int) -> list[float]: """ Conversion from the RGB-representation to the HSV-representation. The tested values are the reverse values from the hsv_to_rgb-doctests. Function "approximately_equal_hsv" is needed because of small deviations due to rounding for the RGB-values. >>> approximately_equal_hsv(rgb_to_hsv(0, 0, 0), [0, 0, 0]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 255, 255), [0, 0, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 0, 0), [0, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 255, 0), [60, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(0, 255, 0), [120, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(0, 0, 255), [240, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(255, 0, 255), [300, 1, 1]) True >>> approximately_equal_hsv(rgb_to_hsv(64, 128, 128), [180, 0.5, 0.5]) True >>> approximately_equal_hsv(rgb_to_hsv(193, 196, 224), [234, 0.14, 0.88]) True >>> approximately_equal_hsv(rgb_to_hsv(128, 32, 80), [330, 0.75, 0.5]) True """ if red < 0 or red > 255: raise Exception("red should be between 0 and 255") if green < 0 or green > 255: raise Exception("green should be between 0 and 255") if blue < 0 or blue > 255: raise Exception("blue should be between 0 and 255") float_red = red / 255 float_green = green / 255 float_blue = blue / 255 value = max(max(float_red, float_green), float_blue) chroma = value - min(min(float_red, float_green), float_blue) saturation = 0 if value == 0 else chroma / value if chroma == 0: hue = 0.0 elif value == float_red: hue = 60 * (0 + (float_green - float_blue) / chroma) elif value == float_green: hue = 60 * (2 + (float_blue - float_red) / chroma) else: hue = 60 * (4 + (float_red - float_green) / chroma) hue = (hue + 360) % 360 return [hue, saturation, value] def approximately_equal_hsv(hsv_1: list[float], hsv_2: list[float]) -> bool: """ Utility-function to check that two hsv-colors are approximately equal >>> approximately_equal_hsv([0, 0, 0], [0, 0, 0]) True >>> approximately_equal_hsv([180, 0.5, 0.3], [179.9999, 0.500001, 0.30001]) True >>> approximately_equal_hsv([0, 0, 0], [1, 0, 0]) False >>> approximately_equal_hsv([180, 0.5, 0.3], [179.9999, 0.6, 0.30001]) False """ check_hue = abs(hsv_1[0] - hsv_2[0]) < 0.2 check_saturation = abs(hsv_1[1] - hsv_2[1]) < 0.002 check_value = abs(hsv_1[2] - hsv_2[2]) < 0.002 return check_hue and check_saturation and check_value
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
#!/usr/bin/env python3 from .hash_table import HashTable from .number_theory.prime_numbers import check_prime, next_prime class DoubleHash(HashTable): """ Hash Table example with open addressing and Double Hash """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def __hash_function_2(self, value, data): next_prime_gt = ( next_prime(value % self.size_table) if not check_prime(value % self.size_table) else value % self.size_table ) # gt = bigger than return next_prime_gt - (data % next_prime_gt) def __hash_double_function(self, key, data, increment): return (increment * self.__hash_function_2(key, data)) % self.size_table def _collision_resolution(self, key, data=None): i = 1 new_key = self.hash_function(data) while self.values[new_key] is not None and self.values[new_key] != key: new_key = ( self.__hash_double_function(key, data, i) if self.balanced_factor() >= self.lim_charge else None ) if new_key is None: break else: i += 1 return new_key
#!/usr/bin/env python3 from .hash_table import HashTable from .number_theory.prime_numbers import check_prime, next_prime class DoubleHash(HashTable): """ Hash Table example with open addressing and Double Hash """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def __hash_function_2(self, value, data): next_prime_gt = ( next_prime(value % self.size_table) if not check_prime(value % self.size_table) else value % self.size_table ) # gt = bigger than return next_prime_gt - (data % next_prime_gt) def __hash_double_function(self, key, data, increment): return (increment * self.__hash_function_2(key, data)) % self.size_table def _collision_resolution(self, key, data=None): i = 1 new_key = self.hash_function(data) while self.values[new_key] is not None and self.values[new_key] != key: new_key = ( self.__hash_double_function(key, data, i) if self.balanced_factor() >= self.lim_charge else None ) if new_key is None: break else: i += 1 return new_key
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from string import ascii_lowercase, ascii_uppercase def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") 'Hello world' >>> capitalize("123 hello world") '123 hello world' >>> capitalize(" hello world") ' hello world' >>> capitalize("a") 'A' >>> capitalize("") '' """ if not sentence: return "" lower_to_upper = {lc: uc for lc, uc in zip(ascii_lowercase, ascii_uppercase)} return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:] if __name__ == "__main__": from doctest import testmod testmod()
from string import ascii_lowercase, ascii_uppercase def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") 'Hello world' >>> capitalize("123 hello world") '123 hello world' >>> capitalize(" hello world") ' hello world' >>> capitalize("a") 'A' >>> capitalize("") '' """ if not sentence: return "" lower_to_upper = {lc: uc for lc, uc in zip(ascii_lowercase, ascii_uppercase)} return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:] if __name__ == "__main__": from doctest import testmod testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" https://en.wikipedia.org/wiki/Best-first_search#Greedy_BFS """ from __future__ import annotations Path = list[tuple[int, int]] grid = [ [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], # 0 are free path whereas 1's are obstacles [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], ] delta = ([-1, 0], [0, -1], [1, 0], [0, 1]) # up, left, down, right class Node: """ >>> k = Node(0, 0, 4, 5, 0, None) >>> k.calculate_heuristic() 9 >>> n = Node(1, 4, 3, 4, 2, None) >>> n.calculate_heuristic() 2 >>> l = [k, n] >>> n == l[0] False >>> l.sort() >>> n == l[0] True """ def __init__( self, pos_x: int, pos_y: int, goal_x: int, goal_y: int, g_cost: float, parent: Node | None, ): self.pos_x = pos_x self.pos_y = pos_y self.pos = (pos_y, pos_x) self.goal_x = goal_x self.goal_y = goal_y self.g_cost = g_cost self.parent = parent self.f_cost = self.calculate_heuristic() def calculate_heuristic(self) -> float: """ The heuristic here is the Manhattan Distance Could elaborate to offer more than one choice """ dy = abs(self.pos_x - self.goal_x) dx = abs(self.pos_y - self.goal_y) return dx + dy def __lt__(self, other) -> bool: return self.f_cost < other.f_cost class GreedyBestFirst: """ >>> gbf = GreedyBestFirst((0, 0), (len(grid) - 1, len(grid[0]) - 1)) >>> [x.pos for x in gbf.get_successors(gbf.start)] [(1, 0), (0, 1)] >>> (gbf.start.pos_y + delta[3][0], gbf.start.pos_x + delta[3][1]) (0, 1) >>> (gbf.start.pos_y + delta[2][0], gbf.start.pos_x + delta[2][1]) (1, 0) >>> gbf.retrace_path(gbf.start) [(0, 0)] >>> gbf.search() # doctest: +NORMALIZE_WHITESPACE [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (4, 1), (5, 1), (6, 1), (6, 2), (6, 3), (5, 3), (5, 4), (5, 5), (6, 5), (6, 6)] """ def __init__(self, start: tuple[int, int], goal: tuple[int, int]): self.start = Node(start[1], start[0], goal[1], goal[0], 0, None) self.target = Node(goal[1], goal[0], goal[1], goal[0], 99999, None) self.open_nodes = [self.start] self.closed_nodes: list[Node] = [] self.reached = False def search(self) -> Path | None: """ Search for the path, if a path is not found, only the starting position is returned """ while self.open_nodes: # Open Nodes are sorted using __lt__ self.open_nodes.sort() current_node = self.open_nodes.pop(0) if current_node.pos == self.target.pos: self.reached = True return self.retrace_path(current_node) self.closed_nodes.append(current_node) successors = self.get_successors(current_node) for child_node in successors: if child_node in self.closed_nodes: continue if child_node not in self.open_nodes: self.open_nodes.append(child_node) else: # retrieve the best current path better_node = self.open_nodes.pop(self.open_nodes.index(child_node)) if child_node.g_cost < better_node.g_cost: self.open_nodes.append(child_node) else: self.open_nodes.append(better_node) if not self.reached: return [self.start.pos] return None def get_successors(self, parent: Node) -> list[Node]: """ Returns a list of successors (both in the grid and free spaces) """ successors = [] for action in delta: pos_x = parent.pos_x + action[1] pos_y = parent.pos_y + action[0] if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(grid) - 1): continue if grid[pos_y][pos_x] != 0: continue successors.append( Node( pos_x, pos_y, self.target.pos_y, self.target.pos_x, parent.g_cost + 1, parent, ) ) return successors def retrace_path(self, node: Node | None) -> Path: """ Retrace the path from parents to parents until start node """ current_node = node path = [] while current_node is not None: path.append((current_node.pos_y, current_node.pos_x)) current_node = current_node.parent path.reverse() return path if __name__ == "__main__": init = (0, 0) goal = (len(grid) - 1, len(grid[0]) - 1) for elem in grid: print(elem) print("------") greedy_bf = GreedyBestFirst(init, goal) path = greedy_bf.search() if path: for pos_x, pos_y in path: grid[pos_x][pos_y] = 2 for elem in grid: print(elem)
""" https://en.wikipedia.org/wiki/Best-first_search#Greedy_BFS """ from __future__ import annotations Path = list[tuple[int, int]] grid = [ [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], # 0 are free path whereas 1's are obstacles [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], ] delta = ([-1, 0], [0, -1], [1, 0], [0, 1]) # up, left, down, right class Node: """ >>> k = Node(0, 0, 4, 5, 0, None) >>> k.calculate_heuristic() 9 >>> n = Node(1, 4, 3, 4, 2, None) >>> n.calculate_heuristic() 2 >>> l = [k, n] >>> n == l[0] False >>> l.sort() >>> n == l[0] True """ def __init__( self, pos_x: int, pos_y: int, goal_x: int, goal_y: int, g_cost: float, parent: Node | None, ): self.pos_x = pos_x self.pos_y = pos_y self.pos = (pos_y, pos_x) self.goal_x = goal_x self.goal_y = goal_y self.g_cost = g_cost self.parent = parent self.f_cost = self.calculate_heuristic() def calculate_heuristic(self) -> float: """ The heuristic here is the Manhattan Distance Could elaborate to offer more than one choice """ dy = abs(self.pos_x - self.goal_x) dx = abs(self.pos_y - self.goal_y) return dx + dy def __lt__(self, other) -> bool: return self.f_cost < other.f_cost class GreedyBestFirst: """ >>> gbf = GreedyBestFirst((0, 0), (len(grid) - 1, len(grid[0]) - 1)) >>> [x.pos for x in gbf.get_successors(gbf.start)] [(1, 0), (0, 1)] >>> (gbf.start.pos_y + delta[3][0], gbf.start.pos_x + delta[3][1]) (0, 1) >>> (gbf.start.pos_y + delta[2][0], gbf.start.pos_x + delta[2][1]) (1, 0) >>> gbf.retrace_path(gbf.start) [(0, 0)] >>> gbf.search() # doctest: +NORMALIZE_WHITESPACE [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (4, 1), (5, 1), (6, 1), (6, 2), (6, 3), (5, 3), (5, 4), (5, 5), (6, 5), (6, 6)] """ def __init__(self, start: tuple[int, int], goal: tuple[int, int]): self.start = Node(start[1], start[0], goal[1], goal[0], 0, None) self.target = Node(goal[1], goal[0], goal[1], goal[0], 99999, None) self.open_nodes = [self.start] self.closed_nodes: list[Node] = [] self.reached = False def search(self) -> Path | None: """ Search for the path, if a path is not found, only the starting position is returned """ while self.open_nodes: # Open Nodes are sorted using __lt__ self.open_nodes.sort() current_node = self.open_nodes.pop(0) if current_node.pos == self.target.pos: self.reached = True return self.retrace_path(current_node) self.closed_nodes.append(current_node) successors = self.get_successors(current_node) for child_node in successors: if child_node in self.closed_nodes: continue if child_node not in self.open_nodes: self.open_nodes.append(child_node) else: # retrieve the best current path better_node = self.open_nodes.pop(self.open_nodes.index(child_node)) if child_node.g_cost < better_node.g_cost: self.open_nodes.append(child_node) else: self.open_nodes.append(better_node) if not self.reached: return [self.start.pos] return None def get_successors(self, parent: Node) -> list[Node]: """ Returns a list of successors (both in the grid and free spaces) """ successors = [] for action in delta: pos_x = parent.pos_x + action[1] pos_y = parent.pos_y + action[0] if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(grid) - 1): continue if grid[pos_y][pos_x] != 0: continue successors.append( Node( pos_x, pos_y, self.target.pos_y, self.target.pos_x, parent.g_cost + 1, parent, ) ) return successors def retrace_path(self, node: Node | None) -> Path: """ Retrace the path from parents to parents until start node """ current_node = node path = [] while current_node is not None: path.append((current_node.pos_y, current_node.pos_x)) current_node = current_node.parent path.reverse() return path if __name__ == "__main__": init = (0, 0) goal = (len(grid) - 1, len(grid[0]) - 1) for elem in grid: print(elem) print("------") greedy_bf = GreedyBestFirst(init, goal) path = greedy_bf.search() if path: for pos_x, pos_y in path: grid[pos_x][pos_y] = 2 for elem in grid: print(elem)
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
# An island in matrix is a group of linked areas, all having the same value. # This code counts number of islands in a given matrix, with including diagonal # connections. class matrix: # Public class to implement a graph def __init__(self, row: int, col: int, graph: list): self.ROW = row self.COL = col self.graph = graph def is_safe(self, i, j, visited) -> bool: return ( 0 <= i < self.ROW and 0 <= j < self.COL and not visited[i][j] and self.graph[i][j] ) def diffs(self, i, j, visited): # Checking all 8 elements surrounding nth element rowNbr = [-1, -1, -1, 0, 0, 1, 1, 1] # Coordinate order colNbr = [-1, 0, 1, -1, 1, -1, 0, 1] visited[i][j] = True # Make those cells visited for k in range(8): if self.is_safe(i + rowNbr[k], j + colNbr[k], visited): self.diffs(i + rowNbr[k], j + colNbr[k], visited) def count_islands(self) -> int: # And finally, count all islands. visited = [[False for j in range(self.COL)] for i in range(self.ROW)] count = 0 for i in range(self.ROW): for j in range(self.COL): if visited[i][j] is False and self.graph[i][j] == 1: self.diffs(i, j, visited) count += 1 return count
# An island in matrix is a group of linked areas, all having the same value. # This code counts number of islands in a given matrix, with including diagonal # connections. class matrix: # Public class to implement a graph def __init__(self, row: int, col: int, graph: list): self.ROW = row self.COL = col self.graph = graph def is_safe(self, i, j, visited) -> bool: return ( 0 <= i < self.ROW and 0 <= j < self.COL and not visited[i][j] and self.graph[i][j] ) def diffs(self, i, j, visited): # Checking all 8 elements surrounding nth element rowNbr = [-1, -1, -1, 0, 0, 1, 1, 1] # Coordinate order colNbr = [-1, 0, 1, -1, 1, -1, 0, 1] visited[i][j] = True # Make those cells visited for k in range(8): if self.is_safe(i + rowNbr[k], j + colNbr[k], visited): self.diffs(i + rowNbr[k], j + colNbr[k], visited) def count_islands(self) -> int: # And finally, count all islands. visited = [[False for j in range(self.COL)] for i in range(self.ROW)] count = 0 for i in range(self.ROW): for j in range(self.COL): if visited[i][j] is False and self.graph[i][j] == 1: self.diffs(i, j, visited) count += 1 return count
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" 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/ """ def ugly_numbers(n: int) -> int: """ Returns the nth ugly number. >>> ugly_numbers(100) 1536 >>> ugly_numbers(0) 1 >>> ugly_numbers(20) 36 >>> ugly_numbers(-5) 1 >>> ugly_numbers(-5.5) Traceback (most recent call last): ... TypeError: 'float' object cannot be interpreted as an integer """ ugly_nums = [1] i2, i3, i5 = 0, 0, 0 next_2 = ugly_nums[i2] * 2 next_3 = ugly_nums[i3] * 3 next_5 = ugly_nums[i5] * 5 for i in range(1, n): next_num = min(next_2, next_3, next_5) ugly_nums.append(next_num) if next_num == next_2: i2 += 1 next_2 = ugly_nums[i2] * 2 if next_num == next_3: i3 += 1 next_3 = ugly_nums[i3] * 3 if next_num == next_5: i5 += 1 next_5 = ugly_nums[i5] * 5 return ugly_nums[-1] if __name__ == "__main__": from doctest import testmod testmod(verbose=True) print(f"{ugly_numbers(200) = }")
""" 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/ """ def ugly_numbers(n: int) -> int: """ Returns the nth ugly number. >>> ugly_numbers(100) 1536 >>> ugly_numbers(0) 1 >>> ugly_numbers(20) 36 >>> ugly_numbers(-5) 1 >>> ugly_numbers(-5.5) Traceback (most recent call last): ... TypeError: 'float' object cannot be interpreted as an integer """ ugly_nums = [1] i2, i3, i5 = 0, 0, 0 next_2 = ugly_nums[i2] * 2 next_3 = ugly_nums[i3] * 3 next_5 = ugly_nums[i5] * 5 for i in range(1, n): next_num = min(next_2, next_3, next_5) ugly_nums.append(next_num) if next_num == next_2: i2 += 1 next_2 = ugly_nums[i2] * 2 if next_num == next_3: i3 += 1 next_3 = ugly_nums[i3] * 3 if next_num == next_5: i5 += 1 next_5 = ugly_nums[i5] * 5 return ugly_nums[-1] if __name__ == "__main__": from doctest import testmod testmod(verbose=True) print(f"{ugly_numbers(200) = }")
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from typing import Literal LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" def translate_message( key: str, message: str, mode: Literal["encrypt", "decrypt"] ) -> str: """ >>> translate_message("QWERTYUIOPASDFGHJKLZXCVBNM","Hello World","encrypt") 'Pcssi Bidsm' """ chars_a = LETTERS if mode == "decrypt" else key chars_b = key if mode == "decrypt" else LETTERS translated = "" # loop through each symbol in the message for symbol in message: if symbol.upper() in chars_a: # encrypt/decrypt the symbol sym_index = chars_a.find(symbol.upper()) if symbol.isupper(): translated += chars_b[sym_index].upper() else: translated += chars_b[sym_index].lower() else: # symbol is not in LETTERS, just add it translated += symbol return translated def encrypt_message(key: str, message: str) -> str: """ >>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Pcssi Bidsm' """ return translate_message(key, message, "encrypt") def decrypt_message(key: str, message: str) -> str: """ >>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Itssg Vgksr' """ return translate_message(key, message, "decrypt") def main() -> None: message = "Hello World" key = "QWERTYUIOPASDFGHJKLZXCVBNM" mode = "decrypt" # set to 'encrypt' or 'decrypt' if mode == "encrypt": translated = encrypt_message(key, message) elif mode == "decrypt": translated = decrypt_message(key, message) print(f"Using the key {key}, the {mode}ed message is: {translated}") if __name__ == "__main__": import doctest doctest.testmod() main()
from typing import Literal LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" def translate_message( key: str, message: str, mode: Literal["encrypt", "decrypt"] ) -> str: """ >>> translate_message("QWERTYUIOPASDFGHJKLZXCVBNM","Hello World","encrypt") 'Pcssi Bidsm' """ chars_a = LETTERS if mode == "decrypt" else key chars_b = key if mode == "decrypt" else LETTERS translated = "" # loop through each symbol in the message for symbol in message: if symbol.upper() in chars_a: # encrypt/decrypt the symbol sym_index = chars_a.find(symbol.upper()) if symbol.isupper(): translated += chars_b[sym_index].upper() else: translated += chars_b[sym_index].lower() else: # symbol is not in LETTERS, just add it translated += symbol return translated def encrypt_message(key: str, message: str) -> str: """ >>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Pcssi Bidsm' """ return translate_message(key, message, "encrypt") def decrypt_message(key: str, message: str) -> str: """ >>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Itssg Vgksr' """ return translate_message(key, message, "decrypt") def main() -> None: message = "Hello World" key = "QWERTYUIOPASDFGHJKLZXCVBNM" mode = "decrypt" # set to 'encrypt' or 'decrypt' if mode == "encrypt": translated = encrypt_message(key, message) elif mode == "decrypt": translated = decrypt_message(key, message) print(f"Using the key {key}, the {mode}ed message is: {translated}") if __name__ == "__main__": import doctest doctest.testmod() main()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" This is pure Python implementation of linear search algorithm For doctests run following command: python3 -m doctest -v linear_search.py For manual testing run: python3 linear_search.py """ def linear_search(sequence: list, target: int) -> int: """A pure Python implementation of a linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param target: item value to search :return: index of found item or None if item is not found Examples: >>> linear_search([0, 5, 7, 10, 15], 0) 0 >>> linear_search([0, 5, 7, 10, 15], 15) 4 >>> linear_search([0, 5, 7, 10, 15], 5) 1 >>> linear_search([0, 5, 7, 10, 15], 6) -1 """ for index, item in enumerate(sequence): if item == target: return index return -1 def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int: """ A pure Python implementation of a recursive linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param low: Lower bound of the array :param high: Higher bound of the array :param target: The element to be found :return: Index of the key or -1 if key not found Examples: >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 0) 0 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 700) 4 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 30) 1 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, -6) -1 """ if not (0 <= high < len(sequence) and 0 <= low < len(sequence)): raise Exception("Invalid upper or lower bound!") if high < low: return -1 if sequence[low] == target: return low if sequence[high] == target: return high return rec_linear_search(sequence, low + 1, high - 1, target) if __name__ == "__main__": user_input = input("Enter numbers separated by comma:\n").strip() sequence = [int(item.strip()) for item in user_input.split(",")] target = int(input("Enter a single number to be found in the list:\n").strip()) result = linear_search(sequence, target) if result != -1: print(f"linear_search({sequence}, {target}) = {result}") else: print(f"{target} was not found in {sequence}")
""" This is pure Python implementation of linear search algorithm For doctests run following command: python3 -m doctest -v linear_search.py For manual testing run: python3 linear_search.py """ def linear_search(sequence: list, target: int) -> int: """A pure Python implementation of a linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param target: item value to search :return: index of found item or None if item is not found Examples: >>> linear_search([0, 5, 7, 10, 15], 0) 0 >>> linear_search([0, 5, 7, 10, 15], 15) 4 >>> linear_search([0, 5, 7, 10, 15], 5) 1 >>> linear_search([0, 5, 7, 10, 15], 6) -1 """ for index, item in enumerate(sequence): if item == target: return index return -1 def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int: """ A pure Python implementation of a recursive linear search algorithm :param sequence: a collection with comparable items (as sorted items not required in Linear Search) :param low: Lower bound of the array :param high: Higher bound of the array :param target: The element to be found :return: Index of the key or -1 if key not found Examples: >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 0) 0 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 700) 4 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 30) 1 >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, -6) -1 """ if not (0 <= high < len(sequence) and 0 <= low < len(sequence)): raise Exception("Invalid upper or lower bound!") if high < low: return -1 if sequence[low] == target: return low if sequence[high] == target: return high return rec_linear_search(sequence, low + 1, high - 1, target) if __name__ == "__main__": user_input = input("Enter numbers separated by comma:\n").strip() sequence = [int(item.strip()) for item in user_input.split(",")] target = int(input("Enter a single number to be found in the list:\n").strip()) result = linear_search(sequence, target) if result != -1: print(f"linear_search({sequence}, {target}) = {result}") else: print(f"{target} was not found in {sequence}")
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
# Information on 2's complement: https://en.wikipedia.org/wiki/Two%27s_complement def twos_complement(number: int) -> str: """ Take in a negative integer 'number'. Return the two's complement representation of 'number'. >>> twos_complement(0) '0b0' >>> twos_complement(-1) '0b11' >>> twos_complement(-5) '0b1011' >>> twos_complement(-17) '0b101111' >>> twos_complement(-207) '0b100110001' >>> twos_complement(1) Traceback (most recent call last): ... ValueError: input must be a negative integer """ if number > 0: raise ValueError("input must be a negative integer") binary_number_length = len(bin(number)[3:]) twos_complement_number = bin(abs(number) - (1 << binary_number_length))[3:] twos_complement_number = ( ( "1" + "0" * (binary_number_length - len(twos_complement_number)) + twos_complement_number ) if number < 0 else "0" ) return "0b" + twos_complement_number if __name__ == "__main__": import doctest doctest.testmod()
# Information on 2's complement: https://en.wikipedia.org/wiki/Two%27s_complement def twos_complement(number: int) -> str: """ Take in a negative integer 'number'. Return the two's complement representation of 'number'. >>> twos_complement(0) '0b0' >>> twos_complement(-1) '0b11' >>> twos_complement(-5) '0b1011' >>> twos_complement(-17) '0b101111' >>> twos_complement(-207) '0b100110001' >>> twos_complement(1) Traceback (most recent call last): ... ValueError: input must be a negative integer """ if number > 0: raise ValueError("input must be a negative integer") binary_number_length = len(bin(number)[3:]) twos_complement_number = bin(abs(number) - (1 << binary_number_length))[3:] twos_complement_number = ( ( "1" + "0" * (binary_number_length - len(twos_complement_number)) + twos_complement_number ) if number < 0 else "0" ) return "0b" + twos_complement_number if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Author: Mohit Radadiya """ from string import ascii_uppercase dict1 = {char: i for i, char in enumerate(ascii_uppercase)} dict2 = {i: char for i, char in enumerate(ascii_uppercase)} # This function generates the key in # a cyclic manner until it's length isn't # equal to the length of original text def generate_key(message: str, key: str) -> str: """ >>> generate_key("THE GERMAN ATTACK","SECRET") 'SECRETSECRETSECRE' """ x = len(message) i = 0 while True: if x == i: i = 0 if len(key) == len(message): break key += key[i] i += 1 return key # This function returns the encrypted text # generated with the help of the key def cipher_text(message: str, key_new: str) -> str: """ >>> cipher_text("THE GERMAN ATTACK","SECRETSECRETSECRE") 'BDC PAYUWL JPAIYI' """ cipher_text = "" i = 0 for letter in message: if letter == " ": cipher_text += " " else: x = (dict1[letter] - dict1[key_new[i]]) % 26 i += 1 cipher_text += dict2[x] return cipher_text # This function decrypts the encrypted text # and returns the original text def original_text(cipher_text: str, key_new: str) -> str: """ >>> original_text("BDC PAYUWL JPAIYI","SECRETSECRETSECRE") 'THE GERMAN ATTACK' """ or_txt = "" i = 0 for letter in cipher_text: if letter == " ": or_txt += " " else: x = (dict1[letter] + dict1[key_new[i]] + 26) % 26 i += 1 or_txt += dict2[x] return or_txt def main() -> None: message = "THE GERMAN ATTACK" key = "SECRET" key_new = generate_key(message, key) s = cipher_text(message, key_new) print(f"Encrypted Text = {s}") print(f"Original Text = {original_text(s, key_new)}") if __name__ == "__main__": import doctest doctest.testmod() main()
""" Author: Mohit Radadiya """ from string import ascii_uppercase dict1 = {char: i for i, char in enumerate(ascii_uppercase)} dict2 = {i: char for i, char in enumerate(ascii_uppercase)} # This function generates the key in # a cyclic manner until it's length isn't # equal to the length of original text def generate_key(message: str, key: str) -> str: """ >>> generate_key("THE GERMAN ATTACK","SECRET") 'SECRETSECRETSECRE' """ x = len(message) i = 0 while True: if x == i: i = 0 if len(key) == len(message): break key += key[i] i += 1 return key # This function returns the encrypted text # generated with the help of the key def cipher_text(message: str, key_new: str) -> str: """ >>> cipher_text("THE GERMAN ATTACK","SECRETSECRETSECRE") 'BDC PAYUWL JPAIYI' """ cipher_text = "" i = 0 for letter in message: if letter == " ": cipher_text += " " else: x = (dict1[letter] - dict1[key_new[i]]) % 26 i += 1 cipher_text += dict2[x] return cipher_text # This function decrypts the encrypted text # and returns the original text def original_text(cipher_text: str, key_new: str) -> str: """ >>> original_text("BDC PAYUWL JPAIYI","SECRETSECRETSECRE") 'THE GERMAN ATTACK' """ or_txt = "" i = 0 for letter in cipher_text: if letter == " ": or_txt += " " else: x = (dict1[letter] + dict1[key_new[i]] + 26) % 26 i += 1 or_txt += dict2[x] return or_txt def main() -> None: message = "THE GERMAN ATTACK" key = "SECRET" key_new = generate_key(message, key) s = cipher_text(message, key_new) print(f"Encrypted Text = {s}") print(f"Original Text = {original_text(s, key_new)}") if __name__ == "__main__": import doctest doctest.testmod() main()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
# flake8: noqa """ Binomial Heap Reference: Advanced Data Structures, Peter Brass """ class Node: """ Node in a doubly-linked binomial tree, containing: - value - size of left subtree - link to left, right and parent nodes """ def __init__(self, val): self.val = val # Number of nodes in left subtree self.left_tree_size = 0 self.left = None self.right = None self.parent = None def mergeTrees(self, other): """ In-place merge of two binomial trees of equal size. Returns the root of the resulting tree """ assert self.left_tree_size == other.left_tree_size, "Unequal Sizes of Blocks" if self.val < other.val: other.left = self.right other.parent = None if self.right: self.right.parent = other self.right = other self.left_tree_size = self.left_tree_size * 2 + 1 return self else: self.left = other.right self.parent = None if other.right: other.right.parent = self other.right = self other.left_tree_size = other.left_tree_size * 2 + 1 return other class BinomialHeap: r""" Min-oriented priority queue implemented with the Binomial Heap data structure implemented with the BinomialHeap class. It supports: - Insert element in a heap with n elements: Guaranteed logn, amoratized 1 - Merge (meld) heaps of size m and n: O(logn + logm) - Delete Min: O(logn) - Peek (return min without deleting it): O(1) Example: Create a random permutation of 30 integers to be inserted and 19 of them deleted >>> import numpy as np >>> permutation = np.random.permutation(list(range(30))) Create a Heap and insert the 30 integers __init__() test >>> first_heap = BinomialHeap() 30 inserts - insert() test >>> for number in permutation: ... first_heap.insert(number) Size test >>> print(first_heap.size) 30 Deleting - delete() test >>> for i in range(25): ... print(first_heap.deleteMin(), end=" ") 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Create a new Heap >>> second_heap = BinomialHeap() >>> vals = [17, 20, 31, 34] >>> for value in vals: ... second_heap.insert(value) The heap should have the following structure: 17 / \ # 31 / \ 20 34 / \ / \ # # # # preOrder() test >>> print(second_heap.preOrder()) [(17, 0), ('#', 1), (31, 1), (20, 2), ('#', 3), ('#', 3), (34, 2), ('#', 3), ('#', 3)] printing Heap - __str__() test >>> print(second_heap) 17 -# -31 --20 ---# ---# --34 ---# ---# mergeHeaps() test >>> merged = second_heap.mergeHeaps(first_heap) >>> merged.peek() 17 values in merged heap; (merge is inplace) >>> while not first_heap.isEmpty(): ... print(first_heap.deleteMin(), end=" ") 17 20 25 26 27 28 29 31 34 """ def __init__(self, bottom_root=None, min_node=None, heap_size=0): self.size = heap_size self.bottom_root = bottom_root self.min_node = min_node def mergeHeaps(self, other): """ In-place merge of two binomial heaps. Both of them become the resulting merged heap """ # Empty heaps corner cases if other.size == 0: return if self.size == 0: self.size = other.size self.bottom_root = other.bottom_root self.min_node = other.min_node return # Update size self.size = self.size + other.size # Update min.node if self.min_node.val > other.min_node.val: self.min_node = other.min_node # Merge # Order roots by left_subtree_size combined_roots_list = [] i, j = self.bottom_root, other.bottom_root while i or j: if i and ((not j) or i.left_tree_size < j.left_tree_size): combined_roots_list.append((i, True)) i = i.parent else: combined_roots_list.append((j, False)) j = j.parent # Insert links between them for i in range(len(combined_roots_list) - 1): if combined_roots_list[i][1] != combined_roots_list[i + 1][1]: combined_roots_list[i][0].parent = combined_roots_list[i + 1][0] combined_roots_list[i + 1][0].left = combined_roots_list[i][0] # Consecutively merge roots with same left_tree_size i = combined_roots_list[0][0] while i.parent: if ( (i.left_tree_size == i.parent.left_tree_size) and (not i.parent.parent) ) or ( i.left_tree_size == i.parent.left_tree_size and i.left_tree_size != i.parent.parent.left_tree_size ): # Neighbouring Nodes previous_node = i.left next_node = i.parent.parent # Merging trees i = i.mergeTrees(i.parent) # Updating links i.left = previous_node i.parent = next_node if previous_node: previous_node.parent = i if next_node: next_node.left = i else: i = i.parent # Updating self.bottom_root while i.left: i = i.left self.bottom_root = i # Update other other.size = self.size other.bottom_root = self.bottom_root other.min_node = self.min_node # Return the merged heap return self def insert(self, val): """ insert a value in the heap """ if self.size == 0: self.bottom_root = Node(val) self.size = 1 self.min_node = self.bottom_root else: # Create new node new_node = Node(val) # Update size self.size += 1 # update min_node if val < self.min_node.val: self.min_node = new_node # Put new_node as a bottom_root in heap self.bottom_root.left = new_node new_node.parent = self.bottom_root self.bottom_root = new_node # Consecutively merge roots with same left_tree_size while ( self.bottom_root.parent and self.bottom_root.left_tree_size == self.bottom_root.parent.left_tree_size ): # Next node next_node = self.bottom_root.parent.parent # Merge self.bottom_root = self.bottom_root.mergeTrees(self.bottom_root.parent) # Update Links self.bottom_root.parent = next_node self.bottom_root.left = None if next_node: next_node.left = self.bottom_root def peek(self): """ return min element without deleting it """ return self.min_node.val def isEmpty(self): return self.size == 0 def deleteMin(self): """ delete min element and return it """ # assert not self.isEmpty(), "Empty Heap" # Save minimal value min_value = self.min_node.val # Last element in heap corner case if self.size == 1: # Update size self.size = 0 # Update bottom root self.bottom_root = None # Update min_node self.min_node = None return min_value # No right subtree corner case # The structure of the tree implies that this should be the bottom root # and there is at least one other root if self.min_node.right is None: # Update size self.size -= 1 # Update bottom root self.bottom_root = self.bottom_root.parent self.bottom_root.left = None # Update min_node self.min_node = self.bottom_root i = self.bottom_root.parent while i: if i.val < self.min_node.val: self.min_node = i i = i.parent return min_value # General case # Find the BinomialHeap of the right subtree of min_node bottom_of_new = self.min_node.right bottom_of_new.parent = None min_of_new = bottom_of_new size_of_new = 1 # Size, min_node and bottom_root while bottom_of_new.left: size_of_new = size_of_new * 2 + 1 bottom_of_new = bottom_of_new.left if bottom_of_new.val < min_of_new.val: min_of_new = bottom_of_new # Corner case of single root on top left path if (not self.min_node.left) and (not self.min_node.parent): self.size = size_of_new self.bottom_root = bottom_of_new self.min_node = min_of_new # print("Single root, multiple nodes case") return min_value # Remaining cases # Construct heap of right subtree newHeap = BinomialHeap( bottom_root=bottom_of_new, min_node=min_of_new, heap_size=size_of_new ) # Update size self.size = self.size - 1 - size_of_new # Neighbour nodes previous_node = self.min_node.left next_node = self.min_node.parent # Initialize new bottom_root and min_node self.min_node = previous_node or next_node self.bottom_root = next_node # Update links of previous_node and search below for new min_node and # bottom_root if previous_node: previous_node.parent = next_node # Update bottom_root and search for min_node below self.bottom_root = previous_node self.min_node = previous_node while self.bottom_root.left: self.bottom_root = self.bottom_root.left if self.bottom_root.val < self.min_node.val: self.min_node = self.bottom_root if next_node: next_node.left = previous_node # Search for new min_node above min_node i = next_node while i: if i.val < self.min_node.val: self.min_node = i i = i.parent # Merge heaps self.mergeHeaps(newHeap) return min_value def preOrder(self): """ Returns the Pre-order representation of the heap including values of nodes plus their level distance from the root; Empty nodes appear as # """ # Find top root top_root = self.bottom_root while top_root.parent: top_root = top_root.parent # preorder heap_preOrder = [] self.__traversal(top_root, heap_preOrder) return heap_preOrder def __traversal(self, curr_node, preorder, level=0): """ Pre-order traversal of nodes """ if curr_node: preorder.append((curr_node.val, level)) self.__traversal(curr_node.left, preorder, level + 1) self.__traversal(curr_node.right, preorder, level + 1) else: preorder.append(("#", level)) def __str__(self): """ Overwriting str for a pre-order print of nodes in heap; Performance is poor, so use only for small examples """ if self.isEmpty(): return "" preorder_heap = self.preOrder() return "\n".join(("-" * level + str(value)) for value, level in preorder_heap) # Unit Tests if __name__ == "__main__": import doctest doctest.testmod()
# flake8: noqa """ Binomial Heap Reference: Advanced Data Structures, Peter Brass """ class Node: """ Node in a doubly-linked binomial tree, containing: - value - size of left subtree - link to left, right and parent nodes """ def __init__(self, val): self.val = val # Number of nodes in left subtree self.left_tree_size = 0 self.left = None self.right = None self.parent = None def mergeTrees(self, other): """ In-place merge of two binomial trees of equal size. Returns the root of the resulting tree """ assert self.left_tree_size == other.left_tree_size, "Unequal Sizes of Blocks" if self.val < other.val: other.left = self.right other.parent = None if self.right: self.right.parent = other self.right = other self.left_tree_size = self.left_tree_size * 2 + 1 return self else: self.left = other.right self.parent = None if other.right: other.right.parent = self other.right = self other.left_tree_size = other.left_tree_size * 2 + 1 return other class BinomialHeap: r""" Min-oriented priority queue implemented with the Binomial Heap data structure implemented with the BinomialHeap class. It supports: - Insert element in a heap with n elements: Guaranteed logn, amoratized 1 - Merge (meld) heaps of size m and n: O(logn + logm) - Delete Min: O(logn) - Peek (return min without deleting it): O(1) Example: Create a random permutation of 30 integers to be inserted and 19 of them deleted >>> import numpy as np >>> permutation = np.random.permutation(list(range(30))) Create a Heap and insert the 30 integers __init__() test >>> first_heap = BinomialHeap() 30 inserts - insert() test >>> for number in permutation: ... first_heap.insert(number) Size test >>> print(first_heap.size) 30 Deleting - delete() test >>> for i in range(25): ... print(first_heap.deleteMin(), end=" ") 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Create a new Heap >>> second_heap = BinomialHeap() >>> vals = [17, 20, 31, 34] >>> for value in vals: ... second_heap.insert(value) The heap should have the following structure: 17 / \ # 31 / \ 20 34 / \ / \ # # # # preOrder() test >>> print(second_heap.preOrder()) [(17, 0), ('#', 1), (31, 1), (20, 2), ('#', 3), ('#', 3), (34, 2), ('#', 3), ('#', 3)] printing Heap - __str__() test >>> print(second_heap) 17 -# -31 --20 ---# ---# --34 ---# ---# mergeHeaps() test >>> merged = second_heap.mergeHeaps(first_heap) >>> merged.peek() 17 values in merged heap; (merge is inplace) >>> while not first_heap.isEmpty(): ... print(first_heap.deleteMin(), end=" ") 17 20 25 26 27 28 29 31 34 """ def __init__(self, bottom_root=None, min_node=None, heap_size=0): self.size = heap_size self.bottom_root = bottom_root self.min_node = min_node def mergeHeaps(self, other): """ In-place merge of two binomial heaps. Both of them become the resulting merged heap """ # Empty heaps corner cases if other.size == 0: return if self.size == 0: self.size = other.size self.bottom_root = other.bottom_root self.min_node = other.min_node return # Update size self.size = self.size + other.size # Update min.node if self.min_node.val > other.min_node.val: self.min_node = other.min_node # Merge # Order roots by left_subtree_size combined_roots_list = [] i, j = self.bottom_root, other.bottom_root while i or j: if i and ((not j) or i.left_tree_size < j.left_tree_size): combined_roots_list.append((i, True)) i = i.parent else: combined_roots_list.append((j, False)) j = j.parent # Insert links between them for i in range(len(combined_roots_list) - 1): if combined_roots_list[i][1] != combined_roots_list[i + 1][1]: combined_roots_list[i][0].parent = combined_roots_list[i + 1][0] combined_roots_list[i + 1][0].left = combined_roots_list[i][0] # Consecutively merge roots with same left_tree_size i = combined_roots_list[0][0] while i.parent: if ( (i.left_tree_size == i.parent.left_tree_size) and (not i.parent.parent) ) or ( i.left_tree_size == i.parent.left_tree_size and i.left_tree_size != i.parent.parent.left_tree_size ): # Neighbouring Nodes previous_node = i.left next_node = i.parent.parent # Merging trees i = i.mergeTrees(i.parent) # Updating links i.left = previous_node i.parent = next_node if previous_node: previous_node.parent = i if next_node: next_node.left = i else: i = i.parent # Updating self.bottom_root while i.left: i = i.left self.bottom_root = i # Update other other.size = self.size other.bottom_root = self.bottom_root other.min_node = self.min_node # Return the merged heap return self def insert(self, val): """ insert a value in the heap """ if self.size == 0: self.bottom_root = Node(val) self.size = 1 self.min_node = self.bottom_root else: # Create new node new_node = Node(val) # Update size self.size += 1 # update min_node if val < self.min_node.val: self.min_node = new_node # Put new_node as a bottom_root in heap self.bottom_root.left = new_node new_node.parent = self.bottom_root self.bottom_root = new_node # Consecutively merge roots with same left_tree_size while ( self.bottom_root.parent and self.bottom_root.left_tree_size == self.bottom_root.parent.left_tree_size ): # Next node next_node = self.bottom_root.parent.parent # Merge self.bottom_root = self.bottom_root.mergeTrees(self.bottom_root.parent) # Update Links self.bottom_root.parent = next_node self.bottom_root.left = None if next_node: next_node.left = self.bottom_root def peek(self): """ return min element without deleting it """ return self.min_node.val def isEmpty(self): return self.size == 0 def deleteMin(self): """ delete min element and return it """ # assert not self.isEmpty(), "Empty Heap" # Save minimal value min_value = self.min_node.val # Last element in heap corner case if self.size == 1: # Update size self.size = 0 # Update bottom root self.bottom_root = None # Update min_node self.min_node = None return min_value # No right subtree corner case # The structure of the tree implies that this should be the bottom root # and there is at least one other root if self.min_node.right is None: # Update size self.size -= 1 # Update bottom root self.bottom_root = self.bottom_root.parent self.bottom_root.left = None # Update min_node self.min_node = self.bottom_root i = self.bottom_root.parent while i: if i.val < self.min_node.val: self.min_node = i i = i.parent return min_value # General case # Find the BinomialHeap of the right subtree of min_node bottom_of_new = self.min_node.right bottom_of_new.parent = None min_of_new = bottom_of_new size_of_new = 1 # Size, min_node and bottom_root while bottom_of_new.left: size_of_new = size_of_new * 2 + 1 bottom_of_new = bottom_of_new.left if bottom_of_new.val < min_of_new.val: min_of_new = bottom_of_new # Corner case of single root on top left path if (not self.min_node.left) and (not self.min_node.parent): self.size = size_of_new self.bottom_root = bottom_of_new self.min_node = min_of_new # print("Single root, multiple nodes case") return min_value # Remaining cases # Construct heap of right subtree newHeap = BinomialHeap( bottom_root=bottom_of_new, min_node=min_of_new, heap_size=size_of_new ) # Update size self.size = self.size - 1 - size_of_new # Neighbour nodes previous_node = self.min_node.left next_node = self.min_node.parent # Initialize new bottom_root and min_node self.min_node = previous_node or next_node self.bottom_root = next_node # Update links of previous_node and search below for new min_node and # bottom_root if previous_node: previous_node.parent = next_node # Update bottom_root and search for min_node below self.bottom_root = previous_node self.min_node = previous_node while self.bottom_root.left: self.bottom_root = self.bottom_root.left if self.bottom_root.val < self.min_node.val: self.min_node = self.bottom_root if next_node: next_node.left = previous_node # Search for new min_node above min_node i = next_node while i: if i.val < self.min_node.val: self.min_node = i i = i.parent # Merge heaps self.mergeHeaps(newHeap) return min_value def preOrder(self): """ Returns the Pre-order representation of the heap including values of nodes plus their level distance from the root; Empty nodes appear as # """ # Find top root top_root = self.bottom_root while top_root.parent: top_root = top_root.parent # preorder heap_preOrder = [] self.__traversal(top_root, heap_preOrder) return heap_preOrder def __traversal(self, curr_node, preorder, level=0): """ Pre-order traversal of nodes """ if curr_node: preorder.append((curr_node.val, level)) self.__traversal(curr_node.left, preorder, level + 1) self.__traversal(curr_node.right, preorder, level + 1) else: preorder.append(("#", level)) def __str__(self): """ Overwriting str for a pre-order print of nodes in heap; Performance is poor, so use only for small examples """ if self.isEmpty(): return "" preorder_heap = self.preOrder() return "\n".join(("-" * level + str(value)) for value, level in preorder_heap) # Unit Tests if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" https://en.wikipedia.org/wiki/Computus#Gauss'_Easter_algorithm """ import math from datetime import datetime, timedelta def gauss_easter(year: int) -> datetime: """ Calculation Gregorian easter date for given year >>> gauss_easter(2007) datetime.datetime(2007, 4, 8, 0, 0) >>> gauss_easter(2008) datetime.datetime(2008, 3, 23, 0, 0) >>> gauss_easter(2020) datetime.datetime(2020, 4, 12, 0, 0) >>> gauss_easter(2021) datetime.datetime(2021, 4, 4, 0, 0) """ metonic_cycle = year % 19 julian_leap_year = year % 4 non_leap_year = year % 7 leap_day_inhibits = math.floor(year / 100) lunar_orbit_correction = math.floor((13 + 8 * leap_day_inhibits) / 25) leap_day_reinstall_number = leap_day_inhibits / 4 secular_moon_shift = ( 15 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number ) % 30 century_starting_point = (4 + leap_day_inhibits - leap_day_reinstall_number) % 7 # days to be added to March 21 days_to_add = (19 * metonic_cycle + secular_moon_shift) % 30 # PHM -> Paschal Full Moon days_from_phm_to_sunday = ( 2 * julian_leap_year + 4 * non_leap_year + 6 * days_to_add + century_starting_point ) % 7 if days_to_add == 29 and days_from_phm_to_sunday == 6: return datetime(year, 4, 19) elif days_to_add == 28 and days_from_phm_to_sunday == 6: return datetime(year, 4, 18) else: return datetime(year, 3, 22) + timedelta( days=int(days_to_add + days_from_phm_to_sunday) ) if __name__ == "__main__": for year in (1994, 2000, 2010, 2021, 2023): tense = "will be" if year > datetime.now().year else "was" print(f"Easter in {year} {tense} {gauss_easter(year)}")
""" https://en.wikipedia.org/wiki/Computus#Gauss'_Easter_algorithm """ import math from datetime import datetime, timedelta def gauss_easter(year: int) -> datetime: """ Calculation Gregorian easter date for given year >>> gauss_easter(2007) datetime.datetime(2007, 4, 8, 0, 0) >>> gauss_easter(2008) datetime.datetime(2008, 3, 23, 0, 0) >>> gauss_easter(2020) datetime.datetime(2020, 4, 12, 0, 0) >>> gauss_easter(2021) datetime.datetime(2021, 4, 4, 0, 0) """ metonic_cycle = year % 19 julian_leap_year = year % 4 non_leap_year = year % 7 leap_day_inhibits = math.floor(year / 100) lunar_orbit_correction = math.floor((13 + 8 * leap_day_inhibits) / 25) leap_day_reinstall_number = leap_day_inhibits / 4 secular_moon_shift = ( 15 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number ) % 30 century_starting_point = (4 + leap_day_inhibits - leap_day_reinstall_number) % 7 # days to be added to March 21 days_to_add = (19 * metonic_cycle + secular_moon_shift) % 30 # PHM -> Paschal Full Moon days_from_phm_to_sunday = ( 2 * julian_leap_year + 4 * non_leap_year + 6 * days_to_add + century_starting_point ) % 7 if days_to_add == 29 and days_from_phm_to_sunday == 6: return datetime(year, 4, 19) elif days_to_add == 28 and days_from_phm_to_sunday == 6: return datetime(year, 4, 18) else: return datetime(year, 3, 22) + timedelta( days=int(days_to_add + days_from_phm_to_sunday) ) if __name__ == "__main__": for year in (1994, 2000, 2010, 2021, 2023): tense = "will be" if year > datetime.now().year else "was" print(f"Easter in {year} {tense} {gauss_easter(year)}")
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" This is a pure Python implementation of the heap sort algorithm. For doctests run following command: python -m doctest -v heap_sort.py or python3 -m doctest -v heap_sort.py For manual testing run: python heap_sort.py """ def heapify(unsorted, index, heap_size): largest = index left_index = 2 * index + 1 right_index = 2 * index + 2 if left_index < heap_size and unsorted[left_index] > unsorted[largest]: largest = left_index if right_index < heap_size and unsorted[right_index] > unsorted[largest]: largest = right_index if largest != index: unsorted[largest], unsorted[index] = unsorted[index], unsorted[largest] heapify(unsorted, largest, heap_size) def heap_sort(unsorted): """ Pure implementation of the heap sort algorithm in Python :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> heap_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> heap_sort([]) [] >>> heap_sort([-2, -5, -45]) [-45, -5, -2] """ n = len(unsorted) for i in range(n // 2 - 1, -1, -1): heapify(unsorted, i, n) for i in range(n - 1, 0, -1): unsorted[0], unsorted[i] = unsorted[i], unsorted[0] heapify(unsorted, 0, i) return unsorted if __name__ == "__main__": user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] print(heap_sort(unsorted))
""" This is a pure Python implementation of the heap sort algorithm. For doctests run following command: python -m doctest -v heap_sort.py or python3 -m doctest -v heap_sort.py For manual testing run: python heap_sort.py """ def heapify(unsorted, index, heap_size): largest = index left_index = 2 * index + 1 right_index = 2 * index + 2 if left_index < heap_size and unsorted[left_index] > unsorted[largest]: largest = left_index if right_index < heap_size and unsorted[right_index] > unsorted[largest]: largest = right_index if largest != index: unsorted[largest], unsorted[index] = unsorted[index], unsorted[largest] heapify(unsorted, largest, heap_size) def heap_sort(unsorted): """ Pure implementation of the heap sort algorithm in Python :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> heap_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> heap_sort([]) [] >>> heap_sort([-2, -5, -45]) [-45, -5, -2] """ n = len(unsorted) for i in range(n // 2 - 1, -1, -1): heapify(unsorted, i, n) for i in range(n - 1, 0, -1): unsorted[0], unsorted[i] = unsorted[i], unsorted[0] heapify(unsorted, 0, i) return unsorted if __name__ == "__main__": user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] print(heap_sort(unsorted))
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
#!/bin/python3 # Doomsday algorithm info: https://en.wikipedia.org/wiki/Doomsday_rule DOOMSDAY_LEAP = [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] DOOMSDAY_NOT_LEAP = [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] WEEK_DAY_NAMES = { 0: "Sunday", 1: "Monday", 2: "Tuesday", 3: "Wednesday", 4: "Thursday", 5: "Friday", 6: "Saturday", } def get_week_day(year: int, month: int, day: int) -> str: """Returns the week-day name out of a given date. >>> get_week_day(2020, 10, 24) 'Saturday' >>> get_week_day(2017, 10, 24) 'Tuesday' >>> get_week_day(2019, 5, 3) 'Friday' >>> get_week_day(1970, 9, 16) 'Wednesday' >>> get_week_day(1870, 8, 13) 'Saturday' >>> get_week_day(2040, 3, 14) 'Wednesday' """ # minimal input check: assert len(str(year)) > 2, "year should be in YYYY format" assert 1 <= month <= 12, "month should be between 1 to 12" assert 1 <= day <= 31, "day should be between 1 to 31" # Doomsday algorithm: century = year // 100 century_anchor = (5 * (century % 4) + 2) % 7 centurian = year % 100 centurian_m = centurian % 12 dooms_day = ( (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor ) % 7 day_anchor = ( DOOMSDAY_NOT_LEAP[month - 1] if (year % 4 != 0) or (centurian == 0 and (year % 400) == 0) else DOOMSDAY_LEAP[month - 1] ) week_day = (dooms_day + day - day_anchor) % 7 return WEEK_DAY_NAMES[week_day] if __name__ == "__main__": import doctest doctest.testmod()
#!/bin/python3 # Doomsday algorithm info: https://en.wikipedia.org/wiki/Doomsday_rule DOOMSDAY_LEAP = [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] DOOMSDAY_NOT_LEAP = [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] WEEK_DAY_NAMES = { 0: "Sunday", 1: "Monday", 2: "Tuesday", 3: "Wednesday", 4: "Thursday", 5: "Friday", 6: "Saturday", } def get_week_day(year: int, month: int, day: int) -> str: """Returns the week-day name out of a given date. >>> get_week_day(2020, 10, 24) 'Saturday' >>> get_week_day(2017, 10, 24) 'Tuesday' >>> get_week_day(2019, 5, 3) 'Friday' >>> get_week_day(1970, 9, 16) 'Wednesday' >>> get_week_day(1870, 8, 13) 'Saturday' >>> get_week_day(2040, 3, 14) 'Wednesday' """ # minimal input check: assert len(str(year)) > 2, "year should be in YYYY format" assert 1 <= month <= 12, "month should be between 1 to 12" assert 1 <= day <= 31, "day should be between 1 to 31" # Doomsday algorithm: century = year // 100 century_anchor = (5 * (century % 4) + 2) % 7 centurian = year % 100 centurian_m = centurian % 12 dooms_day = ( (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor ) % 7 day_anchor = ( DOOMSDAY_NOT_LEAP[month - 1] if (year % 4 != 0) or (centurian == 0 and (year % 400) == 0) else DOOMSDAY_LEAP[month - 1] ) week_day = (dooms_day + day - day_anchor) % 7 return WEEK_DAY_NAMES[week_day] if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
#!/usr/bin/env python3 # Author: OMKAR PATHAK, Nwachukwu Chidiebere # Use a Python dictionary to construct the graph. from __future__ import annotations from pprint import pformat from typing import Generic, TypeVar T = TypeVar("T") class GraphAdjacencyList(Generic[T]): """ Adjacency List type Graph Data Structure that accounts for directed and undirected Graphs. Initialize graph object indicating whether it's directed or undirected. Directed graph example: >>> d_graph = GraphAdjacencyList() >>> d_graph {} >>> d_graph.add_edge(0, 1) {0: [1], 1: []} >>> d_graph.add_edge(1, 2).add_edge(1, 4).add_edge(1, 5) {0: [1], 1: [2, 4, 5], 2: [], 4: [], 5: []} >>> d_graph.add_edge(2, 0).add_edge(2, 6).add_edge(2, 7) {0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []} >>> print(d_graph) {0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []} >>> print(repr(d_graph)) {0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []} Undirected graph example: >>> u_graph = GraphAdjacencyList(directed=False) >>> u_graph.add_edge(0, 1) {0: [1], 1: [0]} >>> u_graph.add_edge(1, 2).add_edge(1, 4).add_edge(1, 5) {0: [1], 1: [0, 2, 4, 5], 2: [1], 4: [1], 5: [1]} >>> u_graph.add_edge(2, 0).add_edge(2, 6).add_edge(2, 7) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1], 5: [1], 6: [2], 7: [2]} >>> u_graph.add_edge(4, 5) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1, 5], 5: [1, 4], 6: [2], 7: [2]} >>> print(u_graph) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1, 5], 5: [1, 4], 6: [2], 7: [2]} >>> print(repr(u_graph)) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1, 5], 5: [1, 4], 6: [2], 7: [2]} >>> char_graph = GraphAdjacencyList(directed=False) >>> char_graph.add_edge('a', 'b') {'a': ['b'], 'b': ['a']} >>> char_graph.add_edge('b', 'c').add_edge('b', 'e').add_edge('b', 'f') {'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']} >>> print(char_graph) {'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']} """ def __init__(self, directed: bool = True) -> None: """ Parameters: directed: (bool) Indicates if graph is directed or undirected. Default is True. """ self.adj_list: dict[T, list[T]] = {} # dictionary of lists self.directed = directed def add_edge( self, source_vertex: T, destination_vertex: T ) -> GraphAdjacencyList[T]: """ Connects vertices together. Creates and Edge from source vertex to destination vertex. Vertices will be created if not found in graph """ if not self.directed: # For undirected graphs # if both source vertex and destination vertex are both present in the # adjacency list, add destination vertex to source vertex list of adjacent # vertices and add source vertex to destination vertex list of adjacent # vertices. if source_vertex in self.adj_list and destination_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) self.adj_list[destination_vertex].append(source_vertex) # if only source vertex is present in adjacency list, add destination vertex # to source vertex list of adjacent vertices, then create a new vertex with # destination vertex as key and assign a list containing the source vertex # as it's first adjacent vertex. elif source_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) self.adj_list[destination_vertex] = [source_vertex] # if only destination vertex is present in adjacency list, add source vertex # to destination vertex list of adjacent vertices, then create a new vertex # with source vertex as key and assign a list containing the source vertex # as it's first adjacent vertex. elif destination_vertex in self.adj_list: self.adj_list[destination_vertex].append(source_vertex) self.adj_list[source_vertex] = [destination_vertex] # if both source vertex and destination vertex are not present in adjacency # list, create a new vertex with source vertex as key and assign a list # containing the destination vertex as it's first adjacent vertex also # create a new vertex with destination vertex as key and assign a list # containing the source vertex as it's first adjacent vertex. else: self.adj_list[source_vertex] = [destination_vertex] self.adj_list[destination_vertex] = [source_vertex] else: # For directed graphs # if both source vertex and destination vertex are present in adjacency # list, add destination vertex to source vertex list of adjacent vertices. if source_vertex in self.adj_list and destination_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) # if only source vertex is present in adjacency list, add destination # vertex to source vertex list of adjacent vertices and create a new vertex # with destination vertex as key, which has no adjacent vertex elif source_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) self.adj_list[destination_vertex] = [] # if only destination vertex is present in adjacency list, create a new # vertex with source vertex as key and assign a list containing destination # vertex as first adjacent vertex elif destination_vertex in self.adj_list: self.adj_list[source_vertex] = [destination_vertex] # if both source vertex and destination vertex are not present in adjacency # list, create a new vertex with source vertex as key and a list containing # destination vertex as it's first adjacent vertex. Then create a new vertex # with destination vertex as key, which has no adjacent vertex else: self.adj_list[source_vertex] = [destination_vertex] self.adj_list[destination_vertex] = [] return self def __repr__(self) -> str: return pformat(self.adj_list)
#!/usr/bin/env python3 # Author: OMKAR PATHAK, Nwachukwu Chidiebere # Use a Python dictionary to construct the graph. from __future__ import annotations from pprint import pformat from typing import Generic, TypeVar T = TypeVar("T") class GraphAdjacencyList(Generic[T]): """ Adjacency List type Graph Data Structure that accounts for directed and undirected Graphs. Initialize graph object indicating whether it's directed or undirected. Directed graph example: >>> d_graph = GraphAdjacencyList() >>> d_graph {} >>> d_graph.add_edge(0, 1) {0: [1], 1: []} >>> d_graph.add_edge(1, 2).add_edge(1, 4).add_edge(1, 5) {0: [1], 1: [2, 4, 5], 2: [], 4: [], 5: []} >>> d_graph.add_edge(2, 0).add_edge(2, 6).add_edge(2, 7) {0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []} >>> print(d_graph) {0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []} >>> print(repr(d_graph)) {0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []} Undirected graph example: >>> u_graph = GraphAdjacencyList(directed=False) >>> u_graph.add_edge(0, 1) {0: [1], 1: [0]} >>> u_graph.add_edge(1, 2).add_edge(1, 4).add_edge(1, 5) {0: [1], 1: [0, 2, 4, 5], 2: [1], 4: [1], 5: [1]} >>> u_graph.add_edge(2, 0).add_edge(2, 6).add_edge(2, 7) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1], 5: [1], 6: [2], 7: [2]} >>> u_graph.add_edge(4, 5) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1, 5], 5: [1, 4], 6: [2], 7: [2]} >>> print(u_graph) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1, 5], 5: [1, 4], 6: [2], 7: [2]} >>> print(repr(u_graph)) {0: [1, 2], 1: [0, 2, 4, 5], 2: [1, 0, 6, 7], 4: [1, 5], 5: [1, 4], 6: [2], 7: [2]} >>> char_graph = GraphAdjacencyList(directed=False) >>> char_graph.add_edge('a', 'b') {'a': ['b'], 'b': ['a']} >>> char_graph.add_edge('b', 'c').add_edge('b', 'e').add_edge('b', 'f') {'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']} >>> print(char_graph) {'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']} """ def __init__(self, directed: bool = True) -> None: """ Parameters: directed: (bool) Indicates if graph is directed or undirected. Default is True. """ self.adj_list: dict[T, list[T]] = {} # dictionary of lists self.directed = directed def add_edge( self, source_vertex: T, destination_vertex: T ) -> GraphAdjacencyList[T]: """ Connects vertices together. Creates and Edge from source vertex to destination vertex. Vertices will be created if not found in graph """ if not self.directed: # For undirected graphs # if both source vertex and destination vertex are both present in the # adjacency list, add destination vertex to source vertex list of adjacent # vertices and add source vertex to destination vertex list of adjacent # vertices. if source_vertex in self.adj_list and destination_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) self.adj_list[destination_vertex].append(source_vertex) # if only source vertex is present in adjacency list, add destination vertex # to source vertex list of adjacent vertices, then create a new vertex with # destination vertex as key and assign a list containing the source vertex # as it's first adjacent vertex. elif source_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) self.adj_list[destination_vertex] = [source_vertex] # if only destination vertex is present in adjacency list, add source vertex # to destination vertex list of adjacent vertices, then create a new vertex # with source vertex as key and assign a list containing the source vertex # as it's first adjacent vertex. elif destination_vertex in self.adj_list: self.adj_list[destination_vertex].append(source_vertex) self.adj_list[source_vertex] = [destination_vertex] # if both source vertex and destination vertex are not present in adjacency # list, create a new vertex with source vertex as key and assign a list # containing the destination vertex as it's first adjacent vertex also # create a new vertex with destination vertex as key and assign a list # containing the source vertex as it's first adjacent vertex. else: self.adj_list[source_vertex] = [destination_vertex] self.adj_list[destination_vertex] = [source_vertex] else: # For directed graphs # if both source vertex and destination vertex are present in adjacency # list, add destination vertex to source vertex list of adjacent vertices. if source_vertex in self.adj_list and destination_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) # if only source vertex is present in adjacency list, add destination # vertex to source vertex list of adjacent vertices and create a new vertex # with destination vertex as key, which has no adjacent vertex elif source_vertex in self.adj_list: self.adj_list[source_vertex].append(destination_vertex) self.adj_list[destination_vertex] = [] # if only destination vertex is present in adjacency list, create a new # vertex with source vertex as key and assign a list containing destination # vertex as first adjacent vertex elif destination_vertex in self.adj_list: self.adj_list[source_vertex] = [destination_vertex] # if both source vertex and destination vertex are not present in adjacency # list, create a new vertex with source vertex as key and a list containing # destination vertex as it's first adjacent vertex. Then create a new vertex # with destination vertex as key, which has no adjacent vertex else: self.adj_list[source_vertex] = [destination_vertex] self.adj_list[destination_vertex] = [] return self def __repr__(self) -> str: return pformat(self.adj_list)
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Isolate the Decimal part of a Number https://stackoverflow.com/questions/3886402/how-to-get-numbers-after-decimal-point """ def decimal_isolate(number, digitAmount): """ Isolates the decimal part of a number. If digitAmount > 0 round to that decimal place, else print the entire decimal. >>> decimal_isolate(1.53, 0) 0.53 >>> decimal_isolate(35.345, 1) 0.3 >>> decimal_isolate(35.345, 2) 0.34 >>> decimal_isolate(35.345, 3) 0.345 >>> decimal_isolate(-14.789, 3) -0.789 >>> decimal_isolate(0, 2) 0 >>> decimal_isolate(-14.123, 1) -0.1 >>> decimal_isolate(-14.123, 2) -0.12 >>> decimal_isolate(-14.123, 3) -0.123 """ if digitAmount > 0: return round(number - int(number), digitAmount) return number - int(number) if __name__ == "__main__": print(decimal_isolate(1.53, 0)) print(decimal_isolate(35.345, 1)) print(decimal_isolate(35.345, 2)) print(decimal_isolate(35.345, 3)) print(decimal_isolate(-14.789, 3)) print(decimal_isolate(0, 2)) print(decimal_isolate(-14.123, 1)) print(decimal_isolate(-14.123, 2)) print(decimal_isolate(-14.123, 3))
""" Isolate the Decimal part of a Number https://stackoverflow.com/questions/3886402/how-to-get-numbers-after-decimal-point """ def decimal_isolate(number, digitAmount): """ Isolates the decimal part of a number. If digitAmount > 0 round to that decimal place, else print the entire decimal. >>> decimal_isolate(1.53, 0) 0.53 >>> decimal_isolate(35.345, 1) 0.3 >>> decimal_isolate(35.345, 2) 0.34 >>> decimal_isolate(35.345, 3) 0.345 >>> decimal_isolate(-14.789, 3) -0.789 >>> decimal_isolate(0, 2) 0 >>> decimal_isolate(-14.123, 1) -0.1 >>> decimal_isolate(-14.123, 2) -0.12 >>> decimal_isolate(-14.123, 3) -0.123 """ if digitAmount > 0: return round(number - int(number), digitAmount) return number - int(number) if __name__ == "__main__": print(decimal_isolate(1.53, 0)) print(decimal_isolate(35.345, 1)) print(decimal_isolate(35.345, 2)) print(decimal_isolate(35.345, 3)) print(decimal_isolate(-14.789, 3)) print(decimal_isolate(0, 2)) print(decimal_isolate(-14.123, 1)) print(decimal_isolate(-14.123, 2)) print(decimal_isolate(-14.123, 3))
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
# https://github.com/rupansh/QuantumComputing/blob/master/rippleadd.py # https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder # https://en.wikipedia.org/wiki/Controlled_NOT_gate from qiskit import Aer, QuantumCircuit, execute from qiskit.providers import BaseBackend def store_two_classics(val1: int, val2: int) -> tuple[QuantumCircuit, str, str]: """ Generates a Quantum Circuit which stores two classical integers Returns the circuit and binary representation of the integers """ x, y = bin(val1)[2:], bin(val2)[2:] # Remove leading '0b' # Ensure that both strings are of the same length if len(x) > len(y): y = y.zfill(len(x)) else: x = x.zfill(len(y)) # We need (3 * number of bits in the larger number)+1 qBits # The second parameter is the number of classical registers, to measure the result circuit = QuantumCircuit((len(x) * 3) + 1, len(x) + 1) # We are essentially "not-ing" the bits that are 1 # Reversed because its easier to perform ops on more significant bits for i in range(len(x)): if x[::-1][i] == "1": circuit.x(i) for j in range(len(y)): if y[::-1][j] == "1": circuit.x(len(x) + j) return circuit, x, y def full_adder( circuit: QuantumCircuit, input1_loc: int, input2_loc: int, carry_in: int, carry_out: int, ): """ Quantum Equivalent of a Full Adder Circuit CX/CCX is like 2-way/3-way XOR """ circuit.ccx(input1_loc, input2_loc, carry_out) circuit.cx(input1_loc, input2_loc) circuit.ccx(input2_loc, carry_in, carry_out) circuit.cx(input2_loc, carry_in) circuit.cx(input1_loc, input2_loc) # The default value for **backend** is the result of a function call which is not # normally recommended and causes flake8-bugbear to raise a B008 error. However, # in this case, this is accptable because `Aer.get_backend()` is called when the # function is defined and that same backend is then reused for all function calls. def ripple_adder( val1: int, val2: int, backend: BaseBackend = Aer.get_backend("qasm_simulator"), # noqa: B008 ) -> int: """ Quantum Equivalent of a Ripple Adder Circuit Uses qasm_simulator backend by default Currently only adds 'emulated' Classical Bits but nothing prevents us from doing this with hadamard'd bits :) Only supports adding positive integers >>> ripple_adder(3, 4) 7 >>> ripple_adder(10, 4) 14 >>> ripple_adder(-1, 10) Traceback (most recent call last): ... ValueError: Both Integers must be positive! """ if val1 < 0 or val2 < 0: raise ValueError("Both Integers must be positive!") # Store the Integers circuit, x, y = store_two_classics(val1, val2) """ We are essentially using each bit of x & y respectively as full_adder's input the carry_input is used from the previous circuit (for circuit num > 1) the carry_out is just below carry_input because it will be essentially the carry_input for the next full_adder """ for i in range(len(x)): full_adder(circuit, i, len(x) + i, len(x) + len(y) + i, len(x) + len(y) + i + 1) circuit.barrier() # Optional, just for aesthetics # Measure the resultant qBits for i in range(len(x) + 1): circuit.measure([(len(x) * 2) + i], [i]) res = execute(circuit, backend, shots=1).result() # The result is in binary. Convert it back to int return int(list(res.get_counts())[0], 2) if __name__ == "__main__": import doctest doctest.testmod()
# https://github.com/rupansh/QuantumComputing/blob/master/rippleadd.py # https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder # https://en.wikipedia.org/wiki/Controlled_NOT_gate from qiskit import Aer, QuantumCircuit, execute from qiskit.providers import BaseBackend def store_two_classics(val1: int, val2: int) -> tuple[QuantumCircuit, str, str]: """ Generates a Quantum Circuit which stores two classical integers Returns the circuit and binary representation of the integers """ x, y = bin(val1)[2:], bin(val2)[2:] # Remove leading '0b' # Ensure that both strings are of the same length if len(x) > len(y): y = y.zfill(len(x)) else: x = x.zfill(len(y)) # We need (3 * number of bits in the larger number)+1 qBits # The second parameter is the number of classical registers, to measure the result circuit = QuantumCircuit((len(x) * 3) + 1, len(x) + 1) # We are essentially "not-ing" the bits that are 1 # Reversed because its easier to perform ops on more significant bits for i in range(len(x)): if x[::-1][i] == "1": circuit.x(i) for j in range(len(y)): if y[::-1][j] == "1": circuit.x(len(x) + j) return circuit, x, y def full_adder( circuit: QuantumCircuit, input1_loc: int, input2_loc: int, carry_in: int, carry_out: int, ): """ Quantum Equivalent of a Full Adder Circuit CX/CCX is like 2-way/3-way XOR """ circuit.ccx(input1_loc, input2_loc, carry_out) circuit.cx(input1_loc, input2_loc) circuit.ccx(input2_loc, carry_in, carry_out) circuit.cx(input2_loc, carry_in) circuit.cx(input1_loc, input2_loc) # The default value for **backend** is the result of a function call which is not # normally recommended and causes flake8-bugbear to raise a B008 error. However, # in this case, this is accptable because `Aer.get_backend()` is called when the # function is defined and that same backend is then reused for all function calls. def ripple_adder( val1: int, val2: int, backend: BaseBackend = Aer.get_backend("qasm_simulator"), # noqa: B008 ) -> int: """ Quantum Equivalent of a Ripple Adder Circuit Uses qasm_simulator backend by default Currently only adds 'emulated' Classical Bits but nothing prevents us from doing this with hadamard'd bits :) Only supports adding positive integers >>> ripple_adder(3, 4) 7 >>> ripple_adder(10, 4) 14 >>> ripple_adder(-1, 10) Traceback (most recent call last): ... ValueError: Both Integers must be positive! """ if val1 < 0 or val2 < 0: raise ValueError("Both Integers must be positive!") # Store the Integers circuit, x, y = store_two_classics(val1, val2) """ We are essentially using each bit of x & y respectively as full_adder's input the carry_input is used from the previous circuit (for circuit num > 1) the carry_out is just below carry_input because it will be essentially the carry_input for the next full_adder """ for i in range(len(x)): full_adder(circuit, i, len(x) + i, len(x) + len(y) + i, len(x) + len(y) + i + 1) circuit.barrier() # Optional, just for aesthetics # Measure the resultant qBits for i in range(len(x) + 1): circuit.measure([(len(x) * 2) + i], [i]) res = execute(circuit, backend, shots=1).result() # The result is in binary. Convert it back to int return int(list(res.get_counts())[0], 2) if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" 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 algorithms and complexity analysis). Source: https://en.wikipedia.org/wiki/Slowsort """ from __future__ import annotations def slowsort(sequence: list, start: int | None = None, end: int | None = None) -> None: """ Sorts sequence[start..end] (both inclusive) in-place. start defaults to 0 if not given. end defaults to len(sequence) - 1 if not given. It returns None. >>> seq = [1, 6, 2, 5, 3, 4, 4, 5]; slowsort(seq); seq [1, 2, 3, 4, 4, 5, 5, 6] >>> seq = []; slowsort(seq); seq [] >>> seq = [2]; slowsort(seq); seq [2] >>> seq = [1, 2, 3, 4]; slowsort(seq); seq [1, 2, 3, 4] >>> seq = [4, 3, 2, 1]; slowsort(seq); seq [1, 2, 3, 4] >>> seq = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]; slowsort(seq, 2, 7); seq [9, 8, 2, 3, 4, 5, 6, 7, 1, 0] >>> seq = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]; slowsort(seq, end = 4); seq [5, 6, 7, 8, 9, 4, 3, 2, 1, 0] >>> seq = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]; slowsort(seq, start = 5); seq [9, 8, 7, 6, 5, 0, 1, 2, 3, 4] """ if start is None: start = 0 if end is None: end = len(sequence) - 1 if start >= end: return mid = (start + end) // 2 slowsort(sequence, start, mid) slowsort(sequence, mid + 1, end) if sequence[end] < sequence[mid]: sequence[end], sequence[mid] = sequence[mid], sequence[end] slowsort(sequence, start, end - 1) if __name__ == "__main__": from doctest import testmod testmod()
""" 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 algorithms and complexity analysis). Source: https://en.wikipedia.org/wiki/Slowsort """ from __future__ import annotations def slowsort(sequence: list, start: int | None = None, end: int | None = None) -> None: """ Sorts sequence[start..end] (both inclusive) in-place. start defaults to 0 if not given. end defaults to len(sequence) - 1 if not given. It returns None. >>> seq = [1, 6, 2, 5, 3, 4, 4, 5]; slowsort(seq); seq [1, 2, 3, 4, 4, 5, 5, 6] >>> seq = []; slowsort(seq); seq [] >>> seq = [2]; slowsort(seq); seq [2] >>> seq = [1, 2, 3, 4]; slowsort(seq); seq [1, 2, 3, 4] >>> seq = [4, 3, 2, 1]; slowsort(seq); seq [1, 2, 3, 4] >>> seq = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]; slowsort(seq, 2, 7); seq [9, 8, 2, 3, 4, 5, 6, 7, 1, 0] >>> seq = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]; slowsort(seq, end = 4); seq [5, 6, 7, 8, 9, 4, 3, 2, 1, 0] >>> seq = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]; slowsort(seq, start = 5); seq [9, 8, 7, 6, 5, 0, 1, 2, 3, 4] """ if start is None: start = 0 if end is None: end = len(sequence) - 1 if start >= end: return mid = (start + end) // 2 slowsort(sequence, start, mid) slowsort(sequence, mid + 1, end) if sequence[end] < sequence[mid]: sequence[end], sequence[mid] = sequence[mid], sequence[end] slowsort(sequence, start, end - 1) if __name__ == "__main__": from doctest import testmod testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" In this problem, we want to determine all possible permutations of the given sequence. We use backtracking to solve this problem. Time complexity: O(n! * n), where n denotes the length of the given sequence. """ from __future__ import annotations def generate_all_permutations(sequence: list[int | str]) -> None: create_state_space_tree(sequence, [], 0, [0 for i in range(len(sequence))]) def create_state_space_tree( sequence: list[int | str], current_sequence: list[int | str], index: int, index_used: list[int], ) -> None: """ Creates a state space tree to iterate through each branch using DFS. We know that each state has exactly len(sequence) - index children. It terminates when it reaches the end of the given sequence. """ if index == len(sequence): print(current_sequence) return for i in range(len(sequence)): if not index_used[i]: current_sequence.append(sequence[i]) index_used[i] = True create_state_space_tree(sequence, current_sequence, index + 1, index_used) current_sequence.pop() index_used[i] = False """ remove the comment to take an input from the user print("Enter the elements") sequence = list(map(int, input().split())) """ sequence: list[int | str] = [3, 1, 2, 4] generate_all_permutations(sequence) sequence_2: list[int | str] = ["A", "B", "C"] generate_all_permutations(sequence_2)
""" In this problem, we want to determine all possible permutations of the given sequence. We use backtracking to solve this problem. Time complexity: O(n! * n), where n denotes the length of the given sequence. """ from __future__ import annotations def generate_all_permutations(sequence: list[int | str]) -> None: create_state_space_tree(sequence, [], 0, [0 for i in range(len(sequence))]) def create_state_space_tree( sequence: list[int | str], current_sequence: list[int | str], index: int, index_used: list[int], ) -> None: """ Creates a state space tree to iterate through each branch using DFS. We know that each state has exactly len(sequence) - index children. It terminates when it reaches the end of the given sequence. """ if index == len(sequence): print(current_sequence) return for i in range(len(sequence)): if not index_used[i]: current_sequence.append(sequence[i]) index_used[i] = True create_state_space_tree(sequence, current_sequence, index + 1, index_used) current_sequence.pop() index_used[i] = False """ remove the comment to take an input from the user print("Enter the elements") sequence = list(map(int, input().split())) """ sequence: list[int | str] = [3, 1, 2, 4] generate_all_permutations(sequence) sequence_2: list[int | str] = ["A", "B", "C"] generate_all_permutations(sequence_2)
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" An RSA prime factor algorithm. The program can efficiently factor RSA prime number given the private key d and public key e. Source: on page 3 of https://crypto.stanford.edu/~dabo/papers/RSA-survey.pdf More readable source: https://www.di-mgt.com.au/rsa_factorize_n.html large number can take minutes to factor, therefore are not included in doctest. """ from __future__ import annotations import math import random def rsafactor(d: int, e: int, N: int) -> list[int]: """ This function returns the factors of N, where p*q=N Return: [p, q] We call N the RSA modulus, e the encryption exponent, and d the decryption exponent. The pair (N, e) is the public key. As its name suggests, it is public and is used to encrypt messages. The pair (N, d) is the secret key or private key and is known only to the recipient of encrypted messages. >>> rsafactor(3, 16971, 25777) [149, 173] >>> rsafactor(7331, 11, 27233) [113, 241] >>> rsafactor(4021, 13, 17711) [89, 199] """ k = d * e - 1 p = 0 q = 0 while p == 0: g = random.randint(2, N - 1) t = k while True: if t % 2 == 0: t = t // 2 x = (g ** t) % N y = math.gcd(x - 1, N) if x > 1 and y > 1: p = y q = N // y break # find the correct factors else: break # t is not divisible by 2, break and choose another g return sorted([p, q]) if __name__ == "__main__": import doctest doctest.testmod()
""" An RSA prime factor algorithm. The program can efficiently factor RSA prime number given the private key d and public key e. Source: on page 3 of https://crypto.stanford.edu/~dabo/papers/RSA-survey.pdf More readable source: https://www.di-mgt.com.au/rsa_factorize_n.html large number can take minutes to factor, therefore are not included in doctest. """ from __future__ import annotations import math import random def rsafactor(d: int, e: int, N: int) -> list[int]: """ This function returns the factors of N, where p*q=N Return: [p, q] We call N the RSA modulus, e the encryption exponent, and d the decryption exponent. The pair (N, e) is the public key. As its name suggests, it is public and is used to encrypt messages. The pair (N, d) is the secret key or private key and is known only to the recipient of encrypted messages. >>> rsafactor(3, 16971, 25777) [149, 173] >>> rsafactor(7331, 11, 27233) [113, 241] >>> rsafactor(4021, 13, 17711) [89, 199] """ k = d * e - 1 p = 0 q = 0 while p == 0: g = random.randint(2, N - 1) t = k while True: if t % 2 == 0: t = t // 2 x = (g ** t) % N y = math.gcd(x - 1, N) if x > 1 and y > 1: p = y q = N // y break # find the correct factors else: break # t is not divisible by 2, break and choose another g return sorted([p, q]) if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
#
#
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n. As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit. Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. """ def solution(limit=28123): """ Finds the sum of all the positive integers which cannot be written as the sum of two abundant numbers as described by the statement above. >>> solution() 4179871 """ sumDivs = [1] * (limit + 1) for i in range(2, int(limit ** 0.5) + 1): sumDivs[i * i] += i for k in range(i + 1, limit // i + 1): sumDivs[k * i] += k + i abundants = set() res = 0 for n in range(1, limit + 1): if sumDivs[n] > n: abundants.add(n) if not any((n - a in abundants) for a in abundants): res += n return res if __name__ == "__main__": print(solution())
""" A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n. As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit. Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. """ def solution(limit=28123): """ Finds the sum of all the positive integers which cannot be written as the sum of two abundant numbers as described by the statement above. >>> solution() 4179871 """ sumDivs = [1] * (limit + 1) for i in range(2, int(limit ** 0.5) + 1): sumDivs[i * i] += i for k in range(i + 1, limit // i + 1): sumDivs[k * i] += k + i abundants = set() res = 0 for n in range(1, limit + 1): if sumDivs[n] > n: abundants.add(n) if not any((n - a in abundants) for a in abundants): res += n return res if __name__ == "__main__": print(solution())
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
#!/usr/bin/env python # # Sort large text files in a minimum amount of memory # import argparse import os class FileSplitter: BLOCK_FILENAME_FORMAT = "block_{0}.dat" def __init__(self, filename): self.filename = filename self.block_filenames = [] def write_block(self, data, block_number): filename = self.BLOCK_FILENAME_FORMAT.format(block_number) with open(filename, "w") as file: file.write(data) self.block_filenames.append(filename) def get_block_filenames(self): return self.block_filenames def split(self, block_size, sort_key=None): i = 0 with open(self.filename) as file: while True: lines = file.readlines(block_size) if lines == []: break if sort_key is None: lines.sort() else: lines.sort(key=sort_key) self.write_block("".join(lines), i) i += 1 def cleanup(self): map(lambda f: os.remove(f), self.block_filenames) class NWayMerge: def select(self, choices): min_index = -1 min_str = None for i in range(len(choices)): if min_str is None or choices[i] < min_str: min_index = i return min_index class FilesArray: def __init__(self, files): self.files = files self.empty = set() self.num_buffers = len(files) self.buffers = {i: None for i in range(self.num_buffers)} def get_dict(self): return { i: self.buffers[i] for i in range(self.num_buffers) if i not in self.empty } def refresh(self): for i in range(self.num_buffers): if self.buffers[i] is None and i not in self.empty: self.buffers[i] = self.files[i].readline() if self.buffers[i] == "": self.empty.add(i) self.files[i].close() if len(self.empty) == self.num_buffers: return False return True def unshift(self, index): value = self.buffers[index] self.buffers[index] = None return value class FileMerger: def __init__(self, merge_strategy): self.merge_strategy = merge_strategy def merge(self, filenames, outfilename, buffer_size): buffers = FilesArray(self.get_file_handles(filenames, buffer_size)) with open(outfilename, "w", buffer_size) as outfile: while buffers.refresh(): min_index = self.merge_strategy.select(buffers.get_dict()) outfile.write(buffers.unshift(min_index)) def get_file_handles(self, filenames, buffer_size): files = {} for i in range(len(filenames)): files[i] = open(filenames[i], "r", buffer_size) return files class ExternalSort: def __init__(self, block_size): self.block_size = block_size def sort(self, filename, sort_key=None): num_blocks = self.get_number_blocks(filename, self.block_size) splitter = FileSplitter(filename) splitter.split(self.block_size, sort_key) merger = FileMerger(NWayMerge()) buffer_size = self.block_size / (num_blocks + 1) merger.merge(splitter.get_block_filenames(), filename + ".out", buffer_size) splitter.cleanup() def get_number_blocks(self, filename, block_size): return (os.stat(filename).st_size / block_size) + 1 def parse_memory(string): if string[-1].lower() == "k": return int(string[:-1]) * 1024 elif string[-1].lower() == "m": return int(string[:-1]) * 1024 * 1024 elif string[-1].lower() == "g": return int(string[:-1]) * 1024 * 1024 * 1024 else: return int(string) def main(): parser = argparse.ArgumentParser() parser.add_argument( "-m", "--mem", help="amount of memory to use for sorting", default="100M" ) parser.add_argument( "filename", metavar="<filename>", nargs=1, help="name of file to sort" ) args = parser.parse_args() sorter = ExternalSort(parse_memory(args.mem)) sorter.sort(args.filename[0]) if __name__ == "__main__": main()
#!/usr/bin/env python # # Sort large text files in a minimum amount of memory # import argparse import os class FileSplitter: BLOCK_FILENAME_FORMAT = "block_{0}.dat" def __init__(self, filename): self.filename = filename self.block_filenames = [] def write_block(self, data, block_number): filename = self.BLOCK_FILENAME_FORMAT.format(block_number) with open(filename, "w") as file: file.write(data) self.block_filenames.append(filename) def get_block_filenames(self): return self.block_filenames def split(self, block_size, sort_key=None): i = 0 with open(self.filename) as file: while True: lines = file.readlines(block_size) if lines == []: break if sort_key is None: lines.sort() else: lines.sort(key=sort_key) self.write_block("".join(lines), i) i += 1 def cleanup(self): map(lambda f: os.remove(f), self.block_filenames) class NWayMerge: def select(self, choices): min_index = -1 min_str = None for i in range(len(choices)): if min_str is None or choices[i] < min_str: min_index = i return min_index class FilesArray: def __init__(self, files): self.files = files self.empty = set() self.num_buffers = len(files) self.buffers = {i: None for i in range(self.num_buffers)} def get_dict(self): return { i: self.buffers[i] for i in range(self.num_buffers) if i not in self.empty } def refresh(self): for i in range(self.num_buffers): if self.buffers[i] is None and i not in self.empty: self.buffers[i] = self.files[i].readline() if self.buffers[i] == "": self.empty.add(i) self.files[i].close() if len(self.empty) == self.num_buffers: return False return True def unshift(self, index): value = self.buffers[index] self.buffers[index] = None return value class FileMerger: def __init__(self, merge_strategy): self.merge_strategy = merge_strategy def merge(self, filenames, outfilename, buffer_size): buffers = FilesArray(self.get_file_handles(filenames, buffer_size)) with open(outfilename, "w", buffer_size) as outfile: while buffers.refresh(): min_index = self.merge_strategy.select(buffers.get_dict()) outfile.write(buffers.unshift(min_index)) def get_file_handles(self, filenames, buffer_size): files = {} for i in range(len(filenames)): files[i] = open(filenames[i], "r", buffer_size) return files class ExternalSort: def __init__(self, block_size): self.block_size = block_size def sort(self, filename, sort_key=None): num_blocks = self.get_number_blocks(filename, self.block_size) splitter = FileSplitter(filename) splitter.split(self.block_size, sort_key) merger = FileMerger(NWayMerge()) buffer_size = self.block_size / (num_blocks + 1) merger.merge(splitter.get_block_filenames(), filename + ".out", buffer_size) splitter.cleanup() def get_number_blocks(self, filename, block_size): return (os.stat(filename).st_size / block_size) + 1 def parse_memory(string): if string[-1].lower() == "k": return int(string[:-1]) * 1024 elif string[-1].lower() == "m": return int(string[:-1]) * 1024 * 1024 elif string[-1].lower() == "g": return int(string[:-1]) * 1024 * 1024 * 1024 else: return int(string) def main(): parser = argparse.ArgumentParser() parser.add_argument( "-m", "--mem", help="amount of memory to use for sorting", default="100M" ) parser.add_argument( "filename", metavar="<filename>", nargs=1, help="name of file to sort" ) args = parser.parse_args() sorter = ExternalSort(parse_memory(args.mem)) sorter.sort(args.filename[0]) if __name__ == "__main__": main()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Graph Coloring also called "m coloring problem" consists of coloring a given graph with at most m colors such that no adjacent vertices are assigned the same color Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring """ def valid_coloring( neighbours: list[int], colored_vertices: list[int], color: int ) -> bool: """ For each neighbour check if the coloring constraint is satisfied If any of the neighbours fail the constraint return False If all neighbours validate the constraint return True >>> neighbours = [0,1,0,1,0] >>> colored_vertices = [0, 2, 1, 2, 0] >>> color = 1 >>> valid_coloring(neighbours, colored_vertices, color) True >>> color = 2 >>> valid_coloring(neighbours, colored_vertices, color) False """ # Does any neighbour not satisfy the constraints return not any( neighbour == 1 and colored_vertices[i] == color for i, neighbour in enumerate(neighbours) ) def util_color( graph: list[list[int]], max_colors: int, colored_vertices: list[int], index: int ) -> bool: """ Pseudo-Code Base Case: 1. Check if coloring is complete 1.1 If complete return True (meaning that we successfully colored the graph) Recursive Step: 2. Iterates over each color: Check if the current coloring is valid: 2.1. Color given vertex 2.2. Do recursive call, check if this coloring leads to a solution 2.4. if current coloring leads to a solution return 2.5. Uncolor given vertex >>> graph = [[0, 1, 0, 0, 0], ... [1, 0, 1, 0, 1], ... [0, 1, 0, 1, 0], ... [0, 1, 1, 0, 0], ... [0, 1, 0, 0, 0]] >>> max_colors = 3 >>> colored_vertices = [0, 1, 0, 0, 0] >>> index = 3 >>> util_color(graph, max_colors, colored_vertices, index) True >>> max_colors = 2 >>> util_color(graph, max_colors, colored_vertices, index) False """ # Base Case if index == len(graph): return True # Recursive Step for i in range(max_colors): if valid_coloring(graph[index], colored_vertices, i): # Color current vertex colored_vertices[index] = i # Validate coloring if util_color(graph, max_colors, colored_vertices, index + 1): return True # Backtrack colored_vertices[index] = -1 return False def color(graph: list[list[int]], max_colors: int) -> list[int]: """ Wrapper function to call subroutine called util_color which will either return True or False. If True is returned colored_vertices list is filled with correct colorings >>> graph = [[0, 1, 0, 0, 0], ... [1, 0, 1, 0, 1], ... [0, 1, 0, 1, 0], ... [0, 1, 1, 0, 0], ... [0, 1, 0, 0, 0]] >>> max_colors = 3 >>> color(graph, max_colors) [0, 1, 0, 2, 0] >>> max_colors = 2 >>> color(graph, max_colors) [] """ colored_vertices = [-1] * len(graph) if util_color(graph, max_colors, colored_vertices, 0): return colored_vertices return []
""" Graph Coloring also called "m coloring problem" consists of coloring a given graph with at most m colors such that no adjacent vertices are assigned the same color Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring """ def valid_coloring( neighbours: list[int], colored_vertices: list[int], color: int ) -> bool: """ For each neighbour check if the coloring constraint is satisfied If any of the neighbours fail the constraint return False If all neighbours validate the constraint return True >>> neighbours = [0,1,0,1,0] >>> colored_vertices = [0, 2, 1, 2, 0] >>> color = 1 >>> valid_coloring(neighbours, colored_vertices, color) True >>> color = 2 >>> valid_coloring(neighbours, colored_vertices, color) False """ # Does any neighbour not satisfy the constraints return not any( neighbour == 1 and colored_vertices[i] == color for i, neighbour in enumerate(neighbours) ) def util_color( graph: list[list[int]], max_colors: int, colored_vertices: list[int], index: int ) -> bool: """ Pseudo-Code Base Case: 1. Check if coloring is complete 1.1 If complete return True (meaning that we successfully colored the graph) Recursive Step: 2. Iterates over each color: Check if the current coloring is valid: 2.1. Color given vertex 2.2. Do recursive call, check if this coloring leads to a solution 2.4. if current coloring leads to a solution return 2.5. Uncolor given vertex >>> graph = [[0, 1, 0, 0, 0], ... [1, 0, 1, 0, 1], ... [0, 1, 0, 1, 0], ... [0, 1, 1, 0, 0], ... [0, 1, 0, 0, 0]] >>> max_colors = 3 >>> colored_vertices = [0, 1, 0, 0, 0] >>> index = 3 >>> util_color(graph, max_colors, colored_vertices, index) True >>> max_colors = 2 >>> util_color(graph, max_colors, colored_vertices, index) False """ # Base Case if index == len(graph): return True # Recursive Step for i in range(max_colors): if valid_coloring(graph[index], colored_vertices, i): # Color current vertex colored_vertices[index] = i # Validate coloring if util_color(graph, max_colors, colored_vertices, index + 1): return True # Backtrack colored_vertices[index] = -1 return False def color(graph: list[list[int]], max_colors: int) -> list[int]: """ Wrapper function to call subroutine called util_color which will either return True or False. If True is returned colored_vertices list is filled with correct colorings >>> graph = [[0, 1, 0, 0, 0], ... [1, 0, 1, 0, 1], ... [0, 1, 0, 1, 0], ... [0, 1, 1, 0, 0], ... [0, 1, 0, 0, 0]] >>> max_colors = 3 >>> color(graph, max_colors) [0, 1, 0, 2, 0] >>> max_colors = 2 >>> color(graph, max_colors) [] """ colored_vertices = [-1] * len(graph) if util_color(graph, max_colors, colored_vertices, 0): return colored_vertices return []
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" https://en.wikipedia.org/wiki/Doubly_linked_list """ class Node: def __init__(self, data): self.data = data self.previous = None self.next = None def __str__(self): return f"{self.data}" class DoublyLinkedList: def __init__(self): self.head = None self.tail = None def __iter__(self): """ >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_head('b') >>> linked_list.insert_at_head('a') >>> linked_list.insert_at_tail('c') >>> tuple(linked_list) ('a', 'b', 'c') """ node = self.head while node: yield node.data node = node.next def __str__(self): """ >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_tail('a') >>> linked_list.insert_at_tail('b') >>> linked_list.insert_at_tail('c') >>> str(linked_list) 'a->b->c' """ return "->".join([str(item) for item in self]) def __len__(self): """ >>> linked_list = DoublyLinkedList() >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) >>> len(linked_list) == 5 True """ return len(tuple(iter(self))) def insert_at_head(self, data): self.insert_at_nth(0, data) def insert_at_tail(self, data): self.insert_at_nth(len(self), data) def insert_at_nth(self, index: int, data): """ >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_nth(-1, 666) Traceback (most recent call last): .... IndexError: list index out of range >>> linked_list.insert_at_nth(1, 666) Traceback (most recent call last): .... IndexError: list index out of range >>> linked_list.insert_at_nth(0, 2) >>> linked_list.insert_at_nth(0, 1) >>> linked_list.insert_at_nth(2, 4) >>> linked_list.insert_at_nth(2, 3) >>> str(linked_list) '1->2->3->4' >>> linked_list.insert_at_nth(5, 5) Traceback (most recent call last): .... IndexError: list index out of range """ if not 0 <= index <= len(self): raise IndexError("list index out of range") new_node = Node(data) if self.head is None: self.head = self.tail = new_node elif index == 0: self.head.previous = new_node new_node.next = self.head self.head = new_node elif index == len(self): self.tail.next = new_node new_node.previous = self.tail self.tail = new_node else: temp = self.head for i in range(0, index): temp = temp.next temp.previous.next = new_node new_node.previous = temp.previous new_node.next = temp temp.previous = new_node def delete_head(self): return self.delete_at_nth(0) def delete_tail(self): return self.delete_at_nth(len(self) - 1) def delete_at_nth(self, index: int): """ >>> linked_list = DoublyLinkedList() >>> linked_list.delete_at_nth(0) Traceback (most recent call last): .... IndexError: list index out of range >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) >>> linked_list.delete_at_nth(0) == 1 True >>> linked_list.delete_at_nth(3) == 5 True >>> linked_list.delete_at_nth(1) == 3 True >>> str(linked_list) '2->4' >>> linked_list.delete_at_nth(2) Traceback (most recent call last): .... IndexError: list index out of range """ if not 0 <= index <= len(self) - 1: raise IndexError("list index out of range") delete_node = self.head # default first node if len(self) == 1: self.head = self.tail = None elif index == 0: self.head = self.head.next self.head.previous = None elif index == len(self) - 1: delete_node = self.tail self.tail = self.tail.previous self.tail.next = None else: temp = self.head for i in range(0, index): temp = temp.next delete_node = temp temp.next.previous = temp.previous temp.previous.next = temp.next return delete_node.data def delete(self, data) -> str: current = self.head while current.data != data: # Find the position to delete if current.next: current = current.next else: # We have reached the end an no value matches return "No data matching given value" if current == self.head: self.delete_head() elif current == self.tail: self.delete_tail() else: # Before: 1 <--> 2(current) <--> 3 current.previous.next = current.next # 1 --> 3 current.next.previous = current.previous # 1 <--> 3 return data def is_empty(self): """ >>> linked_list = DoublyLinkedList() >>> linked_list.is_empty() True >>> linked_list.insert_at_tail(1) >>> linked_list.is_empty() False """ return len(self) == 0 def test_doubly_linked_list() -> None: """ >>> test_doubly_linked_list() """ linked_list = DoublyLinkedList() assert linked_list.is_empty() is True assert str(linked_list) == "" try: linked_list.delete_head() assert False # This should not happen. except IndexError: assert True # This should happen. try: linked_list.delete_tail() assert False # This should not happen. except IndexError: assert True # This should happen. for i in range(10): assert len(linked_list) == i linked_list.insert_at_nth(i, i + 1) assert str(linked_list) == "->".join(str(i) for i in range(1, 11)) linked_list.insert_at_head(0) linked_list.insert_at_tail(11) assert str(linked_list) == "->".join(str(i) for i in range(0, 12)) assert linked_list.delete_head() == 0 assert linked_list.delete_at_nth(9) == 10 assert linked_list.delete_tail() == 11 assert len(linked_list) == 9 assert str(linked_list) == "->".join(str(i) for i in range(1, 10)) if __name__ == "__main__": from doctest import testmod testmod()
""" https://en.wikipedia.org/wiki/Doubly_linked_list """ class Node: def __init__(self, data): self.data = data self.previous = None self.next = None def __str__(self): return f"{self.data}" class DoublyLinkedList: def __init__(self): self.head = None self.tail = None def __iter__(self): """ >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_head('b') >>> linked_list.insert_at_head('a') >>> linked_list.insert_at_tail('c') >>> tuple(linked_list) ('a', 'b', 'c') """ node = self.head while node: yield node.data node = node.next def __str__(self): """ >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_tail('a') >>> linked_list.insert_at_tail('b') >>> linked_list.insert_at_tail('c') >>> str(linked_list) 'a->b->c' """ return "->".join([str(item) for item in self]) def __len__(self): """ >>> linked_list = DoublyLinkedList() >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) >>> len(linked_list) == 5 True """ return len(tuple(iter(self))) def insert_at_head(self, data): self.insert_at_nth(0, data) def insert_at_tail(self, data): self.insert_at_nth(len(self), data) def insert_at_nth(self, index: int, data): """ >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_nth(-1, 666) Traceback (most recent call last): .... IndexError: list index out of range >>> linked_list.insert_at_nth(1, 666) Traceback (most recent call last): .... IndexError: list index out of range >>> linked_list.insert_at_nth(0, 2) >>> linked_list.insert_at_nth(0, 1) >>> linked_list.insert_at_nth(2, 4) >>> linked_list.insert_at_nth(2, 3) >>> str(linked_list) '1->2->3->4' >>> linked_list.insert_at_nth(5, 5) Traceback (most recent call last): .... IndexError: list index out of range """ if not 0 <= index <= len(self): raise IndexError("list index out of range") new_node = Node(data) if self.head is None: self.head = self.tail = new_node elif index == 0: self.head.previous = new_node new_node.next = self.head self.head = new_node elif index == len(self): self.tail.next = new_node new_node.previous = self.tail self.tail = new_node else: temp = self.head for i in range(0, index): temp = temp.next temp.previous.next = new_node new_node.previous = temp.previous new_node.next = temp temp.previous = new_node def delete_head(self): return self.delete_at_nth(0) def delete_tail(self): return self.delete_at_nth(len(self) - 1) def delete_at_nth(self, index: int): """ >>> linked_list = DoublyLinkedList() >>> linked_list.delete_at_nth(0) Traceback (most recent call last): .... IndexError: list index out of range >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) >>> linked_list.delete_at_nth(0) == 1 True >>> linked_list.delete_at_nth(3) == 5 True >>> linked_list.delete_at_nth(1) == 3 True >>> str(linked_list) '2->4' >>> linked_list.delete_at_nth(2) Traceback (most recent call last): .... IndexError: list index out of range """ if not 0 <= index <= len(self) - 1: raise IndexError("list index out of range") delete_node = self.head # default first node if len(self) == 1: self.head = self.tail = None elif index == 0: self.head = self.head.next self.head.previous = None elif index == len(self) - 1: delete_node = self.tail self.tail = self.tail.previous self.tail.next = None else: temp = self.head for i in range(0, index): temp = temp.next delete_node = temp temp.next.previous = temp.previous temp.previous.next = temp.next return delete_node.data def delete(self, data) -> str: current = self.head while current.data != data: # Find the position to delete if current.next: current = current.next else: # We have reached the end an no value matches return "No data matching given value" if current == self.head: self.delete_head() elif current == self.tail: self.delete_tail() else: # Before: 1 <--> 2(current) <--> 3 current.previous.next = current.next # 1 --> 3 current.next.previous = current.previous # 1 <--> 3 return data def is_empty(self): """ >>> linked_list = DoublyLinkedList() >>> linked_list.is_empty() True >>> linked_list.insert_at_tail(1) >>> linked_list.is_empty() False """ return len(self) == 0 def test_doubly_linked_list() -> None: """ >>> test_doubly_linked_list() """ linked_list = DoublyLinkedList() assert linked_list.is_empty() is True assert str(linked_list) == "" try: linked_list.delete_head() assert False # This should not happen. except IndexError: assert True # This should happen. try: linked_list.delete_tail() assert False # This should not happen. except IndexError: assert True # This should happen. for i in range(10): assert len(linked_list) == i linked_list.insert_at_nth(i, i + 1) assert str(linked_list) == "->".join(str(i) for i in range(1, 11)) linked_list.insert_at_head(0) linked_list.insert_at_tail(11) assert str(linked_list) == "->".join(str(i) for i in range(0, 12)) assert linked_list.delete_head() == 0 assert linked_list.delete_at_nth(9) == 10 assert linked_list.delete_tail() == 11 assert len(linked_list) == 9 assert str(linked_list) == "->".join(str(i) for i in range(1, 10)) if __name__ == "__main__": from doctest import testmod testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" This is a pure Python implementation of the bogosort algorithm, also known as permutation sort, stupid sort, slowsort, shotgun sort, or monkey sort. Bogosort generates random permutations until it guesses the correct one. More info on: https://en.wikipedia.org/wiki/Bogosort For doctests run following command: python -m doctest -v bogo_sort.py or python3 -m doctest -v bogo_sort.py For manual testing run: python bogo_sort.py """ import random def bogo_sort(collection): """Pure implementation of the bogosort algorithm in Python :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> bogo_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> bogo_sort([]) [] >>> bogo_sort([-2, -5, -45]) [-45, -5, -2] """ def is_sorted(collection): if len(collection) < 2: return True for i in range(len(collection) - 1): if collection[i] > collection[i + 1]: return False return True while not is_sorted(collection): random.shuffle(collection) return collection if __name__ == "__main__": user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] print(bogo_sort(unsorted))
""" This is a pure Python implementation of the bogosort algorithm, also known as permutation sort, stupid sort, slowsort, shotgun sort, or monkey sort. Bogosort generates random permutations until it guesses the correct one. More info on: https://en.wikipedia.org/wiki/Bogosort For doctests run following command: python -m doctest -v bogo_sort.py or python3 -m doctest -v bogo_sort.py For manual testing run: python bogo_sort.py """ import random def bogo_sort(collection): """Pure implementation of the bogosort algorithm in Python :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> bogo_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> bogo_sort([]) [] >>> bogo_sort([-2, -5, -45]) [-45, -5, -2] """ def is_sorted(collection): if len(collection) < 2: return True for i in range(len(collection) - 1): if collection[i] > collection[i + 1]: return False return True while not is_sorted(collection): random.shuffle(collection) return collection if __name__ == "__main__": user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] print(bogo_sort(unsorted))
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
JFIF``ExifMM*;HasiJ >5454 2019:07:22 20:20:362019:07:22 20:20:36Has http://ns.adobe.com/xap/1.0/<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?> <x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/"/><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:xmp="http://ns.adobe.com/xap/1.0/"><xmp:CreateDate>2019-07-22T20:20:36.543</xmp:CreateDate></rdf:Description><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:creator><rdf:Seq xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li>Has</rdf:li></rdf:Seq> </dc:creator></rdf:Description></rdf:RDF></x:xmpmeta> <?xpacket end='w'?>C   '!%"."%()+,+ /3/*2'*+*C  ***************************************************" }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ?F(((((((((((((((((((((((((((((((((((((((((((((((*GhwڜK4vV\<p])bw'P+$|9 m$4hkHDχ&d^&d2FA|z+_I1>%v@!Rd60J((((((h^#-y5kH٫| %Ǩ Mv+Nm-:W}ιL1$f3EQEQEQEQ\<n>%\%-of/b;xvsEPEPEPEPEw oX{a2CU-p8d2 "EPEPEPE 徟c=m,p2I> :45=;+LSrA#QE#f=fx?i \{oU>I]~)h(ޥ=n$#X11Zhngiqե "3u=Y((( VfM{F B9Z1 Q@xǚo4+^xo1j;A;q(5h6\mM 99?ǥe~<t/{h1%Sm븖t tQET7}$!¢($* YAqY\b#lA]((((((((($cĿ-/#>1O?F<K^23?A7oi6!,wKֺm?5^2Ӵx>GUm3̲,H[m9 `8k+ǜ>2QB \xn@om{[KT˲ӭ2~C$'k UgK j<X\7wm\7 c~+GsgGZ}m iG*C.ebO =7J|QQ}"Xc-.FЬ${P5:ڶU˂2Ngj2IWK^!Ht?]isjaFAoI) k:uZl5oܖU.@R#5?0_%-m_ďKGm ==kdmbb)DM.pskΤodzNӨ귑[~D rY8>3~&o4fd6r7DW=#>CC¿}Y-M‡w0v"FdSMȗj e8]_$SNhw@*tB-m&I0rqҼxs+QԠԼSYv 9>bI=64Ue 0AK4 2`<rsPQ ǯh־ZKX0pDBc}y;9?R*pۊ</'{OC[U\]x5"]JT9k(n<Ospmߦ{qZMu׌].l%_i)@ls$+ξiƫwм.sis җMb~.7F9=#z0ĉ9Uˍ<79T8RI})>Ν ~\z$4PVRV-w%$ l='k^~?容ӟΞz/764}3R)8BpӽjK[xWtK#m껾u6I@kj϶.|t& !ҹs2 ށwh21@ ڹ:e3~1fwq|[qmn]+,%YFDs^ELjU'jmRF֮#rFyNN w>̚狇S k2h.z0NS8<Ә/퇫n nT U[Ů֕:MZByG- ;c@}h;_kEYTfC 8>+M'|E^xg^yYݶ;| pN<P7_`kXǖ<@Fԡ볛|C⿈MYJV[8 yr,1][5_Gӥx50Lq*60 `#C5/JK8l09ўw<]|Cм;]qpʤï3wy><]<V1{ě#& =js][J^LV!%؍LIjm\(<c@tU` z䏏M;<~"xYu.9 !\n@*H0A9W~`%ߎAMz@:[+gyyjPGt2c ~aj;q8*Z={~`h#bvȁ;Xv"x:T6RԴd$22~^r>2x/: 11Ն{p{ٺwixX ]FX"3#ֽ*ź&{ ܭ \8k⒫|=⼟DZO'I$O?Ql>PfhkSĒav{ۏ}خ7ͷtK95*I)oo2l.8cm5O ǫZٍ@ncq+ 6* %֯E!e/}[/žŒQn ǙOsɣ<ҵ17>6L;3OH־sz5|&נoxcP]D,QnYi_Z1#}\աROߒ>*d7bj<yq㶚[Ef 1ڪj_tX|0s9  +ZH>Z:zl! =OuQ[R(ӵ mWL,%Z³C #TWukcjQ[K{ ձcbsb|#$N_*O%)5z߈:?goh& -.)@ٛ(%sY/"ѡ׬WR.&qĨ8BLn/}z}+~s+G"GtC֬EYTmK,LFb;ЏQW'y??ʼ!'wrsL?<3Ǽ@0/L%]K=,v (bAx[|1enޗaKY1yk>Ꭳ%퍵ăXCK ɇkcicg ek ǥVO>M^m>K+cK .CXנ=9'zk;6aR3^`IP3\{c񷺵Y>V}H7|K׆5xz/ ZQ\I`r*8^(I|dOpe 6= }=[W+p%E=WĹ #7ZXwo8S4ψ7PKM|?hhc,c#q@O~/xbNX{䐰`e?<G}ºK\-؈B0+ưi\â#ÌDwn`ӕvr:X\#Ʒǫ5/ Yռ?nTVW2Ӑ>^oi0ݦJd\B A#Mkz]-;2K;{xrGڿXgr˻NOPs޻<+Eד\u I(HQ7G88;20y uXj&au3Om]¡,0'rtS o|-|K$QiwܼUW%ǧ$`8C۪ji7_5]Q"SGTm@U|K?_鑾 5Ȃ#ϵݖ=p2xO<) Д⿴my+5%.{{|>ǩOzq8?ir<8Ok9+۪i65ե.ke8ٴwq JOtn+S[jwQ[a(+"3kSǞ- ֍x^^`G_|pq+>!Z߳ﭤ09D1W>RzO}jnbK6>|m;h:·O^z.I\fIX6qcwNqݛ"Q_8?WƍKeڕݬ $['>VP #R 99O k#:h3Y]@N@^a) V$TOOZd9Y9m°;[@+ny-jȱd9Ƹm77ɦBKP6f?6=IlYI w^JLn/}u/"ѡ׬WR.&qĨ8O_xZR*&-J @ \Eoٮe`Hnw^_j=M"Y~VA\0U||,9xe.4 2EѓpA` xxx)/?[0-,>gǮ0N=yyOUѧe025L ${֓MV}k+]]i{$ u+댎1w>iOqmZŜOHzr:gֽ΀<ƿ|9Ax{Zu5n&K\p,8=W>|M:NH#DyR@ 3C~7BxV)kBpd|@>^Yv~5 H<ۑ $n8q( ( ( ( (3|Cx6wrkx=RBχm-]m,69Z4P?+Hռe&:̲a@`AƏx+HiZIBʓftϨ_?hL%]ۆއ%^6޸~èeuw=!w%6 M =xFJ죽E&x=#G洨.gh嶩m̳d:p'Ƴ׊ }k{pnx-p@w4P & I@n*pq;WE/ i :.,΢WcSZGWP"LQk7\zj/:65_h̚ H]G=P?eza0-dPa{ݭVm_[Դn5˟$ fGaj(:OXUf4SJOz/xO6?fYiyR3Ğ< MttP <p|Y?yfgӊi6qj\aeXy<(!~|.Xnx_ӌ7] \vG6>ŌByktPEP?ְu]f;EF`W<~K*{ {eEs4wEl<>LIbPv>#ڱ|#G^ #t)翇>Ls1dc03z |l{̗v1^NIdR22IqJ@?ohz[j=kmw*׮3&(+A [h:bȶ6јi$U'>Y7y+z/#rh2tn|7esAJ(<w%ٯi<m`a9ȏlWU|=|&ܡ g1gk35еses G}QҴ ᥶Y\~<x=k^~>n[q[ǫ4*DӴX,dPĸU5nű𖑧xS%KT8$ 3Qu="V(ݪX[o+0﷭mQ@^0vJUI.qVuXoCcq GlEgZ-4=MQۘ(ޥt}gFCky- pJ:lպ(ᯇnh?T '|%~ղ-Y?y^_ZPW<9Gv-a0ŎO~X֣(e*zKEs 6 m/é2[Mp,&yUT~$/4}L;Z^Fb#mb (~(Z[k^W.7t̅$~9^+{v:u%\Ln!^\ЙUO8:sxwG5ص6P}Amw|9-+{9I'ishommu۸pF}G5OI1Z5m:xgIᙥf-!<jh}S&Ko>M=kcxj_ &IH؞)o`Wq h WI+(f8I$ʶ( ᇆ4_R If/igyb`=+<F]ZԣkWoɒ(9.yr+(0<cǚ2i${xGV#p 1s\v<DΠh㾟̍HdWQ@ Hm# 9W8涽D0lGsqdg^Erí[ 0h jw(ZkźOci,QG~Q@~xo[K\n@y#=Ϩ8Wz^XfH@>ʣ+*jm^w8%Jckᯇnh?T '|%~@o <"e=M]7xϮOM>x| }D'rŕՎQtPO8u&+ֻ>ýJxb9_Z]Pz_)xr }뾢9O|4#?˞a[+MǠWWEo<]kwSO-n.d$}O#?h>+]Kv'b,=k ( ( ( ( (zWבi m~и2I3+>|PXm~/uT̚F̰;G SY?~-j~;4q嚬a?ۂ=’@Ex .ƚτL,tKGB)uVW 0ՙ|Y^f=[Iִ#BXE=I##@O Kk(u4(͵9\0hgM ߄1g X+!yQ8C:w>< a/ßfF=,<#i=6_-z}@$ dt3Z G^J#iH- <*2NIIapȡ xi.5n3 7@XMކ{Jfg`]m`HC sP?<񧎯ii~a<CĐk7>V(4+4;r0{g|&hԴt,7k̪ddd`0$A*ppzRttiLWgK3a 6Ìj>p2zUf<?mhr3W~:t߇k{M.WXo]]Ļ㓜s'ImkKӛE[EgG$^6u7|9׵x⺸UuFTd*0 'SyRMĹww'|^<!i I4yo <_ "j0m_joh5ǖ+:&:u~YNw{|t5 v>H.iCcdh$ i~9GĖ:]KT(dc7~|Qީ Ťk*Of*=^^ow[MrxݞO [>ڭ~I+4[zS!FIWU`s }|9յ6nn#Sn PY79!wd;PSExZ:/__:HT*y i'ᵕƴoo lЀF@S~x*+ĵ|K]ui{4sP892 jh h<r(tu9 "HeH#$p}+{;ޭ{ImeKۣ^y>=LJ|?ͯixbC+Zw\$9Ҁ;;<a?XjpFVd"':cz |_-,t\+按eډ$ᇍ|Ms_xR[j:Mmtt#u S7W Gҭmb{Cf(N8?tGOO{ .^Vo܈ C,Jyza gþf״<1!-r.S_^@ωd|5`ѯoǹ-Qϧ͟])`Xd7-g^<ΑZZAzt'+k+J_MZKuG<FVEc )HB78 dހ>|%mOomo`hca1ڶ7>)Gƣo]$nP=+Y<a:u˃io C 탂pɜ`ezψ)02մ:E}omnl!W8y9~!&mfG H=WZ@PFGQxfV:}j(]S;^`LyG³[Sk?ƬRD]UA.c(Z+ļ[n< }sNv$w,zWrXs'zgAhtRjqNȳXm|v9$t:PCE:|:-Jc¯,!8,Yz-{5rxSQ=2y+ʭm'8 v=\&ύO5gw mcq<p-\|V?ZkTݯ.m"c~Sӷvx>3y7zP&QT4Xx|F)K#]5y-f/gF4:)(evX %'N|ah:ckRB6 $U 1!yfZ+>>4㦷tY mT:::ҸĩMK~"4Dzd]1T9Ҁ>''PTA?1Sm43ZiNEdo9qF#rwdVr <miwsZ(xۑր;( ԼO7|Go:]ʫ}#iD9nTW['46cdw+| Axx'}>_nN>P~@yW3x6<<4k`ǘ5sx=oOO)z0WORMd bY3x7nJa#j+ƼE_Im=eCylH$ ͎zd ;Co|'oNw =jZXZ6Pi c)Q@X 8=ik]|FMŤZd3edV24#s@O|;o&{OjmUaGCn=AfE^<E\"RE#h@Rgn@x/㽿[ $K;z0<*#s^8 Fr W_}cy/5-cOow )1.ݵr\Ojxv4_ϚᵿUPEy׌↭v shU*Ϩ$y9*a1ۿ^S7I!Ŵ"wlVul@v Q^N|ah:ckRB6 $U 1!yfx^4 㧶մtY mT:::Ҁ=Nj||KCi.ā>O|F񶯤|5t}_"TJIU`F2: _Y~ԗ0xPԵ%NnmەPtQEQEQEQEQE|Zկqi?(WOϮOtlZeeOHwa]䷆YXcy!%vPLd ;'11́ȡe PY]etEVۼ qHGp3x[ j_ }J/]x7y-Ēu(DȔ9 q޾e X`:RYb ɱϩ\`zΟ jz5]Mxӌ75iR rۺ@AZ%"<t1Ok&IW+F '5aźg</uk2F3;rOWR SY>^O '|@,cٞ;z}3ݍ}!Oi3ކ=TV*xS7OT mkogs@?@׌~#>.:z,Wm̱F18@:|ᯆ4]ͧzֆFwQp01_H)t].}Aol\mx1 Fjy_as}jB2U`g'sKec>*6=ƣ&3C3sשH`#JDҴ7e1/n{s~Dtq*|Hkܭm.qHG)XZ[$mk +1- 0N:c/JC%Iu8r܀@t <k/]Oj}[\Zi+I]z;f [BDT~]h=غln.IGq#4?;_X5ϲj3Em"Y= N YytOciu}mgo Q4r(eo4]N >;[E4M]OB cxzg|%ukֲ]iV+IvIS_۷~q U :`Hph}SZŏ\|ծWXX-#?8;quΨ~|~<M YÞ$H1<l{^e:d6K'$7ԁZ92x?zOoK6jGH@Kz=N47;X{bN4)Yt>_,a@)^#b5.Ԛ%|>o[G؅ܷ$)ݍ|9sQ\Z_Ŧ٥Clf<_<2j<2q^xЁ%{ VJ6Z8—>O' gjvЭ̋8R8|xC:č~u |"݄g)1dqֺ߆7־ h-ޫo^5`G:}=E{B:r_Izw Wa[4-:LçYD[q5Ϯ@)_ⷄχh;$;s5uJ=KQk4cXH~_U~]eR;𷉵%S5ߖ̪#Obg6$ '03<>R6pR~b2%=mΡ᫦613V8 sZݨm 8#>q U_Tu۳iWeÞ(:aմ厥d <t!@kmllch쭡Fm̰߁SPkV{] ]8,"!3Ww_wOvRZ]Y,4LV܏hu+lcz5ݛM* h\O{V F IɎx~b<?p+=NZuiHA q>L7V_ψiuƗriI:F9O.} ⾅ӭOQ*KK6?4+:#O;۝/Ɠ\ڭHHQHYCn7nǭtֽ}ziⶻx,on'<ڽ"F]ښmϹMMC ,q¢P|]Rg- zK m<8 E@!IDL}UΣlmی}_31 !yk_ ^WR]ig1vz?_rmt={x#jnY\HF 8o>o>x#NTvIm,Fp1SJcSSZm'Ko.#R;zPicg^aԦ׆AKJtDV$|Ñz/ς?IEsKY],}.I###z |%Ѵww 1h.e{#*n:Fn`:}vA)wDq€<w4D?7W?:6z4v0G +[Y%{[haytaLԑzvO+KlblKj~ ᮷b3f{Do /!#pp9`q_Q-^=[B2.טFH~UY"]@_ɥY=9-n@}wc4?ٚRuԄvw*`MW7dW_Tnjqh|7bxH 0zc[;iuIͼ o\ kqk(vDpv_B׉x[IPxիCqtc/ &r͡_t:FȎ(8?x%kggWo:h>)n-82,n 1R<`@N0k,l-hW a~[K{vʁվ@>PƟ;mVkt5,qkw?h$G p`*#cmgc$V\q52OZ0Y>žIO'ٿ{[B.J3ycy,fkhd/r`}Q@#Ww/okKmk-U6G<=kw~kDĚo䱒ƒ#8aAǭz}g[}F IɊx?B1Me,m1%|zm(:5j :90HHgw9+.iz~ EYF,`\(j<?<x>ػySL/FC#g)]3?.lmtkN#-װz_cI ϧr%\r{:5U6SE5ͬ3K fʓӠS|B{7;O ^׆>S^9T# _Wi]$6:<8/t KѱUQ* []Da_M=Cígx_N@aI^^f+GS!$u<-^=[B2.טFH~T >W'玄}j>CczqKGjW÷ɴB(,20ҽ*+󝒠aGlflKy1r(((((~?xi1J˵cWM,K>*֟6ln-/f_p$A' Pp(ğuwwi\ɽlq#~#x<Ih*]aUT@P^! XgꗒMl]p,E*'8"_3Ks{Ydӭv,5$z{Q@W7{/^%K{tX؂{IEq?o/>n2O<Ϙ%&j((((T|// fjbm_ٟ_~$?lѱ|+;wgf+s=/%:],NUфlAr=f{ЯuKˋ۩~Oq+H1$>_>:񦣻>幍,`ϔٶu Ex-s>{ڴ^K> ԒpW<pW+(㷋O ?L{Sވ0f,== h|#x7SFIoݘ$p`rŇNzQ@}KR.Q.LvO;:djpp=zQEQEQEQEQEVwx|/K r%̎HCc\7NWAj׷7-<᧹r zPQEQEQEbx/D 0ֶپ>흹x3@tUM'ض_>O^F|7h߷<vqVšqNxLPcLR Bp'k(֩]x0i:券6L-h|O=+[Yn.G(]U$Uփx㤚.֓AZZsme22y$ &򏃞=Ե7]<m8mg4W7,7 dORkt|tS?%bh4KB|mFO$@D^YSƺmxcyn~4Ǭ钡HpT&N +~j_67v坚8sRpku|r]N@@EPEPEPEPE5G;*I_x▪u6vjm|*g <dNh(#]u}".kY^3(ZQEQEQEQEQE߁߈oַi[5fa7ٷoGZ̏\|RR+CrdXTlTm\S|6xƗz_n{}kRyc個,H'Zws:%th<5hy,͐H'h 3\vQ4k-ae9nm+þQaqkkcZо!|F--LKg,͜}k[Duj_l4<SsF[/ U$!$A¨ojO.:Iy{3A6'F8OV4>Ϥ%A8֢m>~zmKf,2DcFd?mB~i­xďt[߳]%3&/O-Oj?f[/6"I$bqQ;nbU]#ǿ4-. Tk>[ o  l)铸gڀ=ៈo|UGh+)p6 cvi~''WnSVf͜,Wps qĪ.y<皃Ze޳_4:x`p]@<Oz-ҵ}W\)8*xg=__5#e~dI%czc5S*/JܷqPqrX6|}kG9tމ⋡.C$GyN"=4[xé>")CkrjǕ "t801^H~*ӵrHQ697u8@XtA|RokIHsh @#[+[&]I5]"K gm18Ȣߌ^e⋝BFYΈdQPrAPx❥A/Jծug*UąAg=3xX< 5 3Ll$?4l@~62O8^е_㧀D4ZX?ۈeuL8$#@W/^O뚖#m>}yT_:G|+ꯨ7yte7jK fw{Wwzƻ\i|qit!M *_ÚNJ>Aa QS#$(I?zyO!4n^ '\r1zjo:_ve-\Xܚ:ǫ|'poQ26bFjm'g^2W=;xF^w.g,-!l99|Sx#{6mVPFT.޹,JxW]x0n|LͰ h+$_M]Es?xLF@Ms^{{mXO{}2AmoK,pdWWF|?D5I,`%d<3ƸxIJG oQQK눀_#S_⎽>Ne6J8d%evn>$ɥh-]7IH# O{e|LxRY4-y.:{%Xۂ|폅~v-WVS[XຸW@$Œ@<I~ k-b(X>܊ڿEoؖ{ RBQ3_ZG%/;TWPI#ncv5x~.>kV}I( @;q瞃^<ᾷ:dM?Rʽ <P_k]Hz|(@!lv듚o>*ZxOO v,EdsQL^oI6i3; ' 6 t jZ~.M^զִCy]\F?!'crZxǟ-u_R]*Y kYp\€p2}}"AOkdn{'b@T<7h^1uZAkGq2y ?:L^χVY0ۉp}vBVu 2O+#Nݳ;NI'C5M?g/FңHR loגjMW3xC2Zh6HB,[Ze!ZK]rM$:Frw}ֽ&dqV_ϊ<%O ~hⲱ-fyMnzTsNy'5q.sd#v8 >|?u^xQ)2I'S(.FpŸ]?dt.o\Yټ!Yn=sZ?o&o%.0!9 ('ٺѼS~sxh^Q`sdf`T;y K[i۽{XmtBŲ$QT99.߬-Ry zfk&ˣP>67m>KBiy~֢m3R&(7cM) 6][Wؽb썒l-dӜۥt=7.?kV*⎛7޳}NmFvJ6)'AҺzτ:ne-sL P_} /x[Qѧvo`hpcl|=+ļ)J-jR"ĭHfw%b<Cuxg> K|z-ٴ;:B8 ?W4W׾>%pYm'8gcß|]V}rrlBY`C/3/ /mh}κ}r$oPv[%c>Q2}pUs|ix«j2#xh>嶻")*Csvzߊ~WfTʷR lnrTx|kSu65 {{[!bOϺľ!ht&0\B}hǚcΛeKZkkgkjZIrĜyk_Ïxg4?\557h׀& G;N=7= 5vV 6k:i"X+яLouEmf|v ƒڣx )aͩiۛ%(" \Vyt町Hr31zs<1^sa4z]10%`ߕ&bψ }&I#r.0_΀<Ƕk|sbs[HEx89Fk<CxBY[]o{q(6b7@qW_ɬhIq[ \Xg ƷxW[w;}3ħmўIxoc P[Pׇ~o Tq#kw>mNY~mSFia|Ӥ]\-gVx%csLWMśJ"HbT|3}vNd9z8ɠ Y>,e6t/CWέKp$|!wWԼaϯxc> NpN]3\^cΩg'>:sa8 p @ߵ'@ t_CWW-7S<R'돴!C$9f*<g'ğ&SC|CqzAvV> @ۿoM5}3g5k #kp+EcYҿ[k }w (*1@ |S_iͩi֖NvFgH8$ xZ#YգCcЍ c=y$T|E+~zTw m,c#1W%־ |F՝/ xok=U }x GCTwVUh^dƒZ[ebˎp@z۵<cS6xBo xy7Mq6A ``g$1/^5h8-;&!OWLw׶Z O|`~ MSZK%O\*`x!1pHm2+xH]M֑F$W'@8`C/|A?Уnd&;_P9/qG^wRvR$GcrŀQ5 m&T`k#v0QI'*ޱH}Zzr u9%_νR0|mOFI& 9{Y8(w ׇ|ua<U쮯 }QDYBv q_E]=,Ѱuo 0%l0H\Ҁ<ėڤ7vzHr9Jfz#|EQjkךP$ * Sg<[sGTѯ:k9^3h(((((((((((((((((((((((ikz\;$W[;'Uu*H$om#@4B[k1oI䞟^EyjuNO 8䜱өףQEQEQEQEQEQEQEyz?|5nedE4gwF۞0yxSoKKmzv.yc<# 돯cPbb#LE 2sQEQEQEQEQEQEQEQEy5?hOŲ[4o5wO5tQ@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@W|7/|FtmQ퍥HG9#NSKM'z)Hw2wǺqmspYwD3'1svCn +.{om8w3OŒj;H1cuq8v =U{9Y;ovTW#xWG4FЫ/V?,,B'p~wrqf:dɻ ZQTz$DdȮMupѵ"[P89*T[Ԯ;+?L״`隅ċ |V&WQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQER;jY*$")AQMD6y*$*;k{̖ #dPQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEG_,_Kk? vaST},w!UFI'yƣtE .8i_"_n:סwk%]Z A;em +QF~ N*WW0YIxg*1 \rDo닅+  HTU:}WK' `ߍi5-4P-#P#T%Jcrj%Ck7-l=*POB@#Y\@ɍb۞w8^Ez/|xg{II%i]XYᏇ[Xy_3R rtm{%bFi !Mu6|'KԜdm5[Eqh.bt(Tq1ü>}4IV%IYHp9D\qVsWzm#@M QqDQZj|='wOsgmngyX@XWES9&Z'{(̠(((((((((((((((((Ğ|O 1G.cY @~1aVrʲc OkSߊ#ҭ+\ޭԮӾ7קNyy 5 (yF37|bI<iݿ O6u{3$nAs\wt_ӴRH(䑑$nsqWCom7MNkQW <65OH Ѯ;[%aitLq"g y~\žhd.deu\D (((((((((((((((((((> fߛF^h+%Y~ok*§z(Š((((((((((((((((((((( ~"Z.{iik᭦̏\d+77wlYIe}o61iU+Qo6]3i6*tVڊ,XIJio^SZ|, _g26x<1iz} msoI?:q=T [w_Bx2Oұy:\<<y3msoI?:qGž9|_=};<` CHs8sC1ǧ5.&"*8E;( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( mga揂Yц0©*|q>;N~3m9w>VWQEQEQEQEQEQEQEQEQEA},K%"irI+W|6[!ݴpp3ұz 4Cf+]y֛W/&^vEdx_[!𽖪is؂AU^+XK[NJbe/u^XAsǙEq |k7;f},H vR)(Q@Q@Q@Q@Q@Q@Q@TX[5+'7Wڗ0o4n~U2^i{m}g2M CןR+GVj 6Y T_zL,Ï3_|O}NΛ4Í௮sځ!46q,ϯG6o~Yǎ ڀ&-H.ۉ|kwǯ%L=X|\~hGijVo}Cҡ߷4s*>Q6:U>&E[#&ʃ:L\3/n:ۚmŽob %wQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEO,C V7mD-_[Wk? vPODaS㉯D'Qwvez+ ⽇~)M\'_G#R/_O&/uE`}? > ]o@bOo.x7[PؼSA}?^)M/_O&/uE`}? > ]o@bOo.x7[PؼSA}?zuNlءϮwԢ Kɒcy$l*sSSd%VS ^.-du,FM'ĺw=ZK}@]N[?::qڽ +OImam *~ Sn4}6nnlmzHGCIǕn_sΟ>KRDF1'3GxLjHV4`S$ y֪oRtGw8?z֙?* P,̌:ꥶagq$p,.պr3 ԹX?qM>#5/_O&~0> ]bOo. x7GؼSA}?(^)M/_O&~/t}? ߢ0> ]bOo. x7GؼSA}?(^)M/_O&~/u >"[gMXIrG륦Mw@<xkß.<{ux:izxY"}s[ $+5Œ ~Xvֽ-QQBQ+<)5͘׮Yw}U2@N%}iĻMՄ,u߷_jV|!;Z|?,tߎ =Eb6=hhq'KoOL 1j_趯iH<?l~/iPn=;C?:L<3luǦo[LkٌD*?OM4xfn:\[|LkYD-T|Jh(((((((((((((((((()k:΁KÒW:́:W~fo`9XccaZ.@|EǼ-Pz7e;|]nN鼱lsSEyGXQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEWR;GVH 6_YeAפW:ݪk^)үo#.P`zt@6gtas>阋NapW=sՕ/4K]:TAL2OxCeӬK[{(Jdހ5ZZ]y黮GbL?yqzj:L4;P6y\l~uqiPY=r(OMstxxg_\t|Z@y"W[:mu8V7.-~&xq䭽;d((((((((((((((((((( #dqa+~kO S"sгx߆Sumf N脖'#d|Bkju9!%(ݦ{%kQ o9X]wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wOqo  :6D_r5k-?nO N[-ʮs'_=7N8?;6D_rX.+jvo{E$N0esW1xkRЭ&{)<{0ʠ9&X?ckNm(J/,a#9<Qϥgx:g^b!obg %pZƵ5I~O!-o'~v?>"5O*6}YdOZ.z(Gz4O\}Umm ƊY<zΦsP3:0ybjQvWI]䖧]Eax3]>"\W+*1ۑz[%(.V:%J{(2 ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( φ"_W_Q%zy/`(JGWE; FE; 9\m 0(aqS(NFE; 9\m 0(aqS(NFE)j *;7}\|3wrZvPARZ v8^vQ5xͪim-r[׭T5CW:i#;Y[oZJdOݛOIP,sY"G#*KO0u xL!ۀpo=8溏+|ڪGR[PF>wOxtY{k8j8BINZ7+9&9.A}ERQEQEQEQEQEQEQEQEQEW;_*>-{J諝׽%\7w5PK {&v :{}8.0Nb4UFtcg%$$RZ*hT|^͜7Լ=Rua:ʝFm]!&H)`Hǵz=PKQu{iCzqUtzt; TU+JK֗_+|QEjpQ@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@y$kϾȅo_w=0:(Q@Q@Q@Q@Q@Q@Q@Q@ 4N4؃'j!^}VjS}" Ρ=^EJWly<)uX^vؤLMGzNRԡȺą#-6׫#YA##+*èaE%u|ٜbRaR8?Z'G7eVs*:T`zQMgi:6>d7*G|6<ZRA<k(CR 2 }J2f 15mꝿsp>'_Jcq*pN_-#PFoDLj`t5F`̠HIi`n(AEPEPEPEPEPEPEPEPEP\+w¿T|[^? pE!EPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEP^M zÞ^41htt!f^Ep?O?9+xO5Q@'#oƏNG 'SwP [*BT]r?W? hЭ?}Ep?O?9+xO5Q@'#ƏNG 'SwP [*BT]r?V? hЭ?}Ep?O?9+xO5Q@W? hƻ*ySO?8_*\.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'St' kHjDʑ,HI,Oֳ-m -,m};l2< 8vSb*ֽWMݽ U,0d?rE XK6ֽZ hj^(=>=zs_mLWȎ;u:+/AݤLfW>կN?W? j+QW(f>\Fʇp03sֽtT'WFr qRTG'+O5G" '+O55/_~,a_* ';OjZt+>.kJj)QEB ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (8J87^kU4}SDu]MuuYBG #p z]lEDIWە`A9ϰ>cy77RsBQ]cpy 8eN{-,I|[;y-o/+l_gpq|>ֽ"–7"-=uw|ϕ2zt<t.)Epko0%Ƒg>@J k[~Ϧ[3i=) lC*mf?oq@ǜ˩xN4ߵ%lj.s}o1(uqOiOq?:T\t@<IwW;dtuY~n qLWBs|~Ib;s^MlV1obe;( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( Z_j*VXt |*eHz []_j>)F4<ϕ2@Cl~ϥñ|qFqm&v?/6ޏ ~Md緽Os~f8ۓހ. SV_p%=G{7t+qG֔E*#8ޓ?|ҡ)|t~\y|}kQ^|LlV/ت,!oqSֱ|un#*,QEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEWNPUo)\32|>|Uo)i\4*eH=h}M~=-4xrg>FǏ3zP[]~k.v?Eo'LH䗔y\憎 [J|**GOu_iPVnhGNr&luϧ5ۨ>&xKu+Uv %lN>w>V[ZvV?-ԬbT%wQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQE|SO]~}y*eOG<k.kN5мK-^-ZO4n=@#G.l?y!D8uz˧?NC6F{fZ554}GP49-3HrI=YԢ«gT O4u_ۘt6ofgأJ}̶SG88hũc=TC^c?:^ w̑$CEBq@S.mb qlbs9Kh)4V$S`䢸8#txOëI&9ft'1#>5>[]>vv nOj((((((((((((((((((((((((((((((((((((((((((,Bi3< 4;msIK{rʳyzA] 0A\ufӼk3iA2ۡ_.inx?{9ʊ&<lris;og+szuƧ&m6+R^L!~b1Һ(g% mzMnEp#z*O ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (?
JFIF``ExifMM*;HasiJ >5454 2019:07:22 20:20:362019:07:22 20:20:36Has http://ns.adobe.com/xap/1.0/<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?> <x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/"/><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:xmp="http://ns.adobe.com/xap/1.0/"><xmp:CreateDate>2019-07-22T20:20:36.543</xmp:CreateDate></rdf:Description><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:creator><rdf:Seq xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li>Has</rdf:li></rdf:Seq> </dc:creator></rdf:Description></rdf:RDF></x:xmpmeta> <?xpacket end='w'?>C   '!%"."%()+,+ /3/*2'*+*C  ***************************************************" }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ?F(((((((((((((((((((((((((((((((((((((((((((((((*GhwڜK4vV\<p])bw'P+$|9 m$4hkHDχ&d^&d2FA|z+_I1>%v@!Rd60J((((((h^#-y5kH٫| %Ǩ Mv+Nm-:W}ιL1$f3EQEQEQEQ\<n>%\%-of/b;xvsEPEPEPEPEw oX{a2CU-p8d2 "EPEPEPE 徟c=m,p2I> :45=;+LSrA#QE#f=fx?i \{oU>I]~)h(ޥ=n$#X11Zhngiqե "3u=Y((( VfM{F B9Z1 Q@xǚo4+^xo1j;A;q(5h6\mM 99?ǥe~<t/{h1%Sm븖t tQET7}$!¢($* YAqY\b#lA]((((((((($cĿ-/#>1O?F<K^23?A7oi6!,wKֺm?5^2Ӵx>GUm3̲,H[m9 `8k+ǜ>2QB \xn@om{[KT˲ӭ2~C$'k UgK j<X\7wm\7 c~+GsgGZ}m iG*C.ebO =7J|QQ}"Xc-.FЬ${P5:ڶU˂2Ngj2IWK^!Ht?]isjaFAoI) k:uZl5oܖU.@R#5?0_%-m_ďKGm ==kdmbb)DM.pskΤodzNӨ귑[~D rY8>3~&o4fd6r7DW=#>CC¿}Y-M‡w0v"FdSMȗj e8]_$SNhw@*tB-m&I0rqҼxs+QԠԼSYv 9>bI=64Ue 0AK4 2`<rsPQ ǯh־ZKX0pDBc}y;9?R*pۊ</'{OC[U\]x5"]JT9k(n<Ospmߦ{qZMu׌].l%_i)@ls$+ξiƫwм.sis җMb~.7F9=#z0ĉ9Uˍ<79T8RI})>Ν ~\z$4PVRV-w%$ l='k^~?容ӟΞz/764}3R)8BpӽjK[xWtK#m껾u6I@kj϶.|t& !ҹs2 ށwh21@ ڹ:e3~1fwq|[qmn]+,%YFDs^ELjU'jmRF֮#rFyNN w>̚狇S k2h.z0NS8<Ә/퇫n nT U[Ů֕:MZByG- ;c@}h;_kEYTfC 8>+M'|E^xg^yYݶ;| pN<P7_`kXǖ<@Fԡ볛|C⿈MYJV[8 yr,1][5_Gӥx50Lq*60 `#C5/JK8l09ўw<]|Cм;]qpʤï3wy><]<V1{ě#& =js][J^LV!%؍LIjm\(<c@tU` z䏏M;<~"xYu.9 !\n@*H0A9W~`%ߎAMz@:[+gyyjPGt2c ~aj;q8*Z={~`h#bvȁ;Xv"x:T6RԴd$22~^r>2x/: 11Ն{p{ٺwixX ]FX"3#ֽ*ź&{ ܭ \8k⒫|=⼟DZO'I$O?Ql>PfhkSĒav{ۏ}خ7ͷtK95*I)oo2l.8cm5O ǫZٍ@ncq+ 6* %֯E!e/}[/žŒQn ǙOsɣ<ҵ17>6L;3OH־sz5|&נoxcP]D,QnYi_Z1#}\աROߒ>*d7bj<yq㶚[Ef 1ڪj_tX|0s9  +ZH>Z:zl! =OuQ[R(ӵ mWL,%Z³C #TWukcjQ[K{ ձcbsb|#$N_*O%)5z߈:?goh& -.)@ٛ(%sY/"ѡ׬WR.&qĨ8BLn/}z}+~s+G"GtC֬EYTmK,LFb;ЏQW'y??ʼ!'wrsL?<3Ǽ@0/L%]K=,v (bAx[|1enޗaKY1yk>Ꭳ%퍵ăXCK ɇkcicg ek ǥVO>M^m>K+cK .CXנ=9'zk;6aR3^`IP3\{c񷺵Y>V}H7|K׆5xz/ ZQ\I`r*8^(I|dOpe 6= }=[W+p%E=WĹ #7ZXwo8S4ψ7PKM|?hhc,c#q@O~/xbNX{䐰`e?<G}ºK\-؈B0+ưi\â#ÌDwn`ӕvr:X\#Ʒǫ5/ Yռ?nTVW2Ӑ>^oi0ݦJd\B A#Mkz]-;2K;{xrGڿXgr˻NOPs޻<+Eד\u I(HQ7G88;20y uXj&au3Om]¡,0'rtS o|-|K$QiwܼUW%ǧ$`8C۪ji7_5]Q"SGTm@U|K?_鑾 5Ȃ#ϵݖ=p2xO<) Д⿴my+5%.{{|>ǩOzq8?ir<8Ok9+۪i65ե.ke8ٴwq JOtn+S[jwQ[a(+"3kSǞ- ֍x^^`G_|pq+>!Z߳ﭤ09D1W>RzO}jnbK6>|m;h:·O^z.I\fIX6qcwNqݛ"Q_8?WƍKeڕݬ $['>VP #R 99O k#:h3Y]@N@^a) V$TOOZd9Y9m°;[@+ny-jȱd9Ƹm77ɦBKP6f?6=IlYI w^JLn/}u/"ѡ׬WR.&qĨ8O_xZR*&-J @ \Eoٮe`Hnw^_j=M"Y~VA\0U||,9xe.4 2EѓpA` xxx)/?[0-,>gǮ0N=yyOUѧe025L ${֓MV}k+]]i{$ u+댎1w>iOqmZŜOHzr:gֽ΀<ƿ|9Ax{Zu5n&K\p,8=W>|M:NH#DyR@ 3C~7BxV)kBpd|@>^Yv~5 H<ۑ $n8q( ( ( ( (3|Cx6wrkx=RBχm-]m,69Z4P?+Hռe&:̲a@`AƏx+HiZIBʓftϨ_?hL%]ۆއ%^6޸~èeuw=!w%6 M =xFJ죽E&x=#G洨.gh嶩m̳d:p'Ƴ׊ }k{pnx-p@w4P & I@n*pq;WE/ i :.,΢WcSZGWP"LQk7\zj/:65_h̚ H]G=P?eza0-dPa{ݭVm_[Դn5˟$ fGaj(:OXUf4SJOz/xO6?fYiyR3Ğ< MttP <p|Y?yfgӊi6qj\aeXy<(!~|.Xnx_ӌ7] \vG6>ŌByktPEP?ְu]f;EF`W<~K*{ {eEs4wEl<>LIbPv>#ڱ|#G^ #t)翇>Ls1dc03z |l{̗v1^NIdR22IqJ@?ohz[j=kmw*׮3&(+A [h:bȶ6јi$U'>Y7y+z/#rh2tn|7esAJ(<w%ٯi<m`a9ȏlWU|=|&ܡ g1gk35еses G}QҴ ᥶Y\~<x=k^~>n[q[ǫ4*DӴX,dPĸU5nű𖑧xS%KT8$ 3Qu="V(ݪX[o+0﷭mQ@^0vJUI.qVuXoCcq GlEgZ-4=MQۘ(ޥt}gFCky- pJ:lպ(ᯇnh?T '|%~ղ-Y?y^_ZPW<9Gv-a0ŎO~X֣(e*zKEs 6 m/é2[Mp,&yUT~$/4}L;Z^Fb#mb (~(Z[k^W.7t̅$~9^+{v:u%\Ln!^\ЙUO8:sxwG5ص6P}Amw|9-+{9I'ishommu۸pF}G5OI1Z5m:xgIᙥf-!<jh}S&Ko>M=kcxj_ &IH؞)o`Wq h WI+(f8I$ʶ( ᇆ4_R If/igyb`=+<F]ZԣkWoɒ(9.yr+(0<cǚ2i${xGV#p 1s\v<DΠh㾟̍HdWQ@ Hm# 9W8涽D0lGsqdg^Erí[ 0h jw(ZkźOci,QG~Q@~xo[K\n@y#=Ϩ8Wz^XfH@>ʣ+*jm^w8%Jckᯇnh?T '|%~@o <"e=M]7xϮOM>x| }D'rŕՎQtPO8u&+ֻ>ýJxb9_Z]Pz_)xr }뾢9O|4#?˞a[+MǠWWEo<]kwSO-n.d$}O#?h>+]Kv'b,=k ( ( ( ( (zWבi m~и2I3+>|PXm~/uT̚F̰;G SY?~-j~;4q嚬a?ۂ=’@Ex .ƚτL,tKGB)uVW 0ՙ|Y^f=[Iִ#BXE=I##@O Kk(u4(͵9\0hgM ߄1g X+!yQ8C:w>< a/ßfF=,<#i=6_-z}@$ dt3Z G^J#iH- <*2NIIapȡ xi.5n3 7@XMކ{Jfg`]m`HC sP?<񧎯ii~a<CĐk7>V(4+4;r0{g|&hԴt,7k̪ddd`0$A*ppzRttiLWgK3a 6Ìj>p2zUf<?mhr3W~:t߇k{M.WXo]]Ļ㓜s'ImkKӛE[EgG$^6u7|9׵x⺸UuFTd*0 'SyRMĹww'|^<!i I4yo <_ "j0m_joh5ǖ+:&:u~YNw{|t5 v>H.iCcdh$ i~9GĖ:]KT(dc7~|Qީ Ťk*Of*=^^ow[MrxݞO [>ڭ~I+4[zS!FIWU`s }|9յ6nn#Sn PY79!wd;PSExZ:/__:HT*y i'ᵕƴoo lЀF@S~x*+ĵ|K]ui{4sP892 jh h<r(tu9 "HeH#$p}+{;ޭ{ImeKۣ^y>=LJ|?ͯixbC+Zw\$9Ҁ;;<a?XjpFVd"':cz |_-,t\+按eډ$ᇍ|Ms_xR[j:Mmtt#u S7W Gҭmb{Cf(N8?tGOO{ .^Vo܈ C,Jyza gþf״<1!-r.S_^@ωd|5`ѯoǹ-Qϧ͟])`Xd7-g^<ΑZZAzt'+k+J_MZKuG<FVEc )HB78 dހ>|%mOomo`hca1ڶ7>)Gƣo]$nP=+Y<a:u˃io C 탂pɜ`ezψ)02մ:E}omnl!W8y9~!&mfG H=WZ@PFGQxfV:}j(]S;^`LyG³[Sk?ƬRD]UA.c(Z+ļ[n< }sNv$w,zWrXs'zgAhtRjqNȳXm|v9$t:PCE:|:-Jc¯,!8,Yz-{5rxSQ=2y+ʭm'8 v=\&ύO5gw mcq<p-\|V?ZkTݯ.m"c~Sӷvx>3y7zP&QT4Xx|F)K#]5y-f/gF4:)(evX %'N|ah:ckRB6 $U 1!yfZ+>>4㦷tY mT:::ҸĩMK~"4Dzd]1T9Ҁ>''PTA?1Sm43ZiNEdo9qF#rwdVr <miwsZ(xۑր;( ԼO7|Go:]ʫ}#iD9nTW['46cdw+| Axx'}>_nN>P~@yW3x6<<4k`ǘ5sx=oOO)z0WORMd bY3x7nJa#j+ƼE_Im=eCylH$ ͎zd ;Co|'oNw =jZXZ6Pi c)Q@X 8=ik]|FMŤZd3edV24#s@O|;o&{OjmUaGCn=AfE^<E\"RE#h@Rgn@x/㽿[ $K;z0<*#s^8 Fr W_}cy/5-cOow )1.ݵr\Ojxv4_ϚᵿUPEy׌↭v shU*Ϩ$y9*a1ۿ^S7I!Ŵ"wlVul@v Q^N|ah:ckRB6 $U 1!yfx^4 㧶մtY mT:::Ҁ=Nj||KCi.ā>O|F񶯤|5t}_"TJIU`F2: _Y~ԗ0xPԵ%NnmەPtQEQEQEQEQE|Zկqi?(WOϮOtlZeeOHwa]䷆YXcy!%vPLd ;'11́ȡe PY]etEVۼ qHGp3x[ j_ }J/]x7y-Ēu(DȔ9 q޾e X`:RYb ɱϩ\`zΟ jz5]Mxӌ75iR rۺ@AZ%"<t1Ok&IW+F '5aźg</uk2F3;rOWR SY>^O '|@,cٞ;z}3ݍ}!Oi3ކ=TV*xS7OT mkogs@?@׌~#>.:z,Wm̱F18@:|ᯆ4]ͧzֆFwQp01_H)t].}Aol\mx1 Fjy_as}jB2U`g'sKec>*6=ƣ&3C3sשH`#JDҴ7e1/n{s~Dtq*|Hkܭm.qHG)XZ[$mk +1- 0N:c/JC%Iu8r܀@t <k/]Oj}[\Zi+I]z;f [BDT~]h=غln.IGq#4?;_X5ϲj3Em"Y= N YytOciu}mgo Q4r(eo4]N >;[E4M]OB cxzg|%ukֲ]iV+IvIS_۷~q U :`Hph}SZŏ\|ծWXX-#?8;quΨ~|~<M YÞ$H1<l{^e:d6K'$7ԁZ92x?zOoK6jGH@Kz=N47;X{bN4)Yt>_,a@)^#b5.Ԛ%|>o[G؅ܷ$)ݍ|9sQ\Z_Ŧ٥Clf<_<2j<2q^xЁ%{ VJ6Z8—>O' gjvЭ̋8R8|xC:č~u |"݄g)1dqֺ߆7־ h-ޫo^5`G:}=E{B:r_Izw Wa[4-:LçYD[q5Ϯ@)_ⷄχh;$;s5uJ=KQk4cXH~_U~]eR;𷉵%S5ߖ̪#Obg6$ '03<>R6pR~b2%=mΡ᫦613V8 sZݨm 8#>q U_Tu۳iWeÞ(:aմ厥d <t!@kmllch쭡Fm̰߁SPkV{] ]8,"!3Ww_wOvRZ]Y,4LV܏hu+lcz5ݛM* h\O{V F IɎx~b<?p+=NZuiHA q>L7V_ψiuƗriI:F9O.} ⾅ӭOQ*KK6?4+:#O;۝/Ɠ\ڭHHQHYCn7nǭtֽ}ziⶻx,on'<ڽ"F]ښmϹMMC ,q¢P|]Rg- zK m<8 E@!IDL}UΣlmی}_31 !yk_ ^WR]ig1vz?_rmt={x#jnY\HF 8o>o>x#NTvIm,Fp1SJcSSZm'Ko.#R;zPicg^aԦ׆AKJtDV$|Ñz/ς?IEsKY],}.I###z |%Ѵww 1h.e{#*n:Fn`:}vA)wDq€<w4D?7W?:6z4v0G +[Y%{[haytaLԑzvO+KlblKj~ ᮷b3f{Do /!#pp9`q_Q-^=[B2.טFH~UY"]@_ɥY=9-n@}wc4?ٚRuԄvw*`MW7dW_Tnjqh|7bxH 0zc[;iuIͼ o\ kqk(vDpv_B׉x[IPxիCqtc/ &r͡_t:FȎ(8?x%kggWo:h>)n-82,n 1R<`@N0k,l-hW a~[K{vʁվ@>PƟ;mVkt5,qkw?h$G p`*#cmgc$V\q52OZ0Y>žIO'ٿ{[B.J3ycy,fkhd/r`}Q@#Ww/okKmk-U6G<=kw~kDĚo䱒ƒ#8aAǭz}g[}F IɊx?B1Me,m1%|zm(:5j :90HHgw9+.iz~ EYF,`\(j<?<x>ػySL/FC#g)]3?.lmtkN#-װz_cI ϧr%\r{:5U6SE5ͬ3K fʓӠS|B{7;O ^׆>S^9T# _Wi]$6:<8/t KѱUQ* []Da_M=Cígx_N@aI^^f+GS!$u<-^=[B2.טFH~T >W'玄}j>CczqKGjW÷ɴB(,20ҽ*+󝒠aGlflKy1r(((((~?xi1J˵cWM,K>*֟6ln-/f_p$A' Pp(ğuwwi\ɽlq#~#x<Ih*]aUT@P^! XgꗒMl]p,E*'8"_3Ks{Ydӭv,5$z{Q@W7{/^%K{tX؂{IEq?o/>n2O<Ϙ%&j((((T|// fjbm_ٟ_~$?lѱ|+;wgf+s=/%:],NUфlAr=f{ЯuKˋ۩~Oq+H1$>_>:񦣻>幍,`ϔٶu Ex-s>{ڴ^K> ԒpW<pW+(㷋O ?L{Sވ0f,== h|#x7SFIoݘ$p`rŇNzQ@}KR.Q.LvO;:djpp=zQEQEQEQEQEVwx|/K r%̎HCc\7NWAj׷7-<᧹r zPQEQEQEbx/D 0ֶپ>흹x3@tUM'ض_>O^F|7h߷<vqVšqNxLPcLR Bp'k(֩]x0i:券6L-h|O=+[Yn.G(]U$Uփx㤚.֓AZZsme22y$ &򏃞=Ե7]<m8mg4W7,7 dORkt|tS?%bh4KB|mFO$@D^YSƺmxcyn~4Ǭ钡HpT&N +~j_67v坚8sRpku|r]N@@EPEPEPEPE5G;*I_x▪u6vjm|*g <dNh(#]u}".kY^3(ZQEQEQEQEQE߁߈oַi[5fa7ٷoGZ̏\|RR+CrdXTlTm\S|6xƗz_n{}kRyc個,H'Zws:%th<5hy,͐H'h 3\vQ4k-ae9nm+þQaqkkcZо!|F--LKg,͜}k[Duj_l4<SsF[/ U$!$A¨ojO.:Iy{3A6'F8OV4>Ϥ%A8֢m>~zmKf,2DcFd?mB~i­xďt[߳]%3&/O-Oj?f[/6"I$bqQ;nbU]#ǿ4-. Tk>[ o  l)铸gڀ=ៈo|UGh+)p6 cvi~''WnSVf͜,Wps qĪ.y<皃Ze޳_4:x`p]@<Oz-ҵ}W\)8*xg=__5#e~dI%czc5S*/JܷqPqrX6|}kG9tމ⋡.C$GyN"=4[xé>")CkrjǕ "t801^H~*ӵrHQ697u8@XtA|RokIHsh @#[+[&]I5]"K gm18Ȣߌ^e⋝BFYΈdQPrAPx❥A/Jծug*UąAg=3xX< 5 3Ll$?4l@~62O8^е_㧀D4ZX?ۈeuL8$#@W/^O뚖#m>}yT_:G|+ꯨ7yte7jK fw{Wwzƻ\i|qit!M *_ÚNJ>Aa QS#$(I?zyO!4n^ '\r1zjo:_ve-\Xܚ:ǫ|'poQ26bFjm'g^2W=;xF^w.g,-!l99|Sx#{6mVPFT.޹,JxW]x0n|LͰ h+$_M]Es?xLF@Ms^{{mXO{}2AmoK,pdWWF|?D5I,`%d<3ƸxIJG oQQK눀_#S_⎽>Ne6J8d%evn>$ɥh-]7IH# O{e|LxRY4-y.:{%Xۂ|폅~v-WVS[XຸW@$Œ@<I~ k-b(X>܊ڿEoؖ{ RBQ3_ZG%/;TWPI#ncv5x~.>kV}I( @;q瞃^<ᾷ:dM?Rʽ <P_k]Hz|(@!lv듚o>*ZxOO v,EdsQL^oI6i3; ' 6 t jZ~.M^զִCy]\F?!'crZxǟ-u_R]*Y kYp\€p2}}"AOkdn{'b@T<7h^1uZAkGq2y ?:L^χVY0ۉp}vBVu 2O+#Nݳ;NI'C5M?g/FңHR loגjMW3xC2Zh6HB,[Ze!ZK]rM$:Frw}ֽ&dqV_ϊ<%O ~hⲱ-fyMnzTsNy'5q.sd#v8 >|?u^xQ)2I'S(.FpŸ]?dt.o\Yټ!Yn=sZ?o&o%.0!9 ('ٺѼS~sxh^Q`sdf`T;y K[i۽{XmtBŲ$QT99.߬-Ry zfk&ˣP>67m>KBiy~֢m3R&(7cM) 6][Wؽb썒l-dӜۥt=7.?kV*⎛7޳}NmFvJ6)'AҺzτ:ne-sL P_} /x[Qѧvo`hpcl|=+ļ)J-jR"ĭHfw%b<Cuxg> K|z-ٴ;:B8 ?W4W׾>%pYm'8gcß|]V}rrlBY`C/3/ /mh}κ}r$oPv[%c>Q2}pUs|ix«j2#xh>嶻")*Csvzߊ~WfTʷR lnrTx|kSu65 {{[!bOϺľ!ht&0\B}hǚcΛeKZkkgkjZIrĜyk_Ïxg4?\557h׀& G;N=7= 5vV 6k:i"X+яLouEmf|v ƒڣx )aͩiۛ%(" \Vyt町Hr31zs<1^sa4z]10%`ߕ&bψ }&I#r.0_΀<Ƕk|sbs[HEx89Fk<CxBY[]o{q(6b7@qW_ɬhIq[ \Xg ƷxW[w;}3ħmўIxoc P[Pׇ~o Tq#kw>mNY~mSFia|Ӥ]\-gVx%csLWMśJ"HbT|3}vNd9z8ɠ Y>,e6t/CWέKp$|!wWԼaϯxc> NpN]3\^cΩg'>:sa8 p @ߵ'@ t_CWW-7S<R'돴!C$9f*<g'ğ&SC|CqzAvV> @ۿoM5}3g5k #kp+EcYҿ[k }w (*1@ |S_iͩi֖NvFgH8$ xZ#YգCcЍ c=y$T|E+~zTw m,c#1W%־ |F՝/ xok=U }x GCTwVUh^dƒZ[ebˎp@z۵<cS6xBo xy7Mq6A ``g$1/^5h8-;&!OWLw׶Z O|`~ MSZK%O\*`x!1pHm2+xH]M֑F$W'@8`C/|A?Уnd&;_P9/qG^wRvR$GcrŀQ5 m&T`k#v0QI'*ޱH}Zzr u9%_νR0|mOFI& 9{Y8(w ׇ|ua<U쮯 }QDYBv q_E]=,Ѱuo 0%l0H\Ҁ<ėڤ7vzHr9Jfz#|EQjkךP$ * Sg<[sGTѯ:k9^3h(((((((((((((((((((((((ikz\;$W[;'Uu*H$om#@4B[k1oI䞟^EyjuNO 8䜱өףQEQEQEQEQEQEQEyz?|5nedE4gwF۞0yxSoKKmzv.yc<# 돯cPbb#LE 2sQEQEQEQEQEQEQEQEy5?hOŲ[4o5wO5tQ@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@W|7/|FtmQ퍥HG9#NSKM'z)Hw2wǺqmspYwD3'1svCn +.{om8w3OŒj;H1cuq8v =U{9Y;ovTW#xWG4FЫ/V?,,B'p~wrqf:dɻ ZQTz$DdȮMupѵ"[P89*T[Ԯ;+?L״`隅ċ |V&WQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQER;jY*$")AQMD6y*$*;k{̖ #dPQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEG_,_Kk? vaST},w!UFI'yƣtE .8i_"_n:סwk%]Z A;em +QF~ N*WW0YIxg*1 \rDo닅+  HTU:}WK' `ߍi5-4P-#P#T%Jcrj%Ck7-l=*POB@#Y\@ɍb۞w8^Ez/|xg{II%i]XYᏇ[Xy_3R rtm{%bFi !Mu6|'KԜdm5[Eqh.bt(Tq1ü>}4IV%IYHp9D\qVsWzm#@M QqDQZj|='wOsgmngyX@XWES9&Z'{(̠(((((((((((((((((Ğ|O 1G.cY @~1aVrʲc OkSߊ#ҭ+\ޭԮӾ7קNyy 5 (yF37|bI<iݿ O6u{3$nAs\wt_ӴRH(䑑$nsqWCom7MNkQW <65OH Ѯ;[%aitLq"g y~\žhd.deu\D (((((((((((((((((((> fߛF^h+%Y~ok*§z(Š((((((((((((((((((((( ~"Z.{iik᭦̏\d+77wlYIe}o61iU+Qo6]3i6*tVڊ,XIJio^SZ|, _g26x<1iz} msoI?:q=T [w_Bx2Oұy:\<<y3msoI?:qGž9|_=};<` CHs8sC1ǧ5.&"*8E;( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( mga揂Yц0©*|q>;N~3m9w>VWQEQEQEQEQEQEQEQEQEA},K%"irI+W|6[!ݴpp3ұz 4Cf+]y֛W/&^vEdx_[!𽖪is؂AU^+XK[NJbe/u^XAsǙEq |k7;f},H vR)(Q@Q@Q@Q@Q@Q@Q@TX[5+'7Wڗ0o4n~U2^i{m}g2M CןR+GVj 6Y T_zL,Ï3_|O}NΛ4Í௮sځ!46q,ϯG6o~Yǎ ڀ&-H.ۉ|kwǯ%L=X|\~hGijVo}Cҡ߷4s*>Q6:U>&E[#&ʃ:L\3/n:ۚmŽob %wQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEO,C V7mD-_[Wk? vPODaS㉯D'Qwvez+ ⽇~)M\'_G#R/_O&/uE`}? > ]o@bOo.x7[PؼSA}?^)M/_O&/uE`}? > ]o@bOo.x7[PؼSA}?zuNlءϮwԢ Kɒcy$l*sSSd%VS ^.-du,FM'ĺw=ZK}@]N[?::qڽ +OImam *~ Sn4}6nnlmzHGCIǕn_sΟ>KRDF1'3GxLjHV4`S$ y֪oRtGw8?z֙?* P,̌:ꥶagq$p,.պr3 ԹX?qM>#5/_O&~0> ]bOo. x7GؼSA}?(^)M/_O&~/t}? ߢ0> ]bOo. x7GؼSA}?(^)M/_O&~/u >"[gMXIrG륦Mw@<xkß.<{ux:izxY"}s[ $+5Œ ~Xvֽ-QQBQ+<)5͘׮Yw}U2@N%}iĻMՄ,u߷_jV|!;Z|?,tߎ =Eb6=hhq'KoOL 1j_趯iH<?l~/iPn=;C?:L<3luǦo[LkٌD*?OM4xfn:\[|LkYD-T|Jh(((((((((((((((((()k:΁KÒW:́:W~fo`9XccaZ.@|EǼ-Pz7e;|]nN鼱lsSEyGXQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEWR;GVH 6_YeAפW:ݪk^)үo#.P`zt@6gtas>阋NapW=sՕ/4K]:TAL2OxCeӬK[{(Jdހ5ZZ]y黮GbL?yqzj:L4;P6y\l~uqiPY=r(OMstxxg_\t|Z@y"W[:mu8V7.-~&xq䭽;d((((((((((((((((((( #dqa+~kO S"sгx߆Sumf N脖'#d|Bkju9!%(ݦ{%kQ o9X]wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wW o9G,moֿm@wOqo  :6D_r5k-?nO N[-ʮs'_=7N8?;6D_rX.+jvo{E$N0esW1xkRЭ&{)<{0ʠ9&X?ckNm(J/,a#9<Qϥgx:g^b!obg %pZƵ5I~O!-o'~v?>"5O*6}YdOZ.z(Gz4O\}Umm ƊY<zΦsP3:0ybjQvWI]䖧]Eax3]>"\W+*1ۑz[%(.V:%J{(2 ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( φ"_W_Q%zy/`(JGWE; FE; 9\m 0(aqS(NFE; 9\m 0(aqS(NFE)j *;7}\|3wrZvPARZ v8^vQ5xͪim-r[׭T5CW:i#;Y[oZJdOݛOIP,sY"G#*KO0u xL!ۀpo=8溏+|ڪGR[PF>wOxtY{k8j8BINZ7+9&9.A}ERQEQEQEQEQEQEQEQEQEW;_*>-{J諝׽%\7w5PK {&v :{}8.0Nb4UFtcg%$$RZ*hT|^͜7Լ=Rua:ʝFm]!&H)`Hǵz=PKQu{iCzqUtzt; TU+JK֗_+|QEjpQ@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@y$kϾȅo_w=0:(Q@Q@Q@Q@Q@Q@Q@Q@ 4N4؃'j!^}VjS}" Ρ=^EJWly<)uX^vؤLMGzNRԡȺą#-6׫#YA##+*èaE%u|ٜbRaR8?Z'G7eVs*:T`zQMgi:6>d7*G|6<ZRA<k(CR 2 }J2f 15mꝿsp>'_Jcq*pN_-#PFoDLj`t5F`̠HIi`n(AEPEPEPEPEPEPEPEPEP\+w¿T|[^? pE!EPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEP^M zÞ^41htt!f^Ep?O?9+xO5Q@'#oƏNG 'SwP [*BT]r?W? hЭ?}Ep?O?9+xO5Q@'#ƏNG 'SwP [*BT]r?V? hЭ?}Ep?O?9+xO5Q@W? hƻ*ySO?8_*\.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'SwQȂ J'Sԯ?E.pԯ? J'St' kHjDʑ,HI,Oֳ-m -,m};l2< 8vSb*ֽWMݽ U,0d?rE XK6ֽZ hj^(=>=zs_mLWȎ;u:+/AݤLfW>կN?W? j+QW(f>\Fʇp03sֽtT'WFr qRTG'+O5G" '+O55/_~,a_* ';OjZt+>.kJj)QEB ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (8J87^kU4}SDu]MuuYBG #p z]lEDIWە`A9ϰ>cy77RsBQ]cpy 8eN{-,I|[;y-o/+l_gpq|>ֽ"–7"-=uw|ϕ2zt<t.)Epko0%Ƒg>@J k[~Ϧ[3i=) lC*mf?oq@ǜ˩xN4ߵ%lj.s}o1(uqOiOq?:T\t@<IwW;dtuY~n qLWBs|~Ib;s^MlV1obe;( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( Z_j*VXt |*eHz []_j>)F4<ϕ2@Cl~ϥñ|qFqm&v?/6ޏ ~Md緽Os~f8ۓހ. SV_p%=G{7t+qG֔E*#8ޓ?|ҡ)|t~\y|}kQ^|LlV/ت,!oqSֱ|un#*,QEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEWNPUo)\32|>|Uo)i\4*eH=h}M~=-4xrg>FǏ3zP[]~k.v?Eo'LH䗔y\憎 [J|**GOu_iPVnhGNr&luϧ5ۨ>&xKu+Uv %lN>w>V[ZvV?-ԬbT%wQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQE|SO]~}y*eOG<k.kN5мK-^-ZO4n=@#G.l?y!D8uz˧?NC6F{fZ554}GP49-3HrI=YԢ«gT O4u_ۘt6ofgأJ}̶SG88hũc=TC^c?:^ w̑$CEBq@S.mb qlbs9Kh)4V$S`䢸8#txOëI&9ft'1#>5>[]>vv nOj((((((((((((((((((((((((((((((((((((((((((,Bi3< 4;msIK{rʳyzA] 0A\ufӼk3iA2ۡ_.inx?{9ʊ&<lris;og+szuƧ&m6+R^L!~b1Һ(g% mzMnEp#z*O ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (?
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
from __future__ import annotations class Node: """ A Node has data variable and pointers to Nodes to its left and right. """ def __init__(self, data: int) -> None: self.data = data self.left: Node | None = None self.right: Node | None = None def display(tree: Node | None) -> None: # In Order traversal of the tree """ >>> root = Node(1) >>> root.left = Node(0) >>> root.right = Node(2) >>> display(root) 0 1 2 >>> display(root.right) 2 """ if tree: display(tree.left) print(tree.data) display(tree.right) def depth_of_tree(tree: Node | None) -> int: """ Recursive function that returns the depth of a binary tree. >>> root = Node(0) >>> depth_of_tree(root) 1 >>> root.left = Node(0) >>> depth_of_tree(root) 2 >>> root.right = Node(0) >>> depth_of_tree(root) 2 >>> root.left.right = Node(0) >>> depth_of_tree(root) 3 >>> depth_of_tree(root.left) 2 """ return 1 + max(depth_of_tree(tree.left), depth_of_tree(tree.right)) if tree else 0 def is_full_binary_tree(tree: Node) -> bool: """ Returns True if this is a full binary tree >>> root = Node(0) >>> is_full_binary_tree(root) True >>> root.left = Node(0) >>> is_full_binary_tree(root) False >>> root.right = Node(0) >>> is_full_binary_tree(root) True >>> root.left.left = Node(0) >>> is_full_binary_tree(root) False >>> root.right.right = Node(0) >>> is_full_binary_tree(root) False """ if not tree: return True if tree.left and tree.right: return is_full_binary_tree(tree.left) and is_full_binary_tree(tree.right) else: return not tree.left and not tree.right def main() -> None: # Main function for testing. tree = Node(1) tree.left = Node(2) tree.right = Node(3) tree.left.left = Node(4) tree.left.right = Node(5) tree.left.right.left = Node(6) tree.right.left = Node(7) tree.right.left.left = Node(8) tree.right.left.left.right = Node(9) print(is_full_binary_tree(tree)) print(depth_of_tree(tree)) print("Tree is: ") display(tree) if __name__ == "__main__": main()
from __future__ import annotations class Node: """ A Node has data variable and pointers to Nodes to its left and right. """ def __init__(self, data: int) -> None: self.data = data self.left: Node | None = None self.right: Node | None = None def display(tree: Node | None) -> None: # In Order traversal of the tree """ >>> root = Node(1) >>> root.left = Node(0) >>> root.right = Node(2) >>> display(root) 0 1 2 >>> display(root.right) 2 """ if tree: display(tree.left) print(tree.data) display(tree.right) def depth_of_tree(tree: Node | None) -> int: """ Recursive function that returns the depth of a binary tree. >>> root = Node(0) >>> depth_of_tree(root) 1 >>> root.left = Node(0) >>> depth_of_tree(root) 2 >>> root.right = Node(0) >>> depth_of_tree(root) 2 >>> root.left.right = Node(0) >>> depth_of_tree(root) 3 >>> depth_of_tree(root.left) 2 """ return 1 + max(depth_of_tree(tree.left), depth_of_tree(tree.right)) if tree else 0 def is_full_binary_tree(tree: Node) -> bool: """ Returns True if this is a full binary tree >>> root = Node(0) >>> is_full_binary_tree(root) True >>> root.left = Node(0) >>> is_full_binary_tree(root) False >>> root.right = Node(0) >>> is_full_binary_tree(root) True >>> root.left.left = Node(0) >>> is_full_binary_tree(root) False >>> root.right.right = Node(0) >>> is_full_binary_tree(root) False """ if not tree: return True if tree.left and tree.right: return is_full_binary_tree(tree.left) and is_full_binary_tree(tree.right) else: return not tree.left and not tree.right def main() -> None: # Main function for testing. tree = Node(1) tree.left = Node(2) tree.right = Node(3) tree.left.left = Node(4) tree.left.right = Node(5) tree.left.right.left = Node(6) tree.right.left = Node(7) tree.right.left.left = Node(8) tree.right.left.left.right = Node(9) print(is_full_binary_tree(tree)) print(depth_of_tree(tree)) print("Tree is: ") display(tree) if __name__ == "__main__": main()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" * Binary Exponentiation for Powers * This is a method to find a^b in a time complexity of O(log b) * This is one of the most commonly used methods of finding powers. * Also useful in cases where solution to (a^b)%c is required, * where a,b,c can be numbers over the computers calculation limits. * Done using iteration, can also be done using recursion * @author chinmoy159 * @version 1.0 dated 10/08/2017 """ def b_expo(a, b): res = 1 while b > 0: if b & 1: res *= a a *= a b >>= 1 return res def b_expo_mod(a, b, c): res = 1 while b > 0: if b & 1: res = ((res % c) * (a % c)) % c a *= a b >>= 1 return res """ * Wondering how this method works ! * It's pretty simple. * Let's say you need to calculate a ^ b * RULE 1 : a ^ b = (a*a) ^ (b/2) ---- example : 4 ^ 4 = (4*4) ^ (4/2) = 16 ^ 2 * RULE 2 : IF b is ODD, then ---- a ^ b = a * (a ^ (b - 1)) :: where (b - 1) is even. * Once b is even, repeat the process to get a ^ b * Repeat the process till b = 1 OR b = 0, because a^1 = a AND a^0 = 1 * * As far as the modulo is concerned, * the fact : (a*b) % c = ((a%c) * (b%c)) % c * Now apply RULE 1 OR 2 whichever is required. """
""" * Binary Exponentiation for Powers * This is a method to find a^b in a time complexity of O(log b) * This is one of the most commonly used methods of finding powers. * Also useful in cases where solution to (a^b)%c is required, * where a,b,c can be numbers over the computers calculation limits. * Done using iteration, can also be done using recursion * @author chinmoy159 * @version 1.0 dated 10/08/2017 """ def b_expo(a, b): res = 1 while b > 0: if b & 1: res *= a a *= a b >>= 1 return res def b_expo_mod(a, b, c): res = 1 while b > 0: if b & 1: res = ((res % c) * (a % c)) % c a *= a b >>= 1 return res """ * Wondering how this method works ! * It's pretty simple. * Let's say you need to calculate a ^ b * RULE 1 : a ^ b = (a*a) ^ (b/2) ---- example : 4 ^ 4 = (4*4) ^ (4/2) = 16 ^ 2 * RULE 2 : IF b is ODD, then ---- a ^ b = a * (a ^ (b - 1)) :: where (b - 1) is even. * Once b is even, repeat the process to get a ^ b * Repeat the process till b = 1 OR b = 0, because a^1 = a AND a^0 = 1 * * As far as the modulo is concerned, * the fact : (a*b) % c = ((a%c) * (b%c)) % c * Now apply RULE 1 OR 2 whichever is required. """
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" The algorithm finds the pattern in given text using following rule. The bad-character rule considers the mismatched character in Text. The next occurrence of that character to the left in Pattern is found, If the mismatched character occurs to the left in Pattern, a shift is proposed that aligns text block and pattern. If the mismatched character does not occur to the left in Pattern, a shift is proposed that moves the entirety of Pattern past the point of mismatch in the text. If there no mismatch then the pattern matches with text block. Time Complexity : O(n/m) n=length of main string m=length of pattern string """ from __future__ import annotations class BoyerMooreSearch: def __init__(self, text: str, pattern: str): self.text, self.pattern = text, pattern self.textLen, self.patLen = len(text), len(pattern) def match_in_pattern(self, char: str) -> int: """finds the index of char in pattern in reverse order Parameters : char (chr): character to be searched Returns : i (int): index of char from last in pattern -1 (int): if char is not found in pattern """ for i in range(self.patLen - 1, -1, -1): if char == self.pattern[i]: return i return -1 def mismatch_in_text(self, currentPos: int) -> int: """ find the index of mis-matched character in text when compared with pattern from last Parameters : currentPos (int): current index position of text Returns : i (int): index of mismatched char from last in text -1 (int): if there is no mismatch between pattern and text block """ for i in range(self.patLen - 1, -1, -1): if self.pattern[i] != self.text[currentPos + i]: return currentPos + i return -1 def bad_character_heuristic(self) -> list[int]: # searches pattern in text and returns index positions positions = [] for i in range(self.textLen - self.patLen + 1): mismatch_index = self.mismatch_in_text(i) if mismatch_index == -1: positions.append(i) else: match_index = self.match_in_pattern(self.text[mismatch_index]) i = ( mismatch_index - match_index ) # shifting index lgtm [py/multiple-definition] return positions text = "ABAABA" pattern = "AB" bms = BoyerMooreSearch(text, pattern) positions = bms.bad_character_heuristic() if len(positions) == 0: print("No match found") else: print("Pattern found in following positions: ") print(positions)
""" The algorithm finds the pattern in given text using following rule. The bad-character rule considers the mismatched character in Text. The next occurrence of that character to the left in Pattern is found, If the mismatched character occurs to the left in Pattern, a shift is proposed that aligns text block and pattern. If the mismatched character does not occur to the left in Pattern, a shift is proposed that moves the entirety of Pattern past the point of mismatch in the text. If there no mismatch then the pattern matches with text block. Time Complexity : O(n/m) n=length of main string m=length of pattern string """ from __future__ import annotations class BoyerMooreSearch: def __init__(self, text: str, pattern: str): self.text, self.pattern = text, pattern self.textLen, self.patLen = len(text), len(pattern) def match_in_pattern(self, char: str) -> int: """finds the index of char in pattern in reverse order Parameters : char (chr): character to be searched Returns : i (int): index of char from last in pattern -1 (int): if char is not found in pattern """ for i in range(self.patLen - 1, -1, -1): if char == self.pattern[i]: return i return -1 def mismatch_in_text(self, currentPos: int) -> int: """ find the index of mis-matched character in text when compared with pattern from last Parameters : currentPos (int): current index position of text Returns : i (int): index of mismatched char from last in text -1 (int): if there is no mismatch between pattern and text block """ for i in range(self.patLen - 1, -1, -1): if self.pattern[i] != self.text[currentPos + i]: return currentPos + i return -1 def bad_character_heuristic(self) -> list[int]: # searches pattern in text and returns index positions positions = [] for i in range(self.textLen - self.patLen + 1): mismatch_index = self.mismatch_in_text(i) if mismatch_index == -1: positions.append(i) else: match_index = self.match_in_pattern(self.text[mismatch_index]) i = ( mismatch_index - match_index ) # shifting index lgtm [py/multiple-definition] return positions text = "ABAABA" pattern = "AB" bms = BoyerMooreSearch(text, pattern) positions = bms.bad_character_heuristic() if len(positions) == 0: print("No match found") else: print("Pattern found in following positions: ") print(positions)
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Author : Yvonne This is a pure Python implementation of Dynamic Programming solution to the longest_sub_array problem. The problem is : Given an array, to find the longest and continuous sub array and get the max sum of the sub array in the given array. """ class SubArray: def __init__(self, arr): # we need a list not a string, so do something to change the type self.array = arr.split(",") print(("the input array is:", self.array)) def solve_sub_array(self): rear = [int(self.array[0])] * len(self.array) sum_value = [int(self.array[0])] * len(self.array) for i in range(1, len(self.array)): sum_value[i] = max( int(self.array[i]) + sum_value[i - 1], int(self.array[i]) ) rear[i] = max(sum_value[i], rear[i - 1]) return rear[len(self.array) - 1] if __name__ == "__main__": whole_array = input("please input some numbers:") array = SubArray(whole_array) re = array.solve_sub_array() print(("the results is:", re))
""" Author : Yvonne This is a pure Python implementation of Dynamic Programming solution to the longest_sub_array problem. The problem is : Given an array, to find the longest and continuous sub array and get the max sum of the sub array in the given array. """ class SubArray: def __init__(self, arr): # we need a list not a string, so do something to change the type self.array = arr.split(",") print(("the input array is:", self.array)) def solve_sub_array(self): rear = [int(self.array[0])] * len(self.array) sum_value = [int(self.array[0])] * len(self.array) for i in range(1, len(self.array)): sum_value[i] = max( int(self.array[i]) + sum_value[i - 1], int(self.array[i]) ) rear[i] = max(sum_value[i], rear[i - 1]) return rear[len(self.array) - 1] if __name__ == "__main__": whole_array = input("please input some numbers:") array = SubArray(whole_array) re = array.solve_sub_array() print(("the results is:", re))
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" Author : Mehdi ALAOUI This is a pure Python implementation of Dynamic Programming solution to the longest increasing subsequence of a given sequence. The problem is : Given an array, to find the longest and increasing sub-array in that given array and return it. Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return [10, 22, 33, 41, 60, 80] as output """ from __future__ import annotations def longest_subsequence(array: list[int]) -> list[int]: # This function is recursive """ Some examples >>> longest_subsequence([10, 22, 9, 33, 21, 50, 41, 60, 80]) [10, 22, 33, 41, 60, 80] >>> longest_subsequence([4, 8, 7, 5, 1, 12, 2, 3, 9]) [1, 2, 3, 9] >>> longest_subsequence([9, 8, 7, 6, 5, 7]) [8] >>> longest_subsequence([1, 1, 1]) [1, 1, 1] >>> longest_subsequence([]) [] """ array_length = len(array) # If the array contains only one element, we return it (it's the stop condition of # recursion) if array_length <= 1: return array # Else pivot = array[0] isFound = False i = 1 longest_subseq: list[int] = [] while not isFound and i < array_length: if array[i] < pivot: isFound = True temp_array = [element for element in array[i:] if element >= array[i]] temp_array = longest_subsequence(temp_array) if len(temp_array) > len(longest_subseq): longest_subseq = temp_array else: i += 1 temp_array = [element for element in array[1:] if element >= pivot] temp_array = [pivot] + longest_subsequence(temp_array) if len(temp_array) > len(longest_subseq): return temp_array else: return longest_subseq if __name__ == "__main__": import doctest doctest.testmod()
""" Author : Mehdi ALAOUI This is a pure Python implementation of Dynamic Programming solution to the longest increasing subsequence of a given sequence. The problem is : Given an array, to find the longest and increasing sub-array in that given array and return it. Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return [10, 22, 33, 41, 60, 80] as output """ from __future__ import annotations def longest_subsequence(array: list[int]) -> list[int]: # This function is recursive """ Some examples >>> longest_subsequence([10, 22, 9, 33, 21, 50, 41, 60, 80]) [10, 22, 33, 41, 60, 80] >>> longest_subsequence([4, 8, 7, 5, 1, 12, 2, 3, 9]) [1, 2, 3, 9] >>> longest_subsequence([9, 8, 7, 6, 5, 7]) [8] >>> longest_subsequence([1, 1, 1]) [1, 1, 1] >>> longest_subsequence([]) [] """ array_length = len(array) # If the array contains only one element, we return it (it's the stop condition of # recursion) if array_length <= 1: return array # Else pivot = array[0] isFound = False i = 1 longest_subseq: list[int] = [] while not isFound and i < array_length: if array[i] < pivot: isFound = True temp_array = [element for element in array[i:] if element >= array[i]] temp_array = longest_subsequence(temp_array) if len(temp_array) > len(longest_subseq): longest_subseq = temp_array else: i += 1 temp_array = [element for element in array[1:] if element >= pivot] temp_array = [pivot] + longest_subsequence(temp_array) if len(temp_array) > len(longest_subseq): return temp_array else: return longest_subseq if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" References: wikipedia:square free number python/black : True flake8 : True """ from __future__ import annotations def is_square_free(factors: list[int]) -> bool: """ # doctest: +NORMALIZE_WHITESPACE This functions takes a list of prime factors as input. returns True if the factors are square free. >>> is_square_free([1, 1, 2, 3, 4]) False These are wrong but should return some value it simply checks for repition in the numbers. >>> is_square_free([1, 3, 4, 'sd', 0.0]) True >>> is_square_free([1, 0.5, 2, 0.0]) True >>> is_square_free([1, 2, 2, 5]) False >>> is_square_free('asd') True >>> is_square_free(24) Traceback (most recent call last): ... TypeError: 'int' object is not iterable """ return len(set(factors)) == len(factors) if __name__ == "__main__": import doctest doctest.testmod()
""" References: wikipedia:square free number python/black : True flake8 : True """ from __future__ import annotations def is_square_free(factors: list[int]) -> bool: """ # doctest: +NORMALIZE_WHITESPACE This functions takes a list of prime factors as input. returns True if the factors are square free. >>> is_square_free([1, 1, 2, 3, 4]) False These are wrong but should return some value it simply checks for repition in the numbers. >>> is_square_free([1, 3, 4, 'sd', 0.0]) True >>> is_square_free([1, 0.5, 2, 0.0]) True >>> is_square_free([1, 2, 2, 5]) False >>> is_square_free('asd') True >>> is_square_free(24) Traceback (most recent call last): ... TypeError: 'int' object is not iterable """ return len(set(factors)) == len(factors) if __name__ == "__main__": import doctest doctest.testmod()
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
{ "001": "c0b20f4665d0388d564f0b6ecf3edc9f9480cb15fff87198b95701d9f5fe1f7b", "002": "1f5882e19314ac13acca52ad5503184b3cb1fd8dbeea82e0979d799af2361704", "003": "5c09f0554518a413e58e6bc5964ba90655713483d0b2bbc94572ad6b0b4dda28", "004": "aa74f52b4c428d89606b411bc165eb81a6266821ecc9b4f30cdb70c5c930f4d9", "005": "1ba90ab11bfb2d2400545337212b0de2a5c7f399215175ade6396e91388912b1", "006": "537942be3eb323c507623a6a73fa87bf5aeb97b7c7422993a82aa7c15f6d9cd6", "007": "ecbe74e25cfa4763dbc304ccac2ffb9912e9625cd9993a84bd0dd6d7dc0ca021", "008": "b9fb30b6553415e9150051ce5710a93d0f55b22557c0068d8e16619a388f145a", "009": "d912d9d473ef86f12da1fb2011c5c0c155bd3a0ebdb4bbd7ea275cecdcb63731", "010": "bed2d160e02f0540f19a64ca738aacb79cfcd08ba7e2421567b16cb6e7e3e90e", "011": "9ded5bc849d33e477aa9c944138d34f0aacc485a372e84464e8a572712a5b7da", "012": "3e7be445b6c19e6db58c2482005c1f78cb74011a4279249ca632011a9f1b61a2", "013": "3cb265a96c5645a9ad11d47551f015c25f3f99792c951617656d84626fbc4868", "014": "78a262dd40eba0f7195686ec7f3891a39437523456f8d16fa9065a34409eeac6", "015": "7b8f812ca89e311e1b16b903de76fa7b0800a939b3028d9dc4d35f6fa4050281", "016": "a6f988d30328bd706c66f8ac0d92aac21dd732149cdd69cb31f459dca20c5abe", "017": "1a455b216c6e916943acf3fa4c7e57a7a5cac66d97cc51befca810c223ef9c23", "018": "fde3f2e7127f6810eb4160bf7bb0563240d78c9d75a9a590b6d6244748a7f4ff", "019": "284de502c9847342318c17d474733ef468fbdbe252cddf6e4b4be0676706d9d0", "020": "c86a2932e1c79343a3c16fb218b9944791aaeedd3e30c87d1c7f505c0e588f7c", "021": "e8c6ef4a1736a245b5682e0262c5c43862cfb233ca5e286be2f5bb4d8a974ecf", "022": "85148c096c25e3ed3da55c7e9c89448018b0f5f53ad8d042129c33d9beac6736", "023": "42e2552a2f589e021824339e2508629ffa00b3489ea467f47e77a1ea97e735c9", "024": "4677b3d9daa3b30a9665e4558f826e04f7833dda886b8ef24f7176519a0db537", "025": "7d398da8791745001b3d1c41030676d1c036687eb1ab32e0b5a1832e7579c073", "026": "fbe10beedf9d29cf53137ba38859ffd1dbe7642cedb7ef0a102a3ab109b47842", "027": "e4110e0852a2f70703f0081fc91c4a20f595919a038729cb37c564d68b875c6f", "028": "261171a770d594f6a7fc76c1a839eda7f6dd4e9495e00e75048578fc86d8adf0", "029": "a207c35d8417aeed4c9e78bcf83f936cd8191c702893be62aa690ce16bc909ca", "030": "46e68e4199ab0a663ab306651528b06756556c9f0d8b819095af45e036dfbe6b", "031": "8de34b4ba97b184c7a2096b9266776175242b87d67bc8d77d7289be6f70cd105", "032": "0d246750daa7f1b367a21f55da454ddc8f62e0a95d163062e9b9273320d5130f", "033": "ad57366865126e55649ecb23ae1d48887544976efea46a48eb5d85a6eeb4d306", "034": "728b8d7d6d5d34cad9cbb7c3ea15f807ae57144594b1740b3c73b82314ccd1ed", "035": "02d20bbd7e394ad5999a4cebabac9619732c343a4cac99470c03e23ba2bdc2bc", "036": "9480c0160719234b57defc0681c0949a175ffb3ff4a3bf5e8163ac843f383f35", "037": "e9800abda89919edac504e90dac91f95e0778e3ba0f21a0bac4e77a84766eaaf", "038": "b2004522103364a6e842b9d042c0707d79af68dec7810078729d061fb7948912", "039": "fd0f7e53c5b02b688a57ee37f3d52065cb168a7b9fd5a3abd93d37e1559fbd30", "040": "d29d53701d3c859e29e1b90028eec1ca8e2f29439198b6e036c60951fb458aa1", "041": "bf05020e70de94e26dba112bb6fb7b0755db5ca88c7225e99187c5a08c8a0428", "042": "79d6eaa2676189eb927f2e16a70091474078e2117c3fc607d35cdc6b591ef355", "043": "6512f20c244844b6130204379601855098826afa1b55ff91c293c853ddf67db5", "044": "97e2524fd3796e83b06c0f89fdcb16e4c544e76e9c0496f57ac84834869f4cc3", "045": "8b0300d71656b9cf0716318be9453c99a13bb8644d227fd683d06124e6a28b35", "046": "8485ee802cc628b8cbd82476133d11b57af87e00711516a703525a9af0193b12", "047": "c7274da71333bd93201fa1e05b1ed54e0074d83f259bd7148c70ddc43082bde1", "048": "743d17cbff06ab458b99ecbb32e1d6bb9a7ff2ac804118f7743177dd969cfc61", "049": "47c6094ff1ff6e37788def89190c8256619ef1511681c503fea02c171569d16e", "050": "6ee74ef623df9fb69facd30b91ed78fe70370462bb267097f0dfeef9d9b057bb", "051": "d17cec28356b4f9a7f1ec0f20cca4c89e270aeb0e75d70d485b05bb1f28e9f6d", "052": "ebd72b510911af3e254a030cd891cb804e1902189eee7a0f6199472eb5e4dba2", "053": "9705cc6128a60cc22581217b715750a6053b2ddda67cc3af7e14803b27cf0c1f", "054": "12e2c8df501501b2bb531e941a737ffa7a2a491e849c5c5841e3b6132291bc35", "055": "9f484139a27415ae2e8612bf6c65a8101a18eb5e9b7809e74ca63a45a65f17f4", "056": "3658d7fa3c43456f3c9c87db0490e872039516e6375336254560167cc3db2ea2", "057": "620c9c332101a5bae955c66ae72268fbcd3972766179522c8deede6a249addb7", "058": "196f327021627b6a48db9c6e0a3388d110909d4bb957eb3fbc90ff1ecbda42cb", "059": "0295239a9d71f7452b93e920b7e0e462f712af5444579d25e06b9614ed77de74", "060": "ad7c26db722221bfb1bf7e3c36b501bedf8be857b1cfa8664fccb074b54354f9", "061": "94e4fb283c1abcccae4b8b28e39a294a323cdc9732c3d3ce1133c518d0a286f6", "062": "d25a595036aa8722157aca38f90084acb369b00df1070f49e203d5a3b7a0736d", "063": "0e17daca5f3e175f448bacace3bc0da47d0655a74c8dd0dc497a3afbdad95f1f", "064": "6d62aa4b52071e39f064a930d190b85ab327eb1a5045a8050ac538666ee765ca", "065": "1c6c0bb2c7ecdc3be8e134f79b9de45155258c1f554ae7542dce48f5cc8d63f0", "066": "316c0f93c7fe125865d85d6e7e7a31b79e9a46c414c45078b732080fa22ef2a3", "067": "53f66b6783cb7552d83015df01b0d5229569fce1dd7d1856335c7244b9a3ded6", "068": "4bf689d09a156621220881a2264dc031b2bfb181213b26d6ff2c338408cf94c3", "069": "79555e4b891e2885525c136f8b834cc0b1e9416960b12e371111a5cb2da0479f", "070": "08c6a7c8c06a01d2b17993ada398084b0707652bcfbd580f9173bcddf120ac2c", "071": "63f032489227c969135c6a6571fe9b33d6970dc6eca32c2086c61a4a099c98fa", "072": "9ef8a4249d4b8f24147ab6e9ad2536eb04f10fb886a8099e88e0e7c41cf7c616", "073": "ae9f9c786cd0f24fe03196d5061545862d87a208580570d46e2cfb371319aa68", "074": "b7c7470e59e2a2df1bfd0a4705488ee6fe0c5c125de15cccdfab0e00d6c03dc0", "075": "8a426e100572b8e2ea7c1b404a1ee694699346632cf4942705c54f05162bc07a", "076": "81c54809c3bdfc23f844fde21ae645525817b6e1bee1525270f49282888a5546", "077": "7f2253d7e228b22a08bda1f09c516f6fead81df6536eb02fa991a34bb38d9be8", "078": "71374036b661ac8ffe4b78c191050c3ccd1c956ca8a5f465ea1956f7ce571f63", "079": "2df095aea1862ebfed8df7fb26e8c4a518ca1a8f604a31cfba9da991fc1d6422", "080": "58bfe3a44f8ae452aaa6ef6267bafc3e841cfe7f9672bdfeb841d2e3a62c1587", "081": "04bad90d08bdf11010267ec9d1c9bbb49a813194dace245868ea8140aec9a1f7", "082": "52c42c55daea3131d5357498b8a0ddcf99d1babd16f6ccaee67cb3d0a665b772", "083": "a825281bc5ce8fe70d66a04e96314e7de070f11fed0f78bc81e007ca7c92e8b0", "084": "692a776beae0e92d1121fed36427c10d0860344614ead6b4760d1b7091a6ab1f", "085": "7b2e7211fb4f4d8352c9215c591252344775c56d58b9a5ff88bda8358628ec4e", "086": "8ffe8459134b46975acd31df13a50c51dbeacf1c19a764bf1602ba7c73ffc8fb", "087": "cec1917df3b3ee1f43b3468596ed3042df700dc7a752fefc06c4142a2832995d", "088": "c06356fdcaff01810e1f794263f3e44a75f28e8902a145a0d01a1fff77614722", "089": "0df5486b7bca884d5f00c502e216f734b2865b202397f24bca25ac9b8a95ab4a", "090": "cb69775effd93fc34ef38dfbfcdc4c593b1a3d8e7ab70c0f05d627dbc5cbd298", "091": "327f057e054d1e6a9a1be4ac6acc4b1dedc63d8a88222396ffe98b3194067347", "092": "538cd20a275b610698691d714b2adf4e4c321915def05667f4d25d97413ec076", "093": "d8ed8ca27d83a63df6982905ea53b4613b9d7974edcee06f301cf43d63177f47", "094": "d1b79281d95ce5bfa848060de4e0c80af2c3cae1ff7453cca31ff31e2d67ac14", "095": "0a3ddcd71cf30a567070630f947ab79fc168865ba0bf112aed9b71fb4e76c32f", "096": "9c527d233befbf357335e18e6dd5b14ef3a62e19ef34f90bd3fb9e5a2a0a0111", "097": "f0e2911e303617c9648692ee8056beeb045d89e469315716abed47cd94a3cd56", "098": "ededac5db280586f534cde4f69ce2c134d2360d6b5da3c3ebc400494cc016e78", "099": "92c5fd0421c1d619cbf1bdba83a207261f2c5f764aed46db9b4d2de03b72b654", "100": "993189cbf49fef4c913aa081f2ef44d360b84bf33d19df93fce4663ac34e9927", "101": "e8539f8b271851cad65d551354874d3086fa9ff7b6f6a2ab9890d63f5ba16c68", "102": "9d693eeee1d1899cbc50b6d45df953d3835acf28ee869879b45565fccc814765", "103": "1f17277005b8d58ad32f2cbee4c482cb8c0f3687c3cfe764ec30ee99827c3b1d", "104": "87dfcf5471e77980d098ff445701dbada0f6f7bac2fa5e43fa7685ec435040e1", "105": "a76f4e7fa1357a955743d5c0acb2e641c50bcaf0eec27eb4aaffebb45fe12994", "106": "197f5e68d1e83af7e40a7c7717acc6a99767bf8c53eece9253131a3790a02063", "107": "bf13bc90121776d7de3c4c3ca4c400a4c12284c3da684b3d530113236813ce81", "108": "3dea386e2c4a8a0633b667fdd4beacd8bb3fe27c282f886c828ad7d6b42c2d73", "109": "735cc3e619b9a1e3ac503ba5195c43c02d968113fd3795373ca085ed7777b54d", "110": "01b4e8163485356b46f612c9d40ed4b8602621d4d02289623e7dbb3dcbe03395", "111": "97c1b054c094337ec1397cd5ccdf6c9efe1067ad16f531824a94eaadb3c0953b", "112": "c99c843e0f6d6566132d97c829780332218e005efc14b633e25a5badb912d63a", "113": "8dbc8319e5d8923ef7ab42108341ee2c32a34ffc0d19d5ae5677f1564813314a", "114": "b3b9ebc9f9ddadb6b630eeef5d7ba724b3bb4d071b249318093eb7547949bbb9", "115": "80c3cd40fa35f9088b8741bd8be6153de05f661cfeeb4625ffbf5f4a6c3c02c4", "116": "a39208d7130682b772d6206acd746bc3779cc1bc0033f0a472e97993d0a32d5b", "117": "54201fbc7a70d21c1b0acede7708f1658d8e87032ab666001e888e7887c67d50", "118": "834e6235764ae632737ebf7cd0be66634c4fb70fe1e55e858efd260a66a0e3a9", "119": "bcabd9609d7293a3a3f1640c2937e302fa52ff03a95c117f87f2c465817eba5e", "120": "2bd8cabf5aecfcadde03beda142ac26c00b6ccfc59fdcb685672cd79a92f63a6", "121": "5292478e83f6b244c7c7c5c1fe272121abdc2982f66ed11fcbc6ea7e73af124d", "122": "6d78b19a042a64f08cc4df0d42fb91cd757829718e60e82a54e3498f03f3ef32", "123": "057b9b6e49d03958b3f38e812d2cfdd0f500e35e537b4fa9afedd2f3444db8a2", "124": "d251170c5287da10bffc1ac8af344e0c434ef5f649fd430fcf1049f90d45cf45", "125": "e9b7a676dc359ffce7075886373af79e3348ddbf344502614d9940eecd0532c1", "126": "38752ed2e711a3c001d5139cb3c945c0f780939db4ea80d68f31e6763b11cfba", "127": "e707d9f315269a34d94d9d9fa4f8b29328e66b53447ef38419c6033e57d5d123", "128": "5e15922fba7f61ddccb2ee579b5ec35034cc32def25ff156ae2b0a3e98c4414e", "129": "3cc4ad1254491787f52a66e595dbb573e13ceb554c51d81e42d5490a575da070", "130": "7a6e9899cccb6a01e05013c622422717f54853f7f2581bc3b88a78b25981da08", "131": "4a8596a7790b5ca9e067da401c018b3206befbcf95c38121854d1a0158e7678a", "132": "ed77e05f47f7f19f09cae9b272bfd6daa1682b426d39dcb7f473234c0c9381c5", "133": "e456d3fec55d88653dd88c3f8bbde1f8240c8ceb7882016d19e6f329e412a4ae", "134": "b144116982f4f0930038299efbdd56afc1528ef59047fb75bade8777309fde4b", "135": "0709e1008834c2ca8648376ac62d74ac8df5457069cbfedf2b0776dab07a3c5b", "136": "84692ebaa4fc17e9cfce27126b3fc5a92c1e33e1d94658de0544f8b35a597592", "137": "6eca481578c967fb9373fe4ce7930b39d8eefe1c0c9c7cb5af241a766bd4dfbc", "138": "1b5f0f504917592dea2e878497b0e12655366f2a7a163e0a081d785124982d2c", "139": "0d2f26ec4004c99171fc415282ec714afa617208480b45aeb104c039dc653f5d", "140": "78ceab5e434a86a6a6bb4f486707bffaf536ef6cb2cc5b45a90b3edd89a03283", "141": "d74ae4b07f05779065fb038b35d85a21444ed3bed2373f51d9e22d85a16a704c", "142": "f59af8b0b63a3d0eb580405092c1539261aec18890ea5b6d6e2d93697d67cd38", "143": "66e9d1093f00eef9a32e704232219f462138f13c493cc0775c507cf51cb231ed", "144": "09a1b036b82baba3177d83c27c1f7d0beacaac6de1c5fdcc9680c49f638c5fb9", "145": "b910b9b7bf3c3f071e410e0474958931a022d20c717a298a568308250ed2b0da", "146": "5292f0166523ea1a89c9f7f2d69064dee481a7d3c119841442cd36f03c42b657", "147": "cdb162a8a376b1df385dac44ce7b10777c9fea049961cb303078ebbd08d70de8", "148": "54f631973f7bc002a958b818a1e99e2fc1a91c41eafe19b9136fac9a4eb8d7b8", "149": "c49382eb9fc41e750239ac7b209513a266e80a268c83cf4d0c79f571629bac48", "150": "c89b0574a2e2f4a63845fe0fd9d51122d9d4149d887995051c3e53d2244bba41", "151": "5d09e3b57ced9fd215acc96186743e422ce48900b8992c9b6c74d3e4117e4140", "152": "c3ea99f86b2f8a74ef4145bb245155ff5f91cd856f287523481c15a1959d5fd1", "153": "fb57f89f289ee59c36cede64d2d13828b8997766b49aa4530aabfc18ff4a4f17", "154": "c877d90a178511a52ae2b2119e99e0b8b643cec44d5fd864bd3ef3e0d7f1f4bb", "155": "58801bebc14c905b79c209affab74e176e2e971c1d9799a1a342ae6a3c2afbc1", "156": "983d2222220ab7ffa243f48274f6eb82f92258445b93b23724770995575d77fe", "157": "023344e94ad747fbc529e3e68b95e596badcc445c85c1c7c8fa590e3d492779a", "158": "d1b58f4c07d1db5eb97785807b6d97a0d1ee1340e7dbcc7bb289f3547559f2fc", "159": "cd3a3d2cf8973c5f2c97ebed2460784818513e7d0fee8f98f4fdcf510295e159", "160": "3a926519b024ea9df5e7ad79d0b1c4400f78f58d07834f5ecd7be522112b676d", "161": "2b3d09a4c76b282db1428342c82c5a55c0ab57c7a7640e0850d82021164477e9", "162": "d50ce1ab3a25a5c5e020517092128ab3ec4a3bd5b58673b2e6cda86bcc0c48a0", "163": "7e17ce0fca5d559f76015765c652d76b8468f9ddc91c2069d7799867b9d52769", "164": "5c680d0b2c4dfac8aade87be60cb4d04a4c3d4db398f51e2cbf131d699b630a8", "165": "304de2e63f91f8f74faaebae7a7ec2e0c6e0d8d322d8a747e4e3be88de2d3505", "166": "14212843872dab188a86eb1f0f7012e1b72ea1097545f29377b3b9b52822af76", "167": "18c18f8710f831a82eb74ae979bd36d609bee818c972ff88f8d8fa065270f951", "168": "66640021d592f79b510f9d6101bd8eca89893187d23919c8edff4075e73ae390", "169": "819b01e0394727fd089f84b9351243176920f03d0c6e33e5ff136016da5d8d4e", "170": "e68fadd33a8c41d9a259577a278d8518aeb8b81c67b8cf03ccf43fc451ec8bd8", "171": "33bf9ed4714b0e5da8828f8b3d9d3e9d0cf55c1d496324acb04a3f195252749c", "172": "b9a27b513dc15448772cac5e914de61f02efe323f528892c0bff86d19913a6bd", "173": "1b2a5e44fda5dfee3ce230f44fe73c672249f6620cdbaa343ba0ba808034958c", "174": "98aabf085c6c8647f5e8a4775dc1d036513742d8e03b8c5c51e41bdfc9c3e7ae", "175": "c03dcb22b7faf121d99542018dd10a07a778abee2678d35c03394a8d207b826b", "176": "4fff1a7beda4291446d76e5ed5177c3f36e52a10481009fdaf2976da39e802ae", "177": "614d3df0ba5fdffab2328eff8e9ca2d76b09bbc447c06bf1fab0419ae278fae9", "178": "094a2ba3011118efdd9d4c1f839e6747dee8ba953b52e9012fe2977e32599375", "179": "9f5563a5ea90ca7023f0304acba78005ee6b7351245a8a668a94dfef160f8d29", "180": "dbef09115a57784ea4ea14c1fe35571301b0d6139bea29d1b9e0babf2c2aae05", "181": "3920627e86db42beb1cdf61d026f9f7798082f1221db25a17fb7feb6c1d49027", "182": "58096166bb8199abf4e07a9ef0f960065e5a635443c1937a1a3c527ade51d594", "183": "bdf84a73b16a5dd5ece189dc970ab2c8f0cb5334c96bdd1d6ba2bad6e7f8a213", "184": "c1e8c0f1b1eb3c258923e9daa46ef055bd79512b485c7dc73a9c5e395d5e6911", "185": "0ea72907eb6c1120740cd80ee6b9a935cd754edcf69379328f24dfc3f09b9986", "186": "3c0078aeae0362b6b7561518d3eb28400193fec73aab35980f138c28b6579433", "187": "f2bc655b33e35669ee9adc841cbda98e0834083eb0657d10f7170e70081db7e0", "188": "38e0291a3f5438779b157e5efcae6cef9db21cbac5607cd08882844cf981febd", "189": "9b2a65ac4c35f6b392501dee2a28221a3975aac5f0866b476f5e6a5a59f3fcc2", "190": "606fe2cb6525dabfcdab93afb594dbc8399cb967fc05f0ca93f6084d3f8fb591", "191": "ea1977e7b22df383de61bded2a4bb3064cf17fcc0170be452330256f938b8d55", "192": "91d614f139082168d730003f04b87135c64e13709ced2a96001ed60796867825", "193": "65648f18a50a7f9195fe56bb8cb9e25421c6d777ad2447a3b566dc8c54f3399a", "194": "cdd31847c6138853597261756d5e795884566220a9361217daa5ba7f87560404", "195": "d12224510de6c98076f6289cbe342a7ec7ea3c5453f6e3cf8d37d9eea74bd07e", "196": "1349b472d2821dff215e54d683dbfca49f0b490ade6a30b1db9667bc94e5312d", "197": "e2aa8f7cb3ba893af8bddbffa6240e7eb71a4f4c4498f2a360f3db7b513094df", "198": "a29d9edd0dceca9a72d2238a50dbb728846cd06594baec35a1b2c053faeab93d", "199": "50a6b9725ef854537a554584ca74612a4d37d0ec35d85d04812c3ae730a4c8cc", "200": "5b439098a3081d99496a7b1b2df6500ca5f66c2f170c709a57b27c6be717538a", "201": "b4e86186652a11df0b9ec8f601c68b4823ae0bafd96357051371fde5d11a25ed", "202": "057243f52fd25fa90a16219d945950ed5523ddb7eb6f2f361b33f8b85af25930", "203": "2742f7af8ce9e20185e940bb4e27afc5fefe8cd7d01d7d8e16c7a5aaf3ad47aa", "204": "15f5e9ae4636a6bf8bdd52f582774b9696b485671f4a64ab8c717166dc085205", "205": "e03c2f4ceabf677ec502d235064a62271ce2ee91132b33f57382c4150c295784", "206": "16bb96da8f20d738bbd735404ea148818ef5942d4d1bc4c707171f9e5e476b1e", "207": "133fea765d0b055894d8aba573f47891c1f7f715f53edeefb200fbda758a1884", "208": "90831cd89b4cceacaf099c9bae2452132cfa2f2b5553c651ef4948460e53d1f3", "209": "570fab1574a3fd9aca6404083dec1c150e858e137692ee0c8011e702ec3e902f", "210": "ae9a76ce3418c06d0eac3375a82744fb4250a2f380e723c404334d8572faead0", "211": "aa4b2bc3a136b27bf10a858ac6a8d48f41e40f769182c444df89c5b9f0ed84e5", "212": "81489bf56605b69cc48f0bce22615d4415b2eea882a11a33e1b317c4facba6eb", "213": "a497e789f49b77d647de0e80cd2699acd3d384cc29c534d6609c700968124d14", "214": "409520c6a94de382003db04a3dfee85a6dbb71324f8bd033e566e510ad47e747", "215": "0eccb27846f417380a12dfd588a353e151b328425ecf3794c9cf7b7eec1a1110", "216": "f735b4b441635ecded989bdc2862e35c75f5179d118d0533ae827a84ed29e81b", "217": "9aa88ac109aefaa7ce79c7b085495863a70679058b106a5deb76b2772a531faa", "218": "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9", "219": "9da1307fd12f4c9a21a34e612920cec286d937418a2d5040676408ba0c47f3d8", "220": "a262318d02a14747ed2137c701f94248bf8651a23d1f82826952e66c25029588", "221": "bfb4e53578fa42f83eda027da0467a351298dd65e3e8e84a987d69fc275e9f2d", "222": "4308f4374b84e657aa7a21e5f5fe42ed16386b6dc7a74bff0d24d08ad62acd26", "223": "3790f82f65ce7bc071b4096ca22544548b3413a755f58bfc401eff3ddf487a86", "224": "96356c050fa66d919c75212d789544db81b012bbaf1f7915b053cb9ba2d67de7", "225": "f37f3f2b0dc57a86dee4ba6ff855283bb4d2f0dea1c5bd1b708853444c2ffcec", "226": "49bd28d97a79875007a6713aa9700df14464217c28a6e76bc93ded57b75a33f5", "227": "b1f73471a3e6ea1dfb04610bd89ccb110994780084280fae872d42a2786f9131", "228": "e38da154f6cccd06cd0001924ec2dad8de5bdcd0b78b68e8d8347768d99ac0bd", "229": "098ffc6baaa32734053275ce38f4bbe58efe0ff946bf31e0e2df4c6a169e23d8", "230": "2c72b887a8638941b85765645b45c5cdb73255427e14d5114f6830f847a6b861", "231": "4aa0c92e77eeed08994650ac6129d77db9f026ae2aee78ad5c9fde132fac0505", "232": "5f7905b71cb897bc7cc6db7e29cc38ee459e2fd8f5d58ba4746d3acd4e46d444", "233": "8d986e287ad21475728b0dbd9e935623d69db4e5fdca0d42bc32d70eda48985b", "234": "2d9d03b778af897e305caa8a1a14a117737bbdd549003c6d7477dd3be8331694", "235": "7168cff545d365b09e8997bb9450343c7090913876c8f7eb9f0e9849c6fc7dd5", "236": "ceb3002bad36c22c5da82fd422b36bad91b97a7d3f5409ed5d16aa9b42dc137a", "237": "c857d8fa78c8fde91f29b3fbe332c2e781f7e8b54532f4c352693d6676fda2a8", "238": "3e2edae8b8ddbcfaecd5aa6c69cb5960b84cc16f7b3232f3386aae9ecbd23f20", "239": "49df3a63ca6509687cabb3d208e92b057630231e66b87fe8c781baabb12a55f8", "240": "5034a21557b2de1c5c2d2aadfe8ffe62162c23f42d1aaabc705ed8519e91a3c1", "241": "85abbe1913df41c57d1e6f00cecea416edb19c64681d1bb43fb5024e2f48d409", "242": "4da30e6198a3d9ae6a538c2366e08ee218de6efe2c5b8f231493e21489c21a7e", "243": "7404bb7881a010271831847e71162ee7a393843922ee93cf7cf3455a0074279c", "244": "21aa3213adeb0a562ec7161e1cfcb5f1701303f1c9f03ed726c536283e080db6", "245": "22b9cfa9ab97c84eb64e3478a43acd4d95b90cae8c3453c968457a89c6387a81", "246": "729e3de7687fc597be2eb4c592d697ff29c78cff6945c9690cfb1ee67550eeed", "247": "f49b98df95a1f826c24cf622ba4d80427a0e0767dffcc28a9206c58508863cca", "248": "44b8116c29dafbdfa984b3751c1dfd057b3e93fc57c8cd18495f1c0f605496bc", "249": "49e96b6ba41e88901dbd118139ef6f013b4fc59e2347058a7e726cf6a2f14067", "250": "f0e0dc05fb555ae5ba9820586bef3bb8a3a82905ece3d8a998a3015fc91c1c3e", "251": "8c1ece1b350c210380456da2bab70054f717731b0dfb34bc3cf4abfacf696f15", "252": "ad20a49374f9176bd26460d35f96f30d734df3cf6fc63b4642380b4e866848de", "253": "ba1a2bbccabbcddbf29ee0b56d0d56b4f026e8a7b97e97de2d48c133ccbdf2a1", "254": "381a2eac64a984a81671722bd95ca5b8b6508a6f490af46780e9f393c6797223", "255": "5e6ece13372bad4a6ea011c933389dfaefedad5860aefba2ab97fe5f59156c42", "256": "068d4a3c845803bf66a9e5320261a0fd7b6292a8230b271a6a83f0dc8c73e907", "257": "d80ac9215ffa7adacb22711cc88f5b580272d0d65c49e1ea48e69d17e264d91a", "258": "256c4d399703b7f16dadef9201efc0ef9f6aa6ee05ddfa2d3e26ff6efe09704d", "259": "275a4e84039a1596ac7e8bbe186163dcfb02bfa99c209653ff5d505a29b4cb10", "260": "f461ff2df66653be1a2e579b1aea515d4a84f2ae5ebea3aa21fb2477a53699f4", "261": "178ecd56cd79c7aaec1353093571ce89845130991d64c5a715a02da83a2705ab", "262": "2e0cb5e8fc8ef04c50a5b9ab9a9eecad446598ebc2527b19c447143e5ae09736", "263": "c870fd75ed0d5ed92ec35789c522d029f364328a16282a1c5eb9b3b7e121eff3", "264": "da5d6bdd89eacf70a88810935f80e4725da4feaf2aa86adb13985d7d9e1c247f", "265": "13f16351c3971c286fae5e9cfbaf6f0a128a6507804fd280971a600019e352e8", "266": "4f39cdd293598de9259231592e99bfc5fde82a0bc1820a4c5faeb54f96037f00", "267": "3e054d92034d3d32c3d4e7acadf1c09232e468fc2520d23d2c7d183ec0735aa3", "268": "2d47c47a2b19178cef9e4eba1a53dd39b5f8657bbe011a71c8d402d294d50132", "269": "4448f310ab9bff796ca70c7b7d0cd3b9c517f72744a8615112f65ba30a6d61f7", "270": "ce71f5bd1db540762e4bc6c4798d8b7f3d2b7068e91c300fd271a46298aea2aa", "271": "5a05e212b9b6ccf6092081f567aa73d27da399d45418f674628a8154f9182b6b", "272": "a326c2d7121d80861aaf110826615e560aa4efdec0cc9fdfce051c6b9038e781", "273": "d32b75411f407c5da6a9a6b4a3907b9a9ebbca6b651324c03432d549671bb837", "274": "b5740ac928d58f53537b05ecc80b7463dc1fd5a53400f57aa55573ecbd5faa56", "275": "e1c843ff0e97692a180e384c1a9c03c7de06ef92ccad5aa6157fabf0dbe5b804", "276": "2edf523574e0a062cacf21f51ed6f81128537f27a3cd27b84a8b5d2478d0092d", "277": "130c990ad499345b7638e57dce365442e2ab2d2571546aae60a9fa6ed3834b8d", "278": "2204d89df74e664621dfe8892277d50e7774f60613561d70ae06ee0eb4c483d4", "279": "4618456c7239784964b8fcd27155e01cf5417a16cdca7b163cc885d598ba93f4", "280": "4b2d9501483d450371ec4413519b0b3461502aabb970fb2b07766d0a3d3a3f85", "281": "b04a4a02fa0ae20b657dcfe3f80ef84fd446daa1521aabae006b61bb8fa5a7da", "282": "6dab2ee10b0dc8db525aeaa2f000f3bd35580ba91e71fe92bcd120ad83cf82c5", "283": "c964c01082a258f4c6bb66a983615686cb4ae363f4d25bd0bdad14cd628cfce8", "284": "df960dabff27b2404555d6b83aed7a58ef9a887104d85b6d5296f1c379b28494", "285": "087de77e5f379e7733505f196e483390596050c75dad56a999b1079ea89246ed", "286": "8f3e5fda508a37403238471d09494dde8c206beadfa0a71381bd8c6ac93abaf4", "287": "5d834d4c0ca68d0dca107ffe9dbaddac7fc038b0ad6ccc7ba3cfb53920236103", "288": "20a3ef9e411065c7265deff5e9b4d398cab6f71faa134353ccea35d2b279af04", "289": "9dda7eb623939f599551ad1d39dbf405211352ae4e65ddd87fe3e31899ca571b", "290": "a629c35ad526f4a6c0bb42f35f3e3fa1077c34e1898eac658775072730c40d6b", "291": "81b1e5196bec98afe72f4412cf907a2816515bad0680bd4062f2b2c715643088", "292": "614950a1cff05f4cf403f55393ed9d7807febbae49522ef83b97e0390038ae03", "293": "9e4067ac93c6febda554d724d453d78bf3e28a7742cdec57ee47c5c706fbe940", "294": "9ac900bf0fbb4c3c7e26986ac33698c46c6c3e8102ab75b40b8df94fc3a0c7a1", "295": "2fdcd631f3c68bef3c90f8679b7aef685fa33f20c2d6eb5965cd2a62267c2ffa", "296": "dfc947e61ea2138ebe47234ba503cf5246ecec530b12e363acb240822ddf0b34", "297": "4d5af88ba8a28b49a79773d3e6521e8731ff07d49765203b157481469e6ae6d0", "298": "94aa77eadafaad7327acb8e653888f00e114cca2fbe04691dabdafa2a0c8cd64", "299": "0f221ba58a8ea417e13847ef91af9ff029561ac18c74bbeeb3f5509af81a3b03", "300": "50a79fb6e417fb4a34e155a9af683aa9a74ee922a6c156a58bfedd22cf3185c4", "301": "eb09a0097a47e7a95b892ad7230475a1a28343b47db4faeb3e47f227aeb04738", "302": "fcf9736fe8c20a6d02f00e9b1e719de06aff4afa99d2eba166592aeff1b8f3b7", "303": "e6266f575c94d805a67fcd3f2391d0961b4b121b8a66afbfbae76dfc34e5c06b", "304": "189bd2a8daf5b638ede7c50035fcf426d125de87a401382f66ab75f35b2ac1f7", "305": "0ac58c6eb8513f4ffe911bf0f044e0153862ee89c04939fd9b294860a37ec9ce", "306": "335998d7e2a3fae2da75a5192d62c37dd006be96831fd37e7438ec6d84451c44", "307": "4f1f2695b1b6b1660f3ef6ac31a81630ca74da9368eafbfb214ec1980705c13c", "308": "bc5ae127f8690ba7f6e9ddad98a49137acb45abf4e187eaf3648f197c72fbe90", "309": "6b78ed4c4bfc942b9b5dc340961f19c690d56f9d721b6b764d1db31da53139db", "310": "0d183ec2ff1cbc768a9eb7eb06c2a354f6c8bab00e64ca2aed2da00825f33c05", "311": "3ae7fdad095eed78e0c63cfe4e28ab7ba2b977259590ed38722e9c44727e598b", "312": "329d107b5743a96e3551084832587a6346e410aa89641d83f03f1242a7244473", "313": "ecc63ee12cbe487e5390007271890b8aa5df2cf48b8e692404895d3c2af20758", "314": "5fa65495795c52818aea910c24e4d3176c71817f5268c34e1cb259b256737352", "315": "95bd03b9913be37d24809d30e7bfd31a1b7a127d03d65e52086857bb3a364b5d", "316": "ca6ec6c9159e10719cd8d2cfcfaf2fe2d3637fb3d497e2c80866de6b593632e6", "317": "5b0d72d34b406ce20714a59f1c4d5340c5559285e340497dbcad68729a9db786", "318": "3e2b479fafb86b8ab097588b8fa12ae8a078f8b5801e15c7faa1ef23d87a631b", "319": "e04b18947b36771937dea491f47b75fedf42a6db684035f5690e6c2bd7e6031e", "320": "e546e4a4c9020669c78a095aa5c5038242dd78e0f98517c0e23c43aefeb58138", "321": "3da0198df2f98a7306ee6d2e12b96ba9a6ad837a6c2d4f316d3cd8589b6af308", "322": "07e511e9002147c33739c924c17a61126d12823d143069535a615a97f86d936f", "323": "be514911dd6258f860c2773253f6df6c22ca975a10c4e34db5903269f2975faf", "324": "53ed94369b59a84d003ff3155edbf481a0eef362325539d6ab1a7f370ce919c8", "325": "43c8dc1907d3e1eb30deb565475ec1ad4f807baf6ef34178508ec85071722f0a", "326": "b08d72606988ea5a82e0caf15e68d81b4f2e8dbb4af6a22437916f3fc53e3dea", "327": "f70bb9cb351daf610a91a3c769d84bbb3f3b8f1169b10839196b65b8585e7c38", "328": "6e26ed661a0add2e583229066d304f7e765a0ea337b6a93bf979e4027b70b94e", "329": "89d8b56a1e05d90ccde0df482ff2fec3d44270739810f3c5d06856c38d801380", "330": "2dfac8e04d08dc5eefcbba4e475164103d339f844896a75ef3af2229185118f9", "331": "a20f9b06c126f4ee65e3f3a0bf345007b35ecb69d035dd0ad848e09300130fcb", "332": "6593d40f4e3f53a73191c704d388c7cd1639403da6e679c8e4169b26ade19f3f", "333": "7499bc84f6bd2211365fec34943d64f6be80a53ee2efb21c099c1c910ca29967", "334": "f24dd99fe5b46bb7a7a30c5eff61e71cab21e05f1b03132d7da9c943f65713f6", "335": "8e2111c24160d92b1b29dd010b8b3a0a4f9af55f1d30bd5892756c58ffaec201", "336": "eed2e8d970c1c5031220476e6b700d16e5065d7893a2766a53600825b4ad3ae5", "337": "44e298d1b55c51c9f127989da1149ccf6bda24c40041f777d35d5b8f192753d2", "338": "b3a60e80296f79cfdfc02354acc674162faefcb3fb78b9672254c9cfc6eb113f", "339": "2b55688ba27d72202632783186211ee24ea39c53915066578291fffd9db73128", "340": "15765221271275022a6ef57634d836b052ffbab6d7d5a6899992972143841e3c", "341": "f7340563f85e057709a2fcc71bd448fed8d6de6907d8ba5f91fefa2abffda6cf", "342": "f252eec230c2e92ed1fa04834bc0738b79597c3b0d2a66c787fdd520e63cb3d3", "343": "1d65c53a04f7eea94ebf76d797c0f79fe3d251bd33e5edc16c780715531b4345", "344": "86d3fb095439bddbc0d6e6e8e433d54aff04350e2da2ad05f53d607113075c8b", "345": "21db551743591f9cd20fffcedf3bda17f9f178bc9fbca528a56c2c61b9e7c731", "346": "f326e2241b7e57320914aa279f9ba2e155ea77f809a188958e0b590bea9c3ada", "347": "0fb6749b98280cc8c26950a2cb9c9dbecac18f8760e161e9bab887dcb0077653", "348": "0cdb77330ae73fbbd0f287240f82b7547a0ef42d37004003a9c759f86b686d61", "349": "690ad38e4357b34368966b9de08d89e0c095246bf55969842f373f1976f86062", "350": "5b427d47f98e296cb78875619fe67d42f41868b78886d560d8fcac89043fe945", "351": "93dcda27a0c12f0c32cc35f0de161e7f7792d11abe5d4c50d7fd5192ab8b11c0", "352": "d01c0cd49e7649289a1f13162757de494bb9104b20ac8bdb30a4180df5225889", "353": "3d856f38821d7b221aaaa9baa3d7927f6e360919e8f8505d7499f9bbd85c44b8", "354": "36dd3030dec4a8050d2079678250c9c6c86c66c64fdbe7f5b82e79024bb8d5a7", "355": "b0a915b700e415ba3acc3ef261128680b921b5df9bd6fb1d35c2d1180e7f61d7", "356": "a309814f13708f2eb5ee8dd1a3114e8f8b15646b8c797bc7119ceaa3f6911f0e", "357": "61c9c81a41fd294a8f07033c8373706694faab4df3652d310e84904356cf5e6c", "358": "7d59500b8883d81040173b88462a73849e0d386a53830d599e6a042f4c1c165f", "359": "0793805920db4896155cbce40fb58570a3cc952d0c15ee57393fa3c6ca7a8222", "360": "ee8cacd40fb7515e510cbbe7deb6005369ce7d9800ecff897f3fd8721fd6ef71", "361": "e96f225fa470174b4ac787b21579ad1556804de85c0c83da99a92ddc2c56c7ac", "362": "9a4ce079c1a882a306e21e0c145dab75a2698cba3860152f03dafc802ad9006e", "363": "258a6e6ea10385ca3c0cf08377d13ef31135bd9479d5a4983beadf158e19ccc6", "364": "13aefde214541fab44d2a3013c532637a3da82199fb6c0a1a941c3108f76b9cf", "365": "0cd978902035027c6898d6b5fc11fb5931f06f8e8ec9c24b4706143c91de9450", "366": "47495a92574a6d7b150eb3f4338748ba03672ff93162139f98e03847f96551cb", "367": "fad9203cd26fccb99f0f89fdc569c230eda46cd72ed3fb7e5f6fbcce78ced1a9", "368": "a237e13fa6c32b66695b8c8de6472d5c93c7650989f047f62a17438c07036845", "369": "da4c450ba0c4f76556fce54bc3f6b2a754a626cf1f87ba3280f545e023942640", "370": "5000899cd3070e1937d42a68766c840bdb9629a49c6112bea5cff52fdb4e9f7a", "371": "7afb55ee21c0447f7b961265abe7ccf87f59af6206949bb1da19fd36334b09df", "372": "fcf734716ed1fa724e7228a489304e3c55e813734fb5792a83f806ab04e40485", "373": "83c98f0431cf944440dfe0a9831275ed451b0d16856aba4100f53170c55c2e6c", "374": "d998ea6616a5a7a9f7beb3ec02f8cbed4a9c5f17be978c31f32ac0f9f4e4460d", "375": "6a72aba5c61e27e281235b1f001ab68b840f6e8bef0e6bbd7bfd8eec1abf844e", "376": "980dce9435a9fc03250df4e809c2f68c48601b64c30d32c6e67bf1faa35fe274", "377": "7b4a0b6958cf23951636b5e27af8041dd9901256c53de44c9be313ffd0a01ea0", "378": "a1b13bda78da3ccab1af6c330d3e768fce62841f924933285e7b1f7a8b7dcd5f", "379": "c957fcbb90e1afe9a342e95608ca035596a7dfd4cef398ada55e05a2462aba14", "380": "b794fae83475a77832f46e69799419f9881bd774e1bfda56773b587c42591039", "381": "e7208f3630a20b01a5e1bf5d0537be9dae9fd7529773cac12b96c4ac2b0f8dbf", "382": "70480c0d26a6d76eba0faf3ee047d6214b2ca4d1442070ae5e79893192ffa699", "383": "3c814d251089cb2a92a78ec3424b2a729cfbbfc6a996fd48148261312364a9a8", "384": "f709015ae0f8ad20bd2efd94d01af3858234e381942b5b15391ff7f77211b116", "385": "0bca6cad1f4ff336b93c9f86c4ac872bda67ee0cd41b1862a7a663852717535d", "386": "3e1748647b60bbf292aacae65b3608ccce8e55e203a36ff062ee787cd8c14480", "387": "cf592fa81780e727a56553df32410beba6de9c33543dd1ef1155b368ba9a9b9f", "388": "911326fcfb0638154f69eabb87e4c0c141df09e56274c8522e9c13b7b577f00f", "389": "cdd56fb06838a10149f2c7229bbc76f78b4a5a58945fb70a47261f1bf635c404", "390": "07dde4848eb878808635fb7b366261b1e9cb158635e76577eecc48ccf941323f", "391": "76cd3def1eea8e2631d333798f4d282bf40f6254b2d18c02c78cb56b33462093", "392": "c4f7ecf21a8738c3ad0114a1ee6a2d16668e71b499741381f30827ed451dc817", "393": "7bbc419f89fde57d2862bfb3678ddab96614693dfca109d0f444e4762a2b7a8f", "394": "7781ca3332d6da18b1b9be5e2eff634b526ae9e8088f6e479b49d657f4f41525", "395": "5b5de0def2c4a989a54ae3e748362c78cd018778d5adc4dec13c1bde6ffdc139", "396": "d42c389d6abc7d8102b8cd1b906e4600da08394388d4dcd432ec955e6d8b311d", "397": "629e23dc358ed2a8c202e1b870e270e401aecc5d726a679b542df8e6becb4200", "398": "c30114e73097c3fa4efb203915f3b828b1b8c432ddeab2b7e1ba3fe63c50e190", "399": "a681ef7bdb22145a3e051ecf7bfb694c18b255c80dae6fb8d49f187d28f3c58f", "400": "c993a792804e09c9f60313f4144953eec072ca6a8a27f44d8718ce53d9429585", "401": "074b576ae2054cd030ffcfa132b1465f8f49b836f505cd4bb01af4a98f4f5337", "402": "d45f88fc3c00673ef7e628d867a54a4ea281b3b2620735cea85a8da3b06321df", "403": "a09086d3cdab7d6ff8a9fba1746c5d236e0ad0abe088be99bb172e80c6f0f8f3", "404": "55a774ac3423440dda50d73e472887195940d5e9df605b30deeb0f2528b001a4", "405": "ee9fa61ae8153df7979be3afe6377e584fbdad624833424a5cff64f6ea94c9da", "406": "584cba4abd5711b8f558fde97620b8ff0fe91586bad052ccff87c49c13f72555", "407": "ac50b37409f7ea91f90856bbfa716731013deffb5f5b51540a99736e08e5378e", "408": "2c12c3cf062c3d9cf2c53e6e4dafce70ca5c7a38c97479c3b013cd91076ecf4a", "409": "5a55b5fb584c359f4b6ee2d21deb62923b0b25e1b4c3da0a6f351079ce657173", "410": "9e224b6ab0b7f20759b63d1799b426a8652c9e637b1f38d3eaf8beff73c80c67", "411": "66c0c1ab79e9887b5daf2c510f2c2c4097044b69fee6bd4ffcff73ad4816b8c7", "412": "27f1768d99e22f8b55d010b8b7acd904e8b66751d5310d32c4d017a0ad34d650", "413": "7c99634a1161e424a14d60b516291655096eb90ed055326325d7f5de7a44a3e7", "414": "4e03e038e99870b1faf45a0a29d6124379d05a0a3553a11aaaa91b8ba56eac5f", "415": "955e433ea745016af2a5df015f1cc223ddd84ddccaee60d5302b7ad61542d9e1", "416": "8d07a87b9012a166f5bec4dcd646d5957c9b3633a1a37c40c584ede75cb7ad22", "417": "3f738338cef45597e3b839536953104186f11d94d16877c77abd8a067c152dc3", "418": "0c813356b30108f89fb37e8774a98af4f9eca3df49e963f985ecea82a88b1437", "419": "8ea8d93a9e874f8c8ceeb240f1f1245a077a7c0a62287d3044feaf855b5dae78", "420": "af7ac1e90e07f189afbb284ae24614d9e713e32098bc39bb81d6484d47351444", "421": "f45e155846624f37cf2ee08be2a63cb1ca35bf795fb0f770b4c91ab549f22b25", "422": "69d728f7e25055dbebd41684bc6de61be6b4db4119d7ecdcef5b5d8ead976537", "423": "3e78c62395be704a59a3a6a65e457725105619e0a6f9f3aa6b311c4f7762b0a0", "424": "fbd6edb36c3754a35e7de936839c4fd0564db873924ba97b35cd43e065835582", "425": "ee5bb631b2a9edf8ed05781b192f42e24ae748f3aa4ba5e635374c094d28ddac", "426": "3e913e088a689d2d33bc797040cea94512bf54a61f96501f60576ab22ed0304b", "427": "415e6da4c7f92da36e2d8c43fa8056d0050ae127e648451e2fada49bf2c936d1", "428": "389bded7b0c14212fb69b559fd1ade4f5b235b976c9655365c45481c3afda486", "429": "3007beefa50c509b89b86c54f53757ff701f795dc5f7ed47a1520c2b092455f7", "430": "59ec8ec2866ca502ad558ade9f8a06a9ff815a1ed649bd1cb513f417f1d4727c", "431": "d3f28dffa4e22b3bed74c3c2c9ded1e4a8be49d3757368e4e3efaf7f79affb15", "432": "59fd80dbc8eb4af9596e4ce8a87313d363da41313351a69ab3525faeb905c27e", "433": "471a7ddde597fbaaaed1941f42ca1fc0f4f047e17f2197f8999dea98b38213f3", "434": "319cb430c66d9f418aa90a3d6f9c2dfc8171383d6f4af5803a73684afcf18e15", "435": "aa29c0119ca84133617c8bc7455afdfcf5b05a569393ff21ebcb10d32ffde2c8", "436": "928f772ad7a9fc501f71cdef6dfe60e2d8cb5d5c5800b519d01afeae0681dd08", "437": "ea70162a014b8294ede65af6fcdc11fb365ab2b126aef8d47983d58816fd6a54", "438": "43633662392854b5d9f9f0fa564605212d016c9ea9377d2a6ab52137238d4191", "439": "42f7e88fab5c9cb31d4bb34403d7958abd5023e9cf9ac05cd29626c5df763584", "440": "cd08ef4f14b804e3106ee88f9d2b24864d5e2fec6c7cd7dddfa2713e1431375a", "441": "daa69bac44ce5f57b4b43ab6ece3b2b3561292c0f4c6e82a506ce2973713f749", "442": "910d2abf184cfd7b1964cec906a79f3e45f59e3d42ec20b22f56de59c9018927", "443": "7a14ac86724d318e6d40464e710c17625d441d1e7adf83d3062305de2f85d445", "444": "390877dded07897360921e8d0d126bf45d6a379d47292c90826d775bd1897f2f", "445": "5ee5723341b0b81c9e0172fcb654f8b24322244bc2d1b55afcb78b180ada180b", "446": "8b2dcb0168e8701dc9da286489a1e68e43e1b17638e5990edd882196d7fd5a29", "447": "179af1c75faa5f42e89ce3b41496a64b2d2846361f76dd5d87f4ce97ec2bec07", "448": "18173b14e0c0bf403b5f0d4aa23515ecf44622b3a860d80e866cd498f107123c", "449": "22d7739bccf54ea1159ce6aca3e215482deba85a4db0676cf86d82a760c44a6c", "450": "938bf7cdedab94bd7208b69047014e3d9ab7b54d1223bd649eb3de0bd61ab47e", "451": "abd88e378f54b649e818d6e1d8e06c9f8cf225ac96b4085523acbb1f0c1df24b", "452": "4119701c51dd8c457b74a19ed7ae3bdf069f5fd915c8085e9a15d909a39db036", "453": "381ba093e8ece9e14efc965ee94bb8adbd1c0bf140875ef95f8f11050d5ed489", "454": "b7613128b0401fdbc07a4015eb3935f6677b84dff936fc5e7e9f424d0ba1006e", "455": "35ee11c9763f48a68f2b60b4b9c3919d3a895afc7071e8dcac5abd5845dfe79f", "456": "8b129a3c7163dae86f1f43c18557296240a02bdac70ad29538eb5dce00e51f4d", "457": "629c99f9af0e962f00b812057c0967861a9b6db9dd652233ac4b37f368d09206", "458": "02df8a1d11130bde8af932dfc5cafe7d8e6c2fc12b82df5d222a91e4eed8e2f8", "459": "062b225facc7a897e0e42e6b0f95deeb8b02de64267bf5cea4cb5280ccec1562", "460": "a05f9a7cb049c40760ea2196eb41df1826ad492e6e5fc4696ce7bfcf7a842811", "461": "95e5e99da04c0cd73e1818a62be3fc0de98c76d5cbdc81261672824ed5b8c1a7", "462": "69eafed1b3d4022fc245a8416c1120bdcd039716db8cd43351a96e6c7d10691d", "463": "018efbd353bb456112cf2c760b4d96aef02aa899ef74d4aadfb3dcf374a22987", "464": "cd4447e836cdbed7f6a3998b50c4ab467aedaeb8e54c377da34245e90fddbe12", "465": "da0612471988c89ea2fb190838f9f5e9029fd106330a801e66280c967ff1c52b", "466": "8d16100c0148ed7bd41003b4a0612cbc5fa150ddabe5f9916ed6eac3fcfdefa4", "467": "d6ea164cb91d14d6aba2d482926cb6cbd1a3644737a0530abac635083a97b8a4", "468": "8d0e3f6bff322ff11d1267f1f8303a8ce1e2d796b7dc2d9eb3e3da939dd850b5", "469": "35e2072f22c7cb980fbe797e30c25e9224328813eb81d07d3c88820492ce9a1f", "470": "4993f275946ae0d444410821faa3ef4a448f10888c50ff59f7ae01d0b50328d9", "471": "b9af9323a0237fbf88fdb14b8bce95c084351325249629ffd4fbb32fe9d6da5d", "472": "5b278c08ab97d82c1779411fb1018b07feac7ddf38a69e4d398240a495c54271", "473": "4448b03417a784f554c44eb15ad2d4cc022bd9cb5abe2547811eb8085355aaaa", "474": "1c64fc4076d6b00aff86a180fd9af927b7c1c9ba87a2ca3c83dd80ba5e5ea973", "475": "e571b4b8218a2961ed2b04f62f816eb18686d82b7f2693694b9c774acef4a0ff", "476": "a6383ed918d7851ed7503921a64201a032a33c9e1cbd4e08d1233f543bd21be9", "477": "c871da03e684e099190c4ce787a9588ae85841246ad7bcc9cb4c302d617f881d", "478": "96d8bec6b787a7aea2da8dfa8a1226e00881afc218c211fc59da830775d55acb", "479": "b35720df96afbd98c6a4f081ae1173fdce21d63f75f7b455f4c2b9fc0aa672c2", "480": "2db876e9625c8638c66103ad0206c9a51b68d4c6a3222f403b195a81837856e3", "481": "bac35824e79af403a2058b08cbc84f8e4df93a21d1766e4ea1de6414e2a8a926", "482": "0f9797e2f3691bc7291d81d1ddd5d88cb4e10b0be555e2ebfbd3c5b12b7cd2b2", "483": "8f3348df383ec9ee00e18d41c419370d42ca6ebf71c510690aa5435a679b7e4f", "484": "3b3bac32669c5b66faaa42b89a2dcb4de0bb9aa0bd279d60061dbe9e7039f5dc", "485": "25d0335a0576f974617351ef5aec889f311fc8d7cddb997862b10b2496842d4d", "486": "93b9a59a937594d2196271416ea3b2221d32b3b40a04bbebbdf97e8bdc557e0a", "487": "a643c75a8d062b87a1c8635fdf439c04d949ce01f75dde10ab6edba90cbaee77", "488": "984593c12abbff5d009091cd3c1883c87efc535f760727ed12f06df0902bfa75", "489": "926ac61244f94e10270a2d40169de025be6db342b3de7f0db33a50b07176c143", "490": "e2c8142e501b0b0b808d2d36f5f38266f99cd3aaca7d2f70f4bba386ae1d2025", "491": "1a1c8b472424f8057c94a9f5e0c0b673551fbe9ea4cde5ca2d90df1de76a5c76", "492": "345a83966ead821efa2a9de93aeb0fd5bd60a8f50e162caae2447f1f4d9462bd", "493": "ee7018d63b08bc7226d6f77c2345a87e09fc7cc87b0a003aaf3a4a3f622edffd", "494": "3d69e540997d79f21f249d4d8f73cd75119d81bcfb8bd80782863249f0d7c62c", "495": "b717f1088b0ce24851c30d54bc8dad9f3ae93402b91c874e385e5c699323a5e2", "496": "fbe77ec1978ad86e73e5a3f494fa7c198fe334b511298f5a0f2d04d6a7f51d01", "497": "a4a66d6c7c555a2997ca59a8dbab512388adf20902293a5617132a16df76d954", "498": "d71813b8175fa2d70181d87ae8f839e79792516a1cfa99a7e6b29500c057617f", "499": "477d5b817df8c0b6f0928d02a58fc39fde2224493cec89393bd6dc349e5235bf", "500": "3ac8e26d4864c538936efa7c5920435107a50c01306adaee5a4aeaa2ef378f7d", "501": "766448b05b248ac3d6e991baa3e4b2d53b02aac426bda312c2299b2b983e145e", "502": "50218b55f5b7207438137f2b0c71e3f6d37afd76aa5b1f2106111f3432b4cef8", "503": "1d7c24799a287d42e97dd4ccc5bbd3713ce139e6294896cc5fe2efb80a1be7ad", "504": "9878db5eb2218b18568dc8cfa13bc8363a1c93e6a59a05cc76da0588fd54af46", "505": "872fc20275833f09c8aaef277abfe77f67be6bd443b489e0cb8bdf9d4ca9fac7", "506": "d66834cc7ebe58cce2ee1c02bb11ae69672d711ead6a0a58ab592339cddbf02e", "507": "ae955394665befbbc89e2ba85b5e520cb293b8d03209b1f71d78ce2cc807a437", "508": "3917ce4173af47bfaf8525f0917736bde3f4bee0ed5fae721c3e2fa957ab1675", "509": "2f64571cd71f0e59006da84808abf3d3ccff9a38884321533d448b3e8e3cae05", "510": "41ce72f4701e786427413b68fb70bd77d921c06648ca15033ce1926a9f1224cb", "511": "c9fc787389265492e60d5503f279714d5b19760ea7b2e1a720e6fc0251fe087c", "512": "a8af6acf3744af13cde63540e37bb9bc722ea19a012656e3a3c5bfff8292c423", "513": "506b90816555d1083be7d211f02a5db364e5c2337fc85b1ba845c1a806689373", "514": "e4e9536766181eda627721723bfbdbca85859a3ba92d439f58ac0009c102430c", "515": "16daaa62fa87776bc4843d226988cc83ee846ceef7b885ab63e10789b30071ae", "516": "44b6de4eb51dd8f762142f284b154d3153592549cdea3b94467fa95484a4f172", "517": "bb72c6d437197a8c1f1132626b3b47adb9827f4f9b912d1069cfcc75575371b5", "518": "ff57c1f518651af805bb4b258130c7c5b0726422c3390327217562088785b4ba", "519": "159b59f1261b7a31d7172cdc28d9515d0731e5117cb30f34a497bc3bd0496da2", "520": "bdfb7f17c8c841c0b61ee7f00e51f09e4c78c90f7977548b72050a7aa12dfa3f", "521": "bd27ca9292c19160cbb0568f750b247fbb805b85f4a2316fcf2c3a35d3ae031d", "522": "98e0ef155297aac8a4060d204614753f26f6ba5357deb78c683783dc7ae30191", "523": "9bfc344c80d1200fe12bea3ba4cacf8d5ac9693258962f2f15f42b30ce8ef3ef", "524": "8df22d8716d7ca6354ea42b8e522d286ff9362cfa5881f527efcf1a953ed1151", "525": "13dc6d869fbe2c3d95f715e55f02bc3d5787874b4c88d7da1d05360afd2025fa", "526": "dfbe442040ce9afba654773fb14f307d67ab614267d3feb6b18df03182b5b60f", "527": "ba634833af68fcf0ca7bcb08fa699b2c5fab934eb81ecd85e7464b01bca131ca", "528": "016f7b569dc1c3466c97754c7dcc0f76c2a32a76c22357cc521bcc330d86daf5", "529": "4960ff863e3d21a58f9e81c3d94075cb7a4daea5fcf396812382111e462fc57f", "530": "6a2e45fdfcad65e0ee84d206d59cbac998026d7415d16a5c0b8c55e4a7d6bb3f", "531": "95ec72fa8c409255d43e7c8d4e957bcb9239534973187b3b4cc2557b09bdba98", "532": "fee6802490757983c499a08831d9bdc75a9eff08700bd29e8e5c134583ee07b3", "533": "8a056666bd75d853a12d22b8317042a3f5500cfb21f6698d90ab41e01edcf81d", "534": "8f65c9feb935e09a04c87143d1b2c63e38f08738199ebcc2758f67ee914d8a48", "535": "ed8970f8ef1e2374289fc735aedff90b010c311a3b80d16df6bca2d3c250fdeb", "536": "f82635851b442ec0ee95c5c2b7377ba382aa364cc49ff4e981d509ef324bb356", "537": "54fc97bb6f3d7c724d4e245df37111c20334972300297fe38b590354fb9dfe92", "538": "650c7f5f382c295cf6e7fb092db6fdfff164c861bcfcfe1fb38a50268f53f50a", "539": "0bfb3df290912d8a70dc5e1e2761151cdf2c4b75d4b37c8fdcbed7483ada85fd", "540": "08f1b2bffa88a9d01eecb8c9da6636b5e668a5478d8876a63ec3a74d7f932205", "541": "5e59cf440336e86b67c17ed61f7bee7e548c434f475c415294b3b652d1aec606", "542": "1257b6a3ad900df97f5aabc1e18b9f7ddae8c7d7ad60216ae21b5b7310cbda84", "543": "8a783bfbe11c7f7b24431a15a0eb582f6fe5f75d1d21a3d55f8d8d81ba6b411c", "544": "ce93bedef94ffbf62ad449cb0c68e8103a0bd005563ab854daa5e470664b4d7b", "545": "40c253003d601fd2c90908bffcd8133e77489fe247e74ec03901895318fe69de", "546": "d40739115f18fee96817266232ff1b8845e7966778fdcc644028fe5c759469be", "547": "fa32a8de8fdcfc551d808c5dd0ff5545a199027acd32e380959b91f3b3d04643", "548": "72e66168068b6ffcd2988e24124c8b1dba9a5b52a383a937397575e3c1e3f031", "549": "a23baaa745a976b4f212836beb81a0a7b42d9f2e923c2412e2c07c63ff660ceb", "550": "f58ff320639b2c47c76ed8aba487e31da0fd4656c3be6e33807cd00f77456e5d", "551": "0449ec4d6d5b2e88603e62f3ec0287ed711cff682bbdfe298a197144ab24e80b", "552": "f125761e8a0d02b17b1dc4be40216f2791727fd4e4bc56f60ebea1925c2fbf36", "553": "dbb93b2a6cbf972bb1f94d1f8656cd113a09a02cbc44f25737e7d75c986646e1", "554": "dcfd1e7a4a32ff0fae296b8211b5c9e91ab81844a0308933f598c712c1bc313d", "555": "cebbca914f917f990202f110e77285132d2a5a3ba9a7475c93e3561d8ba88ea0", "556": "0d5518ef165979b758fcc8df9c8cf536861f376f8640541ba6112ee7610ed82e", "557": "0547c86b57c7c8c590f6d7a5131778f5b6ab2eeccc5e819e5fd095a6d4e68b08", "558": "e763aa1dd494e097251484381ddb057c7d79b739c3f8644b1759e786e12f5b40", "559": "e48eea4c3b4c9d58fe02739accf31bb64dd9c31623ad4cc06c740463d664c098", "560": "77a09dc1ea6f1ae669004b8c9429dd83ead1148c62e0d945173edac45d9000a4", "561": "756d226727e611d4bd22aa33747da2f635eeec070906dbc3262ef29e341e2a6d", "562": "29de450d6e440c528287b98bcb4b76fb5155ab573df4721467446114661936ed", "563": "7703d943dbbfdccb90acad65ed7c0eb13a10034ad01809472a55eb3162b7e53b", "564": "65712c105411e6fc0ed35b9347de8cbaea33b0c5e57cf162f48dc257dd4f05b5", "565": "2945ef4779089c9e49a9a9f5e2a67ba7e393aa20a955ed9302da6677cb03a9cd", "566": "95d936e1d454df2e1e7d486c43af387b39a50cb57e57c7712d967bc9ec556f41", "567": "2abe8af9ee20c6b8ad5034bc31fc1f4f16769595d5b4fc2837db3e76a90ac405", "568": "fdc104338866e50ae2bffc1ea19719136f639df6c25f38a8680a70e9375a9378", "569": "25677266de2b900788dfa047cb53f5585c37b564b3a711243fad52e186ec184a", "570": "9101edb48d98c3742ceb713de591d261b79e90481d28f83f2d2c74d7034f4b46", "571": "c364dde8cce2080d073eb1f9666cca97ccdeba61b2bf19ca0c84987e6f8d3576", "572": "9cc3049e9464376b95fb88d6fff4331e0e40196f92a0a9aa1c5d10dfe33079f7", "573": "2ade73491e183608b340f312d08cfd39c10ecb581c87b873443590452580a43e", "574": "96325b210d18a7a1d6873e00a859648c4754bd4c91c324aa812ed78bd047118b", "575": "33942a261a9150e2b5ce2ffe5b934a81f3972cf5aa5a9414a9d5f63f6b55324b", "576": "7fca01a835681914b5fe5014d5649b5170faf459375ccc2bf9ad71ebaa73940c", "577": "2bdc7a0e8adacf885c6ea0f6534b935b8a9dd338c5dcff05a74c162c3e9dd531", "578": "ce6b6de1d907c8839b84f5f3967f6af7e9a3644a0bd7dffe80cfe531de08f8ca", "579": "03dbff2575902a3c56a64483c8e8ca38d9888f72c6a71a6236eb07b808fb24ab", "580": "96892003c30358ed55a39e13e6159fad09ebc3916e34492b91d63832fa86f731", "581": "4fc5533c52133e54f8b54dcbfc4555638ae809676dbfec9d1400ab032f30648d", "582": "7ba9b154acf699c8a123df5471fd40ad556cf6fc630136c686c87b09c88ff546", "583": "ec10ea6801eadac9ae8ead5f222e0580f419b67d2ad5cd5c8ac914dcf5cfd69f", "584": "510001c4104c80517a13f967df6ee071f15fb7b65e97229bc91b2925cbe4e93e", "585": "ced737da53940337c5dff81720024fbaf4cee38aed1d3514d2a75c7b1271acf8", "586": "9ab074d1d480d718930c9abac8b616a0bc5c30846381d6d9bce1741e9bca1991", "587": "ec3fdcd8136188e3b476270894351cdc05dc44a4df50d1c4ed727294fb89430f", "588": "31400607f95129fcc531604b7b0478a748d2495746280dc07ff30e39cd6f4a97", "589": "3051de9b2a7ced941140aa1074952029f532e133beb41c18bfd990f43bfbd9ae", "590": "4af295f83800334d77a04d56be7524ff6241e3d8b2f23820c9c54580b7996086", "591": "2ecf2c1ab8d9e5cef5224842732af17bd2259598e4363e1d46cb172dccc39022", "592": "2e71a26370d45781f31ede0c7810c2705706ce63291a52d5cd6f060ae16aeb01", "593": "423867f77b64f725f823204796301ae09b427190cdbb62d472bc1395507da9a2", "594": "6c28830e35913c59000dfce4432db255f7dd34809285881f05a9e9749f5d8452", "595": "53fc00ae32e0b0d701175ac17ac0b91e05859ae6d7f3e5bf0548dad36e3d68f9", "596": "9ccbee33387383d458e7ffa2c9c0cb9e4f5bbe3d1b949463a98232ae67d29956", "597": "921102754e24e8ba99480e77652d88764020202e6dcd67adddbb1660204e8e78", "598": "430f975f490ce37df74bc346556cb2186f7a47a58d3b282ab42f35b33a812f7c", "599": "b603988248769444a1566b058ef3660cac528086b8193efd6d0be4080b834780", "600": "dd539cd38fade63aa0d14899c7c75ff459ab839148b15b4efacd4bdfa0408dae", "601": "571c5ade4cd89b460b7d2568a44d1efb05e2927ec840d8ecf149dc9e0ff09734", "602": "edef32d6c2c7193b4b30a0e2c7d3ab37e0ec21db62543f4bf78169b683792e41", "603": "cce7491b7ddf0e3ebde191e0e57614e61602cfaa2b52be5c2d657d9ae5e1f1b1", "604": "d08fe0e5c0fc10640043f9d645446e23fa8efbfdf29c93c87794e5b6405ff51e", "605": "1bdd74af73e2434db6149fd8089bd294defe3cedfaaf92f532568ddc6c48e2ea", "606": "30e44b49f18048323d1c1bf4631587df8f0dbd477ebc79b7ef860a792953d932", "607": "2d9b6a1b4810a39471e5dae85eadf595fc108097eeda746c8925a7be057464de", "608": "cd3fdc5ee5b6e606349b9e5775d6e632e0424d6190f632632bd7435d5622b20d", "609": "8b86933e27e64e6840bedc8087fa31326d9527a424c63ecc61823894c81f867d", "610": "a781fd7cb6970e8f6f679296be5bb0fe7ea62207caa7ce86635257186a5a70d9", "611": "4a3a0b9877d68deb8d7db624ec2d7f4b1c467fe337f803a220292ac6131acc05", "612": "6e95bb170c3a521fc7befa446cad879a36b7b3d0e0e8eab1df6ddbd753156ab7", "613": "afe8c7002c5e15859be829b4b69f0da00c1298971d5afa469b050016fc021978", "614": "f85495a58ad9d5c4d16167084bbc3581ea22e6dfc39423b70d7fe486e316d951", "615": "8da9fc3356df220081c71ccfc9c67251e6dd7058fb11258ecfc88ea9b8c00c92", "616": "0fadf4975e2c27aae12447e080505d604258102f61c8667a5c2594ee033567e8", "617": "06d9e8723de7ffd20129f1d8b5993926a97cad1261dc0cf01a37d8fa728ee996", "618": "04d0dc62694f26c61871d8129259540884ad2296a3cf455f6b92fc911f98c336", "619": "a93d0ec83cbbd4ec0866c97b372e4374a9d6724cc3767f5230e8316734cbb0eb", "620": "071da5dc1dd87c2558b45247c29a92092bc5a00ef3cd46d70d08e18b791d2926", "621": "458ca388a6b74c57ae13d1233984d5b66abb1f18dbfa12aa14ba868a9b5a708d", "622": "1ad0227dc5f8c259ada5120d9db05ac7a013bd1bd84cbbca2f0ae6b174dac129", "623": "d82d0401e10767b022417dbb64d348bc6c03ed4bb7e4553493e8d9e65525d229", "624": "1d25005c86a9635d3483ea63ce95fa097f95792ebab86319c12bc66ea1d2ac83", "625": "3fc397ed884cabc16bf30bb7487c8211424a08279a166d4fa4da6dc151a02cd1", "626": "7c42e09e504cb269512dae989ee7fffe1f3bfea499c990e8edea796761331ccb", "627": "5062b75aa39c974a579b0a3360c4da32e481d2242de72106f651c7d7de631cf1", "628": "dc656eef13928f18d14a9265be6a923bc7d76048b861cdf1523e397801a8ef52", "629": "9eefedc5b5995658be337f48146e37020db4ed3bb61e2af1fc57f698bd398b0d", "630": "6e17ecc4a4d07ffbd67c49a59d31b7efeabd3bfead49fdf1ec005836e6030ebf", "631": "781372694518c122f62566aec8867772e492fefef32c00e24b5604297dc1d44c", "632": "c978055ae1d71dfdfd8bb4e845bb82fc4211b14560bf6001edefa4367e1d4403", "633": "af4ff4b546369974642b3f68d4d3e90f0a0496b3b5d1572b638378fb49c7b4fa", "634": "f6af89331ee087a2fc03e0bddd738e2716b49ed616ceb3b47743cf3806c6d8c2", "635": "e4251ea6989571d8b83993560b537b7a9d0777ba54e6941757580cbfc14aab5f", "636": "dc15b5ccabd8fd3141c244b7dbc6fe95078299ea3ce3016cbb483893fcdd4236", "637": "053571be83ed06ab23a96d4e8fa129a4ce7e740de17dc35b000fb56c35a5ab80", "638": "df57e1f418a24e38b39011048084c6b5cc91a56c1deb643ab605e0350f329b4b", "639": "56930902baea90d1a8e505a227e5d7ac4da6b60f6c370ab75a0011cb3746818f", "640": "c105d171242fa8e35f26491ba2f932d1577dfab2a4a6e75034ae69f062e8aa71", "641": "0f6c3873a87ce630accf7f3b19feb764aac3fa0c3933042a817a82e6a9963aea", "642": "c20081830b70a00d1bcc6f4b6572d511d534986c10ea3c057db304a1f26df2da", "643": "143de023a92c7c8ce5fc0b839644e897267c44c8ba4e715743dc99686415a8b5", "644": "7a8c9f1db1b1bce9a3b8d91e5b1a39a92a478029d975f5e45d593b7ca81a7134", "645": "932a51e4c0cc5e30041ca5db1fd0674820638563a9df1300bece7df12c23017e", "646": "a49cbd2966ea8248816b0a53b6eedea4aef2525aac45272b862d7d52e604625a", "647": "40ad98735f3b5417ea1916f6146b69b7659963263caed186abf0790de0d9dae9", "648": "53b288529a83c376f2399e986e5ca25c5993a6640063386fdb2de491afba2e81", "649": "c0bebda0473186148087feb9828a418ab8d50726a1ff5c39ec69c4a6232c6b67", "650": "98ac68d2bc42f89dbe97b3392ac691ed6c2c4f36a44665555bf7f816ca97cd27", "651": "81f8287532f504b4f4a21e6d6ed573845bff197c479fb52e4c5b6f2fc1cfc40f", "652": "fa32d8e7c1c766a6126b0f1cdd9d752cad55f54d0c05839e89d4da238615d9ed", "653": "311cec39a42837f803ce8cfa5e6df32cc27fe541de108e3e7cf7ba3242e414ee", "654": "f2b3d205c2da66cdf9a596e2caa1098132b832758eea2b14da071b8dd9584ec9", "655": "39517ea688972769cccd46ad15b4f06ac2a6175d053dc97f849fa11a63a163e8", "656": "2a21e5e89d9b019c1195c50af7c6e1864cbab05068d10e11519fb6d4766ceae5", "657": "bbf54db41dc18753a3caa5001aae99c0c998e8a07b6e7390932054d7882498e3", "658": "ca8e7b53b095939e5fafefa56e9b45b40c396145acf2a767f9f2430fbba75a79", "659": "3d6c8492fbfe1c76e3f9d66485a7447489b89763623127deb6ed327a0c2a011b", "660": "23d754ebe35981ad5de850f66bb2294a22280a8ad0b4160b1c29dfb5487505d9", "661": "fd7eaca9690ee0384770e855ed600c96080c5c23565bfdae01c6045a87d9550a", "662": "b93bc0a52860ee0a1fdc28adeca7b39288b1119e0f318467f0a193236e00f99c", "663": "f73e3335b21c11b78987deb5a6eace1cef327981322f53a070adfbe31b56e7d0", "664": "f3f0de955603850bd411690d11a5391e63f515a29e31e9241c66c62d688bcf72", "665": "f2650e75f39098e5a114077b6e07bc15325adce22e1ab4b20569a4eeda5c6ca6", "666": "a01a34d1c29aff5618a96046605adb74fa49b834975051d4ac82672567727a21", "667": "2db51646a4038b38c88512738f79bb21776d39c7bfa3086538cccba0b63024db", "668": "2f3336b7f1211fcc180cd76dc6442fecb412771aa45ef1a7675aa437d04e582b", "669": "28bf022d827392eff1ec8ec121767ec24778f1b69da8605b4ab059023b8ad28a", "670": "38db5dbb2a3ce2d31d1958f5b3ca4c3555eb0ac4193ebffa3f42ffd6bb4806e3", "671": "0580cf2ef8abd3afbf91fba2032c2d51e43306bebb7f979bb750c3d7bd14c961", "672": "394f1b74ccfac5a4fa958d813b5932371c5f8c2f3dbd1eb7202af2223aa08afb", "673": "61c90400cd197b8ea6d7de90fcd1af0959fc37625fe163363fdae0ac4a724bfd", "674": "6037c38f696b10fb531c26396890cd3b48d5408c5b37e61d03a72ae2f7b64ed6", "675": "39c8b1bd1d534381b811bd8050e54b753106c1bfaf5d3cc63d8fe92a94471915", "676": "346d1e2de9915fa2f4ce3675ccebadccb8e9d14239f1e53b6d08d09f5c26297d", "677": "36841bba8f77d669e9d8f4e09ec580ce2c7a36c37da719815e65cc641eb1fdeb", "678": "09532ddbaffb710f02964e270f8658bd8a09149744726a82f618708b35a5fa26", "679": "774f8d6f89a5875342b21e8337aa5e3ab0539960a5b42554bc8d8a0fffce7d65", "680": "48d62baa62c2a9c561612192ec39a7dbcecc8badadc0ddc755191648597a42f9", "681": "7adc09dd86f3e73979d9f8a4b3232102ca52bc41d043614fe989cd908ed88c76", "682": "522f0ff3ae2f1761dca78207dec1c9b52556eba2db7503ca03441abf62f65c76", "683": "376e3c3e4b88ee76cb0f02390751a7248fcf1562013b1390b1e276a3f3d7da63", "684": "6363f306f081683781908acd4bedd92b3a75c796243cdacadc4b9896d8cfaaaa", "685": "29f2c4c5325cf626b392a910e6e22b6d2a989bfbb38439c20162b7b786b5e2f8", "686": "990ae3583a1f7a32b7581a8ace626511c812e0bd910b8064fefb31e625b9c22d", "687": "7e78b4b91851b976f5cc2a1341b9389ae7bdd0248ae7f7c53e7ebb2d86bbc73c", "688": "1ada92e769892b4bb540d75cbf40017a24b5b309b28a097ed62eb7f2727518e7", "689": "17a0ba5b100d0a92f3f82e2e6f31c71a6ca53a0f043094a6419331e22036150b", "690": "f9658a8f0687d69f420f655c500304c3c0888f298a68075ab6a2165a3bc47c53", "691": "3ff8aa53eb2f7e700fdc7cb838ca7f7b495948bb997ef70d196c10592fa64680", "692": "c01c3e579b2743866cd3d0c1d9039871356143a99c572593d2702f387e9f629f", "693": "c08e2dd3686459c2989cd6a367d2cc64b2bc2af460417102e9856e91b5f78fa4", "694": "063e59bfd9cbed08afa508954ac9c1c313b80331d6a917fd2202e15e1eeb00e9", "695": "c3259eeed96a5837a6630fd9d1245de7c77e10d0733b6129a3dc99548bd92800", "696": "9ab20a4d8c3c0de897a1c8afa95733d0f7f79870c6379064ef4cf1f5baae67e6", "697": "62c07adf4da24a20a723f6c32e35a51f2b942e363dc9fa35070e34991a5a9c1d", "698": "632f1a4eba12f5c80401d82c4bad7c5679f55ccc89bf2da3e3930ff3d6671ba1", "699": "8c40c5c92fad7ed2774080ddd39f62cdc94ca05dde4273344497ab4206499484", "700": "3dccee8e873d2c9c2f8359417e666b702f97b60b90b229e3c41190909ff9388b", "701": "65a57fc7ebcdab77821276a1eba1c1a625bf2bae575b025359de492592ded205", "702": "c1b0ade78aadbf0d5576489c2200439ef825fe74452115edbc908e9ff955efc0", "703": "1e5ea7fffdcdbca5fc91694b200db8e2e3737e829b7694e4dcf3b937b41be330", "704": "9ddf38880f294ac1a759c764c394cacd4635735880f326a0b5e4a896e4fdce8c", "705": "2bb033d9eeb9157fc6ae835e99b9523bfb1d61173cfb34941cbfdc4c0d3ea67e", "706": "51a0e8daacbd6537efd583c48c5815a9bd22fef0eb9b8e15dbe2ee87c76e2a6b", "707": "9f50d3b52dc4ebae279c6f6021258ca8cd60b8cd13e358f29a2879caa390a774", "708": "42e0a9be7737aaab1fd27543c0273f4c97dd3bd6471e6ec04b1fc7b79542db71", "709": "ac2605c16873ea2b5f0ce5008089a55e37588f45313ad06ccc7dfd96f407eb8a", "710": "09214942caed4184e7155b4016b1e0de37c0a142deaebee3879c770438a28276", "711": "8d8ea19a78bcb10e502f91a057bac1b200ab17db66e11cdf42b63ec65a8e6c18", "712": "001493340cc232a48125f958308be6d0567ff2684e0625e55af8b0a024c4ccca", "713": "98a124df4ffa11cca86fbd959f4d091665fc871a4a86cc1024429d1c116b556e", "714": "cd175b00873a9a3369c628861c1f20df57a4ca75074530ebf5b974d04b8b93c4", "715": "cdb954d8620ad2d95915f94243cdcf71170cfc363334b2f831544f55f0d15746", "716": "abb62293fb9df9bc7a6e80ea24f0da1049f894ade937367e24563a3277f953ef", "717": "319369720bf1831be4c73600c26f5d08dcf6cf85fd32340c28263e39c1dda5e6", "718": "412ce061b1ae228d2226fdb3bf2cb68421870465d6a8cf7ae58515c02fe54684", "719": "c461587d4f3a41c375628e94fb9f971cc2829b8608d3c7aca840e62a6c8f1929", "720": "3651d0d1f023c90e42be5c6ccf28ca71203d1c67d85249323d35db28f146786f", "721": "8430fc43038ba44efb6e9ecbd5aa3dfeaeaf73f2d04a2d5596855c7de5de9c20", "722": "9687101dfe209fd65f57a10603baa38ba83c9152e43a8b802b96f1e07f568e0e", "723": "74832787e7d4e0cb7991256c8f6d02775dffec0684de234786f25f898003f2de", "724": "fa05e2b497e7eafa64574017a4c45aadef6b163d907b03d63ba3f4021096d329", "725": "005c873563f51bbebfdb1f8dbc383259e9a98e506bc87ae8d8c9044b81fc6418" }
{ "001": "c0b20f4665d0388d564f0b6ecf3edc9f9480cb15fff87198b95701d9f5fe1f7b", "002": "1f5882e19314ac13acca52ad5503184b3cb1fd8dbeea82e0979d799af2361704", "003": "5c09f0554518a413e58e6bc5964ba90655713483d0b2bbc94572ad6b0b4dda28", "004": "aa74f52b4c428d89606b411bc165eb81a6266821ecc9b4f30cdb70c5c930f4d9", "005": "1ba90ab11bfb2d2400545337212b0de2a5c7f399215175ade6396e91388912b1", "006": "537942be3eb323c507623a6a73fa87bf5aeb97b7c7422993a82aa7c15f6d9cd6", "007": "ecbe74e25cfa4763dbc304ccac2ffb9912e9625cd9993a84bd0dd6d7dc0ca021", "008": "b9fb30b6553415e9150051ce5710a93d0f55b22557c0068d8e16619a388f145a", "009": "d912d9d473ef86f12da1fb2011c5c0c155bd3a0ebdb4bbd7ea275cecdcb63731", "010": "bed2d160e02f0540f19a64ca738aacb79cfcd08ba7e2421567b16cb6e7e3e90e", "011": "9ded5bc849d33e477aa9c944138d34f0aacc485a372e84464e8a572712a5b7da", "012": "3e7be445b6c19e6db58c2482005c1f78cb74011a4279249ca632011a9f1b61a2", "013": "3cb265a96c5645a9ad11d47551f015c25f3f99792c951617656d84626fbc4868", "014": "78a262dd40eba0f7195686ec7f3891a39437523456f8d16fa9065a34409eeac6", "015": "7b8f812ca89e311e1b16b903de76fa7b0800a939b3028d9dc4d35f6fa4050281", "016": "a6f988d30328bd706c66f8ac0d92aac21dd732149cdd69cb31f459dca20c5abe", "017": "1a455b216c6e916943acf3fa4c7e57a7a5cac66d97cc51befca810c223ef9c23", "018": "fde3f2e7127f6810eb4160bf7bb0563240d78c9d75a9a590b6d6244748a7f4ff", "019": "284de502c9847342318c17d474733ef468fbdbe252cddf6e4b4be0676706d9d0", "020": "c86a2932e1c79343a3c16fb218b9944791aaeedd3e30c87d1c7f505c0e588f7c", "021": "e8c6ef4a1736a245b5682e0262c5c43862cfb233ca5e286be2f5bb4d8a974ecf", "022": "85148c096c25e3ed3da55c7e9c89448018b0f5f53ad8d042129c33d9beac6736", "023": "42e2552a2f589e021824339e2508629ffa00b3489ea467f47e77a1ea97e735c9", "024": "4677b3d9daa3b30a9665e4558f826e04f7833dda886b8ef24f7176519a0db537", "025": "7d398da8791745001b3d1c41030676d1c036687eb1ab32e0b5a1832e7579c073", "026": "fbe10beedf9d29cf53137ba38859ffd1dbe7642cedb7ef0a102a3ab109b47842", "027": "e4110e0852a2f70703f0081fc91c4a20f595919a038729cb37c564d68b875c6f", "028": "261171a770d594f6a7fc76c1a839eda7f6dd4e9495e00e75048578fc86d8adf0", "029": "a207c35d8417aeed4c9e78bcf83f936cd8191c702893be62aa690ce16bc909ca", "030": "46e68e4199ab0a663ab306651528b06756556c9f0d8b819095af45e036dfbe6b", "031": "8de34b4ba97b184c7a2096b9266776175242b87d67bc8d77d7289be6f70cd105", "032": "0d246750daa7f1b367a21f55da454ddc8f62e0a95d163062e9b9273320d5130f", "033": "ad57366865126e55649ecb23ae1d48887544976efea46a48eb5d85a6eeb4d306", "034": "728b8d7d6d5d34cad9cbb7c3ea15f807ae57144594b1740b3c73b82314ccd1ed", "035": "02d20bbd7e394ad5999a4cebabac9619732c343a4cac99470c03e23ba2bdc2bc", "036": "9480c0160719234b57defc0681c0949a175ffb3ff4a3bf5e8163ac843f383f35", "037": "e9800abda89919edac504e90dac91f95e0778e3ba0f21a0bac4e77a84766eaaf", "038": "b2004522103364a6e842b9d042c0707d79af68dec7810078729d061fb7948912", "039": "fd0f7e53c5b02b688a57ee37f3d52065cb168a7b9fd5a3abd93d37e1559fbd30", "040": "d29d53701d3c859e29e1b90028eec1ca8e2f29439198b6e036c60951fb458aa1", "041": "bf05020e70de94e26dba112bb6fb7b0755db5ca88c7225e99187c5a08c8a0428", "042": "79d6eaa2676189eb927f2e16a70091474078e2117c3fc607d35cdc6b591ef355", "043": "6512f20c244844b6130204379601855098826afa1b55ff91c293c853ddf67db5", "044": "97e2524fd3796e83b06c0f89fdcb16e4c544e76e9c0496f57ac84834869f4cc3", "045": "8b0300d71656b9cf0716318be9453c99a13bb8644d227fd683d06124e6a28b35", "046": "8485ee802cc628b8cbd82476133d11b57af87e00711516a703525a9af0193b12", "047": "c7274da71333bd93201fa1e05b1ed54e0074d83f259bd7148c70ddc43082bde1", "048": "743d17cbff06ab458b99ecbb32e1d6bb9a7ff2ac804118f7743177dd969cfc61", "049": "47c6094ff1ff6e37788def89190c8256619ef1511681c503fea02c171569d16e", "050": "6ee74ef623df9fb69facd30b91ed78fe70370462bb267097f0dfeef9d9b057bb", "051": "d17cec28356b4f9a7f1ec0f20cca4c89e270aeb0e75d70d485b05bb1f28e9f6d", "052": "ebd72b510911af3e254a030cd891cb804e1902189eee7a0f6199472eb5e4dba2", "053": "9705cc6128a60cc22581217b715750a6053b2ddda67cc3af7e14803b27cf0c1f", "054": "12e2c8df501501b2bb531e941a737ffa7a2a491e849c5c5841e3b6132291bc35", "055": "9f484139a27415ae2e8612bf6c65a8101a18eb5e9b7809e74ca63a45a65f17f4", "056": "3658d7fa3c43456f3c9c87db0490e872039516e6375336254560167cc3db2ea2", "057": "620c9c332101a5bae955c66ae72268fbcd3972766179522c8deede6a249addb7", "058": "196f327021627b6a48db9c6e0a3388d110909d4bb957eb3fbc90ff1ecbda42cb", "059": "0295239a9d71f7452b93e920b7e0e462f712af5444579d25e06b9614ed77de74", "060": "ad7c26db722221bfb1bf7e3c36b501bedf8be857b1cfa8664fccb074b54354f9", "061": "94e4fb283c1abcccae4b8b28e39a294a323cdc9732c3d3ce1133c518d0a286f6", "062": "d25a595036aa8722157aca38f90084acb369b00df1070f49e203d5a3b7a0736d", "063": "0e17daca5f3e175f448bacace3bc0da47d0655a74c8dd0dc497a3afbdad95f1f", "064": "6d62aa4b52071e39f064a930d190b85ab327eb1a5045a8050ac538666ee765ca", "065": "1c6c0bb2c7ecdc3be8e134f79b9de45155258c1f554ae7542dce48f5cc8d63f0", "066": "316c0f93c7fe125865d85d6e7e7a31b79e9a46c414c45078b732080fa22ef2a3", "067": "53f66b6783cb7552d83015df01b0d5229569fce1dd7d1856335c7244b9a3ded6", "068": "4bf689d09a156621220881a2264dc031b2bfb181213b26d6ff2c338408cf94c3", "069": "79555e4b891e2885525c136f8b834cc0b1e9416960b12e371111a5cb2da0479f", "070": "08c6a7c8c06a01d2b17993ada398084b0707652bcfbd580f9173bcddf120ac2c", "071": "63f032489227c969135c6a6571fe9b33d6970dc6eca32c2086c61a4a099c98fa", "072": "9ef8a4249d4b8f24147ab6e9ad2536eb04f10fb886a8099e88e0e7c41cf7c616", "073": "ae9f9c786cd0f24fe03196d5061545862d87a208580570d46e2cfb371319aa68", "074": "b7c7470e59e2a2df1bfd0a4705488ee6fe0c5c125de15cccdfab0e00d6c03dc0", "075": "8a426e100572b8e2ea7c1b404a1ee694699346632cf4942705c54f05162bc07a", "076": "81c54809c3bdfc23f844fde21ae645525817b6e1bee1525270f49282888a5546", "077": "7f2253d7e228b22a08bda1f09c516f6fead81df6536eb02fa991a34bb38d9be8", "078": "71374036b661ac8ffe4b78c191050c3ccd1c956ca8a5f465ea1956f7ce571f63", "079": "2df095aea1862ebfed8df7fb26e8c4a518ca1a8f604a31cfba9da991fc1d6422", "080": "58bfe3a44f8ae452aaa6ef6267bafc3e841cfe7f9672bdfeb841d2e3a62c1587", "081": "04bad90d08bdf11010267ec9d1c9bbb49a813194dace245868ea8140aec9a1f7", "082": "52c42c55daea3131d5357498b8a0ddcf99d1babd16f6ccaee67cb3d0a665b772", "083": "a825281bc5ce8fe70d66a04e96314e7de070f11fed0f78bc81e007ca7c92e8b0", "084": "692a776beae0e92d1121fed36427c10d0860344614ead6b4760d1b7091a6ab1f", "085": "7b2e7211fb4f4d8352c9215c591252344775c56d58b9a5ff88bda8358628ec4e", "086": "8ffe8459134b46975acd31df13a50c51dbeacf1c19a764bf1602ba7c73ffc8fb", "087": "cec1917df3b3ee1f43b3468596ed3042df700dc7a752fefc06c4142a2832995d", "088": "c06356fdcaff01810e1f794263f3e44a75f28e8902a145a0d01a1fff77614722", "089": "0df5486b7bca884d5f00c502e216f734b2865b202397f24bca25ac9b8a95ab4a", "090": "cb69775effd93fc34ef38dfbfcdc4c593b1a3d8e7ab70c0f05d627dbc5cbd298", "091": "327f057e054d1e6a9a1be4ac6acc4b1dedc63d8a88222396ffe98b3194067347", "092": "538cd20a275b610698691d714b2adf4e4c321915def05667f4d25d97413ec076", "093": "d8ed8ca27d83a63df6982905ea53b4613b9d7974edcee06f301cf43d63177f47", "094": "d1b79281d95ce5bfa848060de4e0c80af2c3cae1ff7453cca31ff31e2d67ac14", "095": "0a3ddcd71cf30a567070630f947ab79fc168865ba0bf112aed9b71fb4e76c32f", "096": "9c527d233befbf357335e18e6dd5b14ef3a62e19ef34f90bd3fb9e5a2a0a0111", "097": "f0e2911e303617c9648692ee8056beeb045d89e469315716abed47cd94a3cd56", "098": "ededac5db280586f534cde4f69ce2c134d2360d6b5da3c3ebc400494cc016e78", "099": "92c5fd0421c1d619cbf1bdba83a207261f2c5f764aed46db9b4d2de03b72b654", "100": "993189cbf49fef4c913aa081f2ef44d360b84bf33d19df93fce4663ac34e9927", "101": "e8539f8b271851cad65d551354874d3086fa9ff7b6f6a2ab9890d63f5ba16c68", "102": "9d693eeee1d1899cbc50b6d45df953d3835acf28ee869879b45565fccc814765", "103": "1f17277005b8d58ad32f2cbee4c482cb8c0f3687c3cfe764ec30ee99827c3b1d", "104": "87dfcf5471e77980d098ff445701dbada0f6f7bac2fa5e43fa7685ec435040e1", "105": "a76f4e7fa1357a955743d5c0acb2e641c50bcaf0eec27eb4aaffebb45fe12994", "106": "197f5e68d1e83af7e40a7c7717acc6a99767bf8c53eece9253131a3790a02063", "107": "bf13bc90121776d7de3c4c3ca4c400a4c12284c3da684b3d530113236813ce81", "108": "3dea386e2c4a8a0633b667fdd4beacd8bb3fe27c282f886c828ad7d6b42c2d73", "109": "735cc3e619b9a1e3ac503ba5195c43c02d968113fd3795373ca085ed7777b54d", "110": "01b4e8163485356b46f612c9d40ed4b8602621d4d02289623e7dbb3dcbe03395", "111": "97c1b054c094337ec1397cd5ccdf6c9efe1067ad16f531824a94eaadb3c0953b", "112": "c99c843e0f6d6566132d97c829780332218e005efc14b633e25a5badb912d63a", "113": "8dbc8319e5d8923ef7ab42108341ee2c32a34ffc0d19d5ae5677f1564813314a", "114": "b3b9ebc9f9ddadb6b630eeef5d7ba724b3bb4d071b249318093eb7547949bbb9", "115": "80c3cd40fa35f9088b8741bd8be6153de05f661cfeeb4625ffbf5f4a6c3c02c4", "116": "a39208d7130682b772d6206acd746bc3779cc1bc0033f0a472e97993d0a32d5b", "117": "54201fbc7a70d21c1b0acede7708f1658d8e87032ab666001e888e7887c67d50", "118": "834e6235764ae632737ebf7cd0be66634c4fb70fe1e55e858efd260a66a0e3a9", "119": "bcabd9609d7293a3a3f1640c2937e302fa52ff03a95c117f87f2c465817eba5e", "120": "2bd8cabf5aecfcadde03beda142ac26c00b6ccfc59fdcb685672cd79a92f63a6", "121": "5292478e83f6b244c7c7c5c1fe272121abdc2982f66ed11fcbc6ea7e73af124d", "122": "6d78b19a042a64f08cc4df0d42fb91cd757829718e60e82a54e3498f03f3ef32", "123": "057b9b6e49d03958b3f38e812d2cfdd0f500e35e537b4fa9afedd2f3444db8a2", "124": "d251170c5287da10bffc1ac8af344e0c434ef5f649fd430fcf1049f90d45cf45", "125": "e9b7a676dc359ffce7075886373af79e3348ddbf344502614d9940eecd0532c1", "126": "38752ed2e711a3c001d5139cb3c945c0f780939db4ea80d68f31e6763b11cfba", "127": "e707d9f315269a34d94d9d9fa4f8b29328e66b53447ef38419c6033e57d5d123", "128": "5e15922fba7f61ddccb2ee579b5ec35034cc32def25ff156ae2b0a3e98c4414e", "129": "3cc4ad1254491787f52a66e595dbb573e13ceb554c51d81e42d5490a575da070", "130": "7a6e9899cccb6a01e05013c622422717f54853f7f2581bc3b88a78b25981da08", "131": "4a8596a7790b5ca9e067da401c018b3206befbcf95c38121854d1a0158e7678a", "132": "ed77e05f47f7f19f09cae9b272bfd6daa1682b426d39dcb7f473234c0c9381c5", "133": "e456d3fec55d88653dd88c3f8bbde1f8240c8ceb7882016d19e6f329e412a4ae", "134": "b144116982f4f0930038299efbdd56afc1528ef59047fb75bade8777309fde4b", "135": "0709e1008834c2ca8648376ac62d74ac8df5457069cbfedf2b0776dab07a3c5b", "136": "84692ebaa4fc17e9cfce27126b3fc5a92c1e33e1d94658de0544f8b35a597592", "137": "6eca481578c967fb9373fe4ce7930b39d8eefe1c0c9c7cb5af241a766bd4dfbc", "138": "1b5f0f504917592dea2e878497b0e12655366f2a7a163e0a081d785124982d2c", "139": "0d2f26ec4004c99171fc415282ec714afa617208480b45aeb104c039dc653f5d", "140": "78ceab5e434a86a6a6bb4f486707bffaf536ef6cb2cc5b45a90b3edd89a03283", "141": "d74ae4b07f05779065fb038b35d85a21444ed3bed2373f51d9e22d85a16a704c", "142": "f59af8b0b63a3d0eb580405092c1539261aec18890ea5b6d6e2d93697d67cd38", "143": "66e9d1093f00eef9a32e704232219f462138f13c493cc0775c507cf51cb231ed", "144": "09a1b036b82baba3177d83c27c1f7d0beacaac6de1c5fdcc9680c49f638c5fb9", "145": "b910b9b7bf3c3f071e410e0474958931a022d20c717a298a568308250ed2b0da", "146": "5292f0166523ea1a89c9f7f2d69064dee481a7d3c119841442cd36f03c42b657", "147": "cdb162a8a376b1df385dac44ce7b10777c9fea049961cb303078ebbd08d70de8", "148": "54f631973f7bc002a958b818a1e99e2fc1a91c41eafe19b9136fac9a4eb8d7b8", "149": "c49382eb9fc41e750239ac7b209513a266e80a268c83cf4d0c79f571629bac48", "150": "c89b0574a2e2f4a63845fe0fd9d51122d9d4149d887995051c3e53d2244bba41", "151": "5d09e3b57ced9fd215acc96186743e422ce48900b8992c9b6c74d3e4117e4140", "152": "c3ea99f86b2f8a74ef4145bb245155ff5f91cd856f287523481c15a1959d5fd1", "153": "fb57f89f289ee59c36cede64d2d13828b8997766b49aa4530aabfc18ff4a4f17", "154": "c877d90a178511a52ae2b2119e99e0b8b643cec44d5fd864bd3ef3e0d7f1f4bb", "155": "58801bebc14c905b79c209affab74e176e2e971c1d9799a1a342ae6a3c2afbc1", "156": "983d2222220ab7ffa243f48274f6eb82f92258445b93b23724770995575d77fe", "157": "023344e94ad747fbc529e3e68b95e596badcc445c85c1c7c8fa590e3d492779a", "158": "d1b58f4c07d1db5eb97785807b6d97a0d1ee1340e7dbcc7bb289f3547559f2fc", "159": "cd3a3d2cf8973c5f2c97ebed2460784818513e7d0fee8f98f4fdcf510295e159", "160": "3a926519b024ea9df5e7ad79d0b1c4400f78f58d07834f5ecd7be522112b676d", "161": "2b3d09a4c76b282db1428342c82c5a55c0ab57c7a7640e0850d82021164477e9", "162": "d50ce1ab3a25a5c5e020517092128ab3ec4a3bd5b58673b2e6cda86bcc0c48a0", "163": "7e17ce0fca5d559f76015765c652d76b8468f9ddc91c2069d7799867b9d52769", "164": "5c680d0b2c4dfac8aade87be60cb4d04a4c3d4db398f51e2cbf131d699b630a8", "165": "304de2e63f91f8f74faaebae7a7ec2e0c6e0d8d322d8a747e4e3be88de2d3505", "166": "14212843872dab188a86eb1f0f7012e1b72ea1097545f29377b3b9b52822af76", "167": "18c18f8710f831a82eb74ae979bd36d609bee818c972ff88f8d8fa065270f951", "168": "66640021d592f79b510f9d6101bd8eca89893187d23919c8edff4075e73ae390", "169": "819b01e0394727fd089f84b9351243176920f03d0c6e33e5ff136016da5d8d4e", "170": "e68fadd33a8c41d9a259577a278d8518aeb8b81c67b8cf03ccf43fc451ec8bd8", "171": "33bf9ed4714b0e5da8828f8b3d9d3e9d0cf55c1d496324acb04a3f195252749c", "172": "b9a27b513dc15448772cac5e914de61f02efe323f528892c0bff86d19913a6bd", "173": "1b2a5e44fda5dfee3ce230f44fe73c672249f6620cdbaa343ba0ba808034958c", "174": "98aabf085c6c8647f5e8a4775dc1d036513742d8e03b8c5c51e41bdfc9c3e7ae", "175": "c03dcb22b7faf121d99542018dd10a07a778abee2678d35c03394a8d207b826b", "176": "4fff1a7beda4291446d76e5ed5177c3f36e52a10481009fdaf2976da39e802ae", "177": "614d3df0ba5fdffab2328eff8e9ca2d76b09bbc447c06bf1fab0419ae278fae9", "178": "094a2ba3011118efdd9d4c1f839e6747dee8ba953b52e9012fe2977e32599375", "179": "9f5563a5ea90ca7023f0304acba78005ee6b7351245a8a668a94dfef160f8d29", "180": "dbef09115a57784ea4ea14c1fe35571301b0d6139bea29d1b9e0babf2c2aae05", "181": "3920627e86db42beb1cdf61d026f9f7798082f1221db25a17fb7feb6c1d49027", "182": "58096166bb8199abf4e07a9ef0f960065e5a635443c1937a1a3c527ade51d594", "183": "bdf84a73b16a5dd5ece189dc970ab2c8f0cb5334c96bdd1d6ba2bad6e7f8a213", "184": "c1e8c0f1b1eb3c258923e9daa46ef055bd79512b485c7dc73a9c5e395d5e6911", "185": "0ea72907eb6c1120740cd80ee6b9a935cd754edcf69379328f24dfc3f09b9986", "186": "3c0078aeae0362b6b7561518d3eb28400193fec73aab35980f138c28b6579433", "187": "f2bc655b33e35669ee9adc841cbda98e0834083eb0657d10f7170e70081db7e0", "188": "38e0291a3f5438779b157e5efcae6cef9db21cbac5607cd08882844cf981febd", "189": "9b2a65ac4c35f6b392501dee2a28221a3975aac5f0866b476f5e6a5a59f3fcc2", "190": "606fe2cb6525dabfcdab93afb594dbc8399cb967fc05f0ca93f6084d3f8fb591", "191": "ea1977e7b22df383de61bded2a4bb3064cf17fcc0170be452330256f938b8d55", "192": "91d614f139082168d730003f04b87135c64e13709ced2a96001ed60796867825", "193": "65648f18a50a7f9195fe56bb8cb9e25421c6d777ad2447a3b566dc8c54f3399a", "194": "cdd31847c6138853597261756d5e795884566220a9361217daa5ba7f87560404", "195": "d12224510de6c98076f6289cbe342a7ec7ea3c5453f6e3cf8d37d9eea74bd07e", "196": "1349b472d2821dff215e54d683dbfca49f0b490ade6a30b1db9667bc94e5312d", "197": "e2aa8f7cb3ba893af8bddbffa6240e7eb71a4f4c4498f2a360f3db7b513094df", "198": "a29d9edd0dceca9a72d2238a50dbb728846cd06594baec35a1b2c053faeab93d", "199": "50a6b9725ef854537a554584ca74612a4d37d0ec35d85d04812c3ae730a4c8cc", "200": "5b439098a3081d99496a7b1b2df6500ca5f66c2f170c709a57b27c6be717538a", "201": "b4e86186652a11df0b9ec8f601c68b4823ae0bafd96357051371fde5d11a25ed", "202": "057243f52fd25fa90a16219d945950ed5523ddb7eb6f2f361b33f8b85af25930", "203": "2742f7af8ce9e20185e940bb4e27afc5fefe8cd7d01d7d8e16c7a5aaf3ad47aa", "204": "15f5e9ae4636a6bf8bdd52f582774b9696b485671f4a64ab8c717166dc085205", "205": "e03c2f4ceabf677ec502d235064a62271ce2ee91132b33f57382c4150c295784", "206": "16bb96da8f20d738bbd735404ea148818ef5942d4d1bc4c707171f9e5e476b1e", "207": "133fea765d0b055894d8aba573f47891c1f7f715f53edeefb200fbda758a1884", "208": "90831cd89b4cceacaf099c9bae2452132cfa2f2b5553c651ef4948460e53d1f3", "209": "570fab1574a3fd9aca6404083dec1c150e858e137692ee0c8011e702ec3e902f", "210": "ae9a76ce3418c06d0eac3375a82744fb4250a2f380e723c404334d8572faead0", "211": "aa4b2bc3a136b27bf10a858ac6a8d48f41e40f769182c444df89c5b9f0ed84e5", "212": "81489bf56605b69cc48f0bce22615d4415b2eea882a11a33e1b317c4facba6eb", "213": "a497e789f49b77d647de0e80cd2699acd3d384cc29c534d6609c700968124d14", "214": "409520c6a94de382003db04a3dfee85a6dbb71324f8bd033e566e510ad47e747", "215": "0eccb27846f417380a12dfd588a353e151b328425ecf3794c9cf7b7eec1a1110", "216": "f735b4b441635ecded989bdc2862e35c75f5179d118d0533ae827a84ed29e81b", "217": "9aa88ac109aefaa7ce79c7b085495863a70679058b106a5deb76b2772a531faa", "218": "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9", "219": "9da1307fd12f4c9a21a34e612920cec286d937418a2d5040676408ba0c47f3d8", "220": "a262318d02a14747ed2137c701f94248bf8651a23d1f82826952e66c25029588", "221": "bfb4e53578fa42f83eda027da0467a351298dd65e3e8e84a987d69fc275e9f2d", "222": "4308f4374b84e657aa7a21e5f5fe42ed16386b6dc7a74bff0d24d08ad62acd26", "223": "3790f82f65ce7bc071b4096ca22544548b3413a755f58bfc401eff3ddf487a86", "224": "96356c050fa66d919c75212d789544db81b012bbaf1f7915b053cb9ba2d67de7", "225": "f37f3f2b0dc57a86dee4ba6ff855283bb4d2f0dea1c5bd1b708853444c2ffcec", "226": "49bd28d97a79875007a6713aa9700df14464217c28a6e76bc93ded57b75a33f5", "227": "b1f73471a3e6ea1dfb04610bd89ccb110994780084280fae872d42a2786f9131", "228": "e38da154f6cccd06cd0001924ec2dad8de5bdcd0b78b68e8d8347768d99ac0bd", "229": "098ffc6baaa32734053275ce38f4bbe58efe0ff946bf31e0e2df4c6a169e23d8", "230": "2c72b887a8638941b85765645b45c5cdb73255427e14d5114f6830f847a6b861", "231": "4aa0c92e77eeed08994650ac6129d77db9f026ae2aee78ad5c9fde132fac0505", "232": "5f7905b71cb897bc7cc6db7e29cc38ee459e2fd8f5d58ba4746d3acd4e46d444", "233": "8d986e287ad21475728b0dbd9e935623d69db4e5fdca0d42bc32d70eda48985b", "234": "2d9d03b778af897e305caa8a1a14a117737bbdd549003c6d7477dd3be8331694", "235": "7168cff545d365b09e8997bb9450343c7090913876c8f7eb9f0e9849c6fc7dd5", "236": "ceb3002bad36c22c5da82fd422b36bad91b97a7d3f5409ed5d16aa9b42dc137a", "237": "c857d8fa78c8fde91f29b3fbe332c2e781f7e8b54532f4c352693d6676fda2a8", "238": "3e2edae8b8ddbcfaecd5aa6c69cb5960b84cc16f7b3232f3386aae9ecbd23f20", "239": "49df3a63ca6509687cabb3d208e92b057630231e66b87fe8c781baabb12a55f8", "240": "5034a21557b2de1c5c2d2aadfe8ffe62162c23f42d1aaabc705ed8519e91a3c1", "241": "85abbe1913df41c57d1e6f00cecea416edb19c64681d1bb43fb5024e2f48d409", "242": "4da30e6198a3d9ae6a538c2366e08ee218de6efe2c5b8f231493e21489c21a7e", "243": "7404bb7881a010271831847e71162ee7a393843922ee93cf7cf3455a0074279c", "244": "21aa3213adeb0a562ec7161e1cfcb5f1701303f1c9f03ed726c536283e080db6", "245": "22b9cfa9ab97c84eb64e3478a43acd4d95b90cae8c3453c968457a89c6387a81", "246": "729e3de7687fc597be2eb4c592d697ff29c78cff6945c9690cfb1ee67550eeed", "247": "f49b98df95a1f826c24cf622ba4d80427a0e0767dffcc28a9206c58508863cca", "248": "44b8116c29dafbdfa984b3751c1dfd057b3e93fc57c8cd18495f1c0f605496bc", "249": "49e96b6ba41e88901dbd118139ef6f013b4fc59e2347058a7e726cf6a2f14067", "250": "f0e0dc05fb555ae5ba9820586bef3bb8a3a82905ece3d8a998a3015fc91c1c3e", "251": "8c1ece1b350c210380456da2bab70054f717731b0dfb34bc3cf4abfacf696f15", "252": "ad20a49374f9176bd26460d35f96f30d734df3cf6fc63b4642380b4e866848de", "253": "ba1a2bbccabbcddbf29ee0b56d0d56b4f026e8a7b97e97de2d48c133ccbdf2a1", "254": "381a2eac64a984a81671722bd95ca5b8b6508a6f490af46780e9f393c6797223", "255": "5e6ece13372bad4a6ea011c933389dfaefedad5860aefba2ab97fe5f59156c42", "256": "068d4a3c845803bf66a9e5320261a0fd7b6292a8230b271a6a83f0dc8c73e907", "257": "d80ac9215ffa7adacb22711cc88f5b580272d0d65c49e1ea48e69d17e264d91a", "258": "256c4d399703b7f16dadef9201efc0ef9f6aa6ee05ddfa2d3e26ff6efe09704d", "259": "275a4e84039a1596ac7e8bbe186163dcfb02bfa99c209653ff5d505a29b4cb10", "260": "f461ff2df66653be1a2e579b1aea515d4a84f2ae5ebea3aa21fb2477a53699f4", "261": "178ecd56cd79c7aaec1353093571ce89845130991d64c5a715a02da83a2705ab", "262": "2e0cb5e8fc8ef04c50a5b9ab9a9eecad446598ebc2527b19c447143e5ae09736", "263": "c870fd75ed0d5ed92ec35789c522d029f364328a16282a1c5eb9b3b7e121eff3", "264": "da5d6bdd89eacf70a88810935f80e4725da4feaf2aa86adb13985d7d9e1c247f", "265": "13f16351c3971c286fae5e9cfbaf6f0a128a6507804fd280971a600019e352e8", "266": "4f39cdd293598de9259231592e99bfc5fde82a0bc1820a4c5faeb54f96037f00", "267": "3e054d92034d3d32c3d4e7acadf1c09232e468fc2520d23d2c7d183ec0735aa3", "268": "2d47c47a2b19178cef9e4eba1a53dd39b5f8657bbe011a71c8d402d294d50132", "269": "4448f310ab9bff796ca70c7b7d0cd3b9c517f72744a8615112f65ba30a6d61f7", "270": "ce71f5bd1db540762e4bc6c4798d8b7f3d2b7068e91c300fd271a46298aea2aa", "271": "5a05e212b9b6ccf6092081f567aa73d27da399d45418f674628a8154f9182b6b", "272": "a326c2d7121d80861aaf110826615e560aa4efdec0cc9fdfce051c6b9038e781", "273": "d32b75411f407c5da6a9a6b4a3907b9a9ebbca6b651324c03432d549671bb837", "274": "b5740ac928d58f53537b05ecc80b7463dc1fd5a53400f57aa55573ecbd5faa56", "275": "e1c843ff0e97692a180e384c1a9c03c7de06ef92ccad5aa6157fabf0dbe5b804", "276": "2edf523574e0a062cacf21f51ed6f81128537f27a3cd27b84a8b5d2478d0092d", "277": "130c990ad499345b7638e57dce365442e2ab2d2571546aae60a9fa6ed3834b8d", "278": "2204d89df74e664621dfe8892277d50e7774f60613561d70ae06ee0eb4c483d4", "279": "4618456c7239784964b8fcd27155e01cf5417a16cdca7b163cc885d598ba93f4", "280": "4b2d9501483d450371ec4413519b0b3461502aabb970fb2b07766d0a3d3a3f85", "281": "b04a4a02fa0ae20b657dcfe3f80ef84fd446daa1521aabae006b61bb8fa5a7da", "282": "6dab2ee10b0dc8db525aeaa2f000f3bd35580ba91e71fe92bcd120ad83cf82c5", "283": "c964c01082a258f4c6bb66a983615686cb4ae363f4d25bd0bdad14cd628cfce8", "284": "df960dabff27b2404555d6b83aed7a58ef9a887104d85b6d5296f1c379b28494", "285": "087de77e5f379e7733505f196e483390596050c75dad56a999b1079ea89246ed", "286": "8f3e5fda508a37403238471d09494dde8c206beadfa0a71381bd8c6ac93abaf4", "287": "5d834d4c0ca68d0dca107ffe9dbaddac7fc038b0ad6ccc7ba3cfb53920236103", "288": "20a3ef9e411065c7265deff5e9b4d398cab6f71faa134353ccea35d2b279af04", "289": "9dda7eb623939f599551ad1d39dbf405211352ae4e65ddd87fe3e31899ca571b", "290": "a629c35ad526f4a6c0bb42f35f3e3fa1077c34e1898eac658775072730c40d6b", "291": "81b1e5196bec98afe72f4412cf907a2816515bad0680bd4062f2b2c715643088", "292": "614950a1cff05f4cf403f55393ed9d7807febbae49522ef83b97e0390038ae03", "293": "9e4067ac93c6febda554d724d453d78bf3e28a7742cdec57ee47c5c706fbe940", "294": "9ac900bf0fbb4c3c7e26986ac33698c46c6c3e8102ab75b40b8df94fc3a0c7a1", "295": "2fdcd631f3c68bef3c90f8679b7aef685fa33f20c2d6eb5965cd2a62267c2ffa", "296": "dfc947e61ea2138ebe47234ba503cf5246ecec530b12e363acb240822ddf0b34", "297": "4d5af88ba8a28b49a79773d3e6521e8731ff07d49765203b157481469e6ae6d0", "298": "94aa77eadafaad7327acb8e653888f00e114cca2fbe04691dabdafa2a0c8cd64", "299": "0f221ba58a8ea417e13847ef91af9ff029561ac18c74bbeeb3f5509af81a3b03", "300": "50a79fb6e417fb4a34e155a9af683aa9a74ee922a6c156a58bfedd22cf3185c4", "301": "eb09a0097a47e7a95b892ad7230475a1a28343b47db4faeb3e47f227aeb04738", "302": "fcf9736fe8c20a6d02f00e9b1e719de06aff4afa99d2eba166592aeff1b8f3b7", "303": "e6266f575c94d805a67fcd3f2391d0961b4b121b8a66afbfbae76dfc34e5c06b", "304": "189bd2a8daf5b638ede7c50035fcf426d125de87a401382f66ab75f35b2ac1f7", "305": "0ac58c6eb8513f4ffe911bf0f044e0153862ee89c04939fd9b294860a37ec9ce", "306": "335998d7e2a3fae2da75a5192d62c37dd006be96831fd37e7438ec6d84451c44", "307": "4f1f2695b1b6b1660f3ef6ac31a81630ca74da9368eafbfb214ec1980705c13c", "308": "bc5ae127f8690ba7f6e9ddad98a49137acb45abf4e187eaf3648f197c72fbe90", "309": "6b78ed4c4bfc942b9b5dc340961f19c690d56f9d721b6b764d1db31da53139db", "310": "0d183ec2ff1cbc768a9eb7eb06c2a354f6c8bab00e64ca2aed2da00825f33c05", "311": "3ae7fdad095eed78e0c63cfe4e28ab7ba2b977259590ed38722e9c44727e598b", "312": "329d107b5743a96e3551084832587a6346e410aa89641d83f03f1242a7244473", "313": "ecc63ee12cbe487e5390007271890b8aa5df2cf48b8e692404895d3c2af20758", "314": "5fa65495795c52818aea910c24e4d3176c71817f5268c34e1cb259b256737352", "315": "95bd03b9913be37d24809d30e7bfd31a1b7a127d03d65e52086857bb3a364b5d", "316": "ca6ec6c9159e10719cd8d2cfcfaf2fe2d3637fb3d497e2c80866de6b593632e6", "317": "5b0d72d34b406ce20714a59f1c4d5340c5559285e340497dbcad68729a9db786", "318": "3e2b479fafb86b8ab097588b8fa12ae8a078f8b5801e15c7faa1ef23d87a631b", "319": "e04b18947b36771937dea491f47b75fedf42a6db684035f5690e6c2bd7e6031e", "320": "e546e4a4c9020669c78a095aa5c5038242dd78e0f98517c0e23c43aefeb58138", "321": "3da0198df2f98a7306ee6d2e12b96ba9a6ad837a6c2d4f316d3cd8589b6af308", "322": "07e511e9002147c33739c924c17a61126d12823d143069535a615a97f86d936f", "323": "be514911dd6258f860c2773253f6df6c22ca975a10c4e34db5903269f2975faf", "324": "53ed94369b59a84d003ff3155edbf481a0eef362325539d6ab1a7f370ce919c8", "325": "43c8dc1907d3e1eb30deb565475ec1ad4f807baf6ef34178508ec85071722f0a", "326": "b08d72606988ea5a82e0caf15e68d81b4f2e8dbb4af6a22437916f3fc53e3dea", "327": "f70bb9cb351daf610a91a3c769d84bbb3f3b8f1169b10839196b65b8585e7c38", "328": "6e26ed661a0add2e583229066d304f7e765a0ea337b6a93bf979e4027b70b94e", "329": "89d8b56a1e05d90ccde0df482ff2fec3d44270739810f3c5d06856c38d801380", "330": "2dfac8e04d08dc5eefcbba4e475164103d339f844896a75ef3af2229185118f9", "331": "a20f9b06c126f4ee65e3f3a0bf345007b35ecb69d035dd0ad848e09300130fcb", "332": "6593d40f4e3f53a73191c704d388c7cd1639403da6e679c8e4169b26ade19f3f", "333": "7499bc84f6bd2211365fec34943d64f6be80a53ee2efb21c099c1c910ca29967", "334": "f24dd99fe5b46bb7a7a30c5eff61e71cab21e05f1b03132d7da9c943f65713f6", "335": "8e2111c24160d92b1b29dd010b8b3a0a4f9af55f1d30bd5892756c58ffaec201", "336": "eed2e8d970c1c5031220476e6b700d16e5065d7893a2766a53600825b4ad3ae5", "337": "44e298d1b55c51c9f127989da1149ccf6bda24c40041f777d35d5b8f192753d2", "338": "b3a60e80296f79cfdfc02354acc674162faefcb3fb78b9672254c9cfc6eb113f", "339": "2b55688ba27d72202632783186211ee24ea39c53915066578291fffd9db73128", "340": "15765221271275022a6ef57634d836b052ffbab6d7d5a6899992972143841e3c", "341": "f7340563f85e057709a2fcc71bd448fed8d6de6907d8ba5f91fefa2abffda6cf", "342": "f252eec230c2e92ed1fa04834bc0738b79597c3b0d2a66c787fdd520e63cb3d3", "343": "1d65c53a04f7eea94ebf76d797c0f79fe3d251bd33e5edc16c780715531b4345", "344": "86d3fb095439bddbc0d6e6e8e433d54aff04350e2da2ad05f53d607113075c8b", "345": "21db551743591f9cd20fffcedf3bda17f9f178bc9fbca528a56c2c61b9e7c731", "346": "f326e2241b7e57320914aa279f9ba2e155ea77f809a188958e0b590bea9c3ada", "347": "0fb6749b98280cc8c26950a2cb9c9dbecac18f8760e161e9bab887dcb0077653", "348": "0cdb77330ae73fbbd0f287240f82b7547a0ef42d37004003a9c759f86b686d61", "349": "690ad38e4357b34368966b9de08d89e0c095246bf55969842f373f1976f86062", "350": "5b427d47f98e296cb78875619fe67d42f41868b78886d560d8fcac89043fe945", "351": "93dcda27a0c12f0c32cc35f0de161e7f7792d11abe5d4c50d7fd5192ab8b11c0", "352": "d01c0cd49e7649289a1f13162757de494bb9104b20ac8bdb30a4180df5225889", "353": "3d856f38821d7b221aaaa9baa3d7927f6e360919e8f8505d7499f9bbd85c44b8", "354": "36dd3030dec4a8050d2079678250c9c6c86c66c64fdbe7f5b82e79024bb8d5a7", "355": "b0a915b700e415ba3acc3ef261128680b921b5df9bd6fb1d35c2d1180e7f61d7", "356": "a309814f13708f2eb5ee8dd1a3114e8f8b15646b8c797bc7119ceaa3f6911f0e", "357": "61c9c81a41fd294a8f07033c8373706694faab4df3652d310e84904356cf5e6c", "358": "7d59500b8883d81040173b88462a73849e0d386a53830d599e6a042f4c1c165f", "359": "0793805920db4896155cbce40fb58570a3cc952d0c15ee57393fa3c6ca7a8222", "360": "ee8cacd40fb7515e510cbbe7deb6005369ce7d9800ecff897f3fd8721fd6ef71", "361": "e96f225fa470174b4ac787b21579ad1556804de85c0c83da99a92ddc2c56c7ac", "362": "9a4ce079c1a882a306e21e0c145dab75a2698cba3860152f03dafc802ad9006e", "363": "258a6e6ea10385ca3c0cf08377d13ef31135bd9479d5a4983beadf158e19ccc6", "364": "13aefde214541fab44d2a3013c532637a3da82199fb6c0a1a941c3108f76b9cf", "365": "0cd978902035027c6898d6b5fc11fb5931f06f8e8ec9c24b4706143c91de9450", "366": "47495a92574a6d7b150eb3f4338748ba03672ff93162139f98e03847f96551cb", "367": "fad9203cd26fccb99f0f89fdc569c230eda46cd72ed3fb7e5f6fbcce78ced1a9", "368": "a237e13fa6c32b66695b8c8de6472d5c93c7650989f047f62a17438c07036845", "369": "da4c450ba0c4f76556fce54bc3f6b2a754a626cf1f87ba3280f545e023942640", "370": "5000899cd3070e1937d42a68766c840bdb9629a49c6112bea5cff52fdb4e9f7a", "371": "7afb55ee21c0447f7b961265abe7ccf87f59af6206949bb1da19fd36334b09df", "372": "fcf734716ed1fa724e7228a489304e3c55e813734fb5792a83f806ab04e40485", "373": "83c98f0431cf944440dfe0a9831275ed451b0d16856aba4100f53170c55c2e6c", "374": "d998ea6616a5a7a9f7beb3ec02f8cbed4a9c5f17be978c31f32ac0f9f4e4460d", "375": "6a72aba5c61e27e281235b1f001ab68b840f6e8bef0e6bbd7bfd8eec1abf844e", "376": "980dce9435a9fc03250df4e809c2f68c48601b64c30d32c6e67bf1faa35fe274", "377": "7b4a0b6958cf23951636b5e27af8041dd9901256c53de44c9be313ffd0a01ea0", "378": "a1b13bda78da3ccab1af6c330d3e768fce62841f924933285e7b1f7a8b7dcd5f", "379": "c957fcbb90e1afe9a342e95608ca035596a7dfd4cef398ada55e05a2462aba14", "380": "b794fae83475a77832f46e69799419f9881bd774e1bfda56773b587c42591039", "381": "e7208f3630a20b01a5e1bf5d0537be9dae9fd7529773cac12b96c4ac2b0f8dbf", "382": "70480c0d26a6d76eba0faf3ee047d6214b2ca4d1442070ae5e79893192ffa699", "383": "3c814d251089cb2a92a78ec3424b2a729cfbbfc6a996fd48148261312364a9a8", "384": "f709015ae0f8ad20bd2efd94d01af3858234e381942b5b15391ff7f77211b116", "385": "0bca6cad1f4ff336b93c9f86c4ac872bda67ee0cd41b1862a7a663852717535d", "386": "3e1748647b60bbf292aacae65b3608ccce8e55e203a36ff062ee787cd8c14480", "387": "cf592fa81780e727a56553df32410beba6de9c33543dd1ef1155b368ba9a9b9f", "388": "911326fcfb0638154f69eabb87e4c0c141df09e56274c8522e9c13b7b577f00f", "389": "cdd56fb06838a10149f2c7229bbc76f78b4a5a58945fb70a47261f1bf635c404", "390": "07dde4848eb878808635fb7b366261b1e9cb158635e76577eecc48ccf941323f", "391": "76cd3def1eea8e2631d333798f4d282bf40f6254b2d18c02c78cb56b33462093", "392": "c4f7ecf21a8738c3ad0114a1ee6a2d16668e71b499741381f30827ed451dc817", "393": "7bbc419f89fde57d2862bfb3678ddab96614693dfca109d0f444e4762a2b7a8f", "394": "7781ca3332d6da18b1b9be5e2eff634b526ae9e8088f6e479b49d657f4f41525", "395": "5b5de0def2c4a989a54ae3e748362c78cd018778d5adc4dec13c1bde6ffdc139", "396": "d42c389d6abc7d8102b8cd1b906e4600da08394388d4dcd432ec955e6d8b311d", "397": "629e23dc358ed2a8c202e1b870e270e401aecc5d726a679b542df8e6becb4200", "398": "c30114e73097c3fa4efb203915f3b828b1b8c432ddeab2b7e1ba3fe63c50e190", "399": "a681ef7bdb22145a3e051ecf7bfb694c18b255c80dae6fb8d49f187d28f3c58f", "400": "c993a792804e09c9f60313f4144953eec072ca6a8a27f44d8718ce53d9429585", "401": "074b576ae2054cd030ffcfa132b1465f8f49b836f505cd4bb01af4a98f4f5337", "402": "d45f88fc3c00673ef7e628d867a54a4ea281b3b2620735cea85a8da3b06321df", "403": "a09086d3cdab7d6ff8a9fba1746c5d236e0ad0abe088be99bb172e80c6f0f8f3", "404": "55a774ac3423440dda50d73e472887195940d5e9df605b30deeb0f2528b001a4", "405": "ee9fa61ae8153df7979be3afe6377e584fbdad624833424a5cff64f6ea94c9da", "406": "584cba4abd5711b8f558fde97620b8ff0fe91586bad052ccff87c49c13f72555", "407": "ac50b37409f7ea91f90856bbfa716731013deffb5f5b51540a99736e08e5378e", "408": "2c12c3cf062c3d9cf2c53e6e4dafce70ca5c7a38c97479c3b013cd91076ecf4a", "409": "5a55b5fb584c359f4b6ee2d21deb62923b0b25e1b4c3da0a6f351079ce657173", "410": "9e224b6ab0b7f20759b63d1799b426a8652c9e637b1f38d3eaf8beff73c80c67", "411": "66c0c1ab79e9887b5daf2c510f2c2c4097044b69fee6bd4ffcff73ad4816b8c7", "412": "27f1768d99e22f8b55d010b8b7acd904e8b66751d5310d32c4d017a0ad34d650", "413": "7c99634a1161e424a14d60b516291655096eb90ed055326325d7f5de7a44a3e7", "414": "4e03e038e99870b1faf45a0a29d6124379d05a0a3553a11aaaa91b8ba56eac5f", "415": "955e433ea745016af2a5df015f1cc223ddd84ddccaee60d5302b7ad61542d9e1", "416": "8d07a87b9012a166f5bec4dcd646d5957c9b3633a1a37c40c584ede75cb7ad22", "417": "3f738338cef45597e3b839536953104186f11d94d16877c77abd8a067c152dc3", "418": "0c813356b30108f89fb37e8774a98af4f9eca3df49e963f985ecea82a88b1437", "419": "8ea8d93a9e874f8c8ceeb240f1f1245a077a7c0a62287d3044feaf855b5dae78", "420": "af7ac1e90e07f189afbb284ae24614d9e713e32098bc39bb81d6484d47351444", "421": "f45e155846624f37cf2ee08be2a63cb1ca35bf795fb0f770b4c91ab549f22b25", "422": "69d728f7e25055dbebd41684bc6de61be6b4db4119d7ecdcef5b5d8ead976537", "423": "3e78c62395be704a59a3a6a65e457725105619e0a6f9f3aa6b311c4f7762b0a0", "424": "fbd6edb36c3754a35e7de936839c4fd0564db873924ba97b35cd43e065835582", "425": "ee5bb631b2a9edf8ed05781b192f42e24ae748f3aa4ba5e635374c094d28ddac", "426": "3e913e088a689d2d33bc797040cea94512bf54a61f96501f60576ab22ed0304b", "427": "415e6da4c7f92da36e2d8c43fa8056d0050ae127e648451e2fada49bf2c936d1", "428": "389bded7b0c14212fb69b559fd1ade4f5b235b976c9655365c45481c3afda486", "429": "3007beefa50c509b89b86c54f53757ff701f795dc5f7ed47a1520c2b092455f7", "430": "59ec8ec2866ca502ad558ade9f8a06a9ff815a1ed649bd1cb513f417f1d4727c", "431": "d3f28dffa4e22b3bed74c3c2c9ded1e4a8be49d3757368e4e3efaf7f79affb15", "432": "59fd80dbc8eb4af9596e4ce8a87313d363da41313351a69ab3525faeb905c27e", "433": "471a7ddde597fbaaaed1941f42ca1fc0f4f047e17f2197f8999dea98b38213f3", "434": "319cb430c66d9f418aa90a3d6f9c2dfc8171383d6f4af5803a73684afcf18e15", "435": "aa29c0119ca84133617c8bc7455afdfcf5b05a569393ff21ebcb10d32ffde2c8", "436": "928f772ad7a9fc501f71cdef6dfe60e2d8cb5d5c5800b519d01afeae0681dd08", "437": "ea70162a014b8294ede65af6fcdc11fb365ab2b126aef8d47983d58816fd6a54", "438": "43633662392854b5d9f9f0fa564605212d016c9ea9377d2a6ab52137238d4191", "439": "42f7e88fab5c9cb31d4bb34403d7958abd5023e9cf9ac05cd29626c5df763584", "440": "cd08ef4f14b804e3106ee88f9d2b24864d5e2fec6c7cd7dddfa2713e1431375a", "441": "daa69bac44ce5f57b4b43ab6ece3b2b3561292c0f4c6e82a506ce2973713f749", "442": "910d2abf184cfd7b1964cec906a79f3e45f59e3d42ec20b22f56de59c9018927", "443": "7a14ac86724d318e6d40464e710c17625d441d1e7adf83d3062305de2f85d445", "444": "390877dded07897360921e8d0d126bf45d6a379d47292c90826d775bd1897f2f", "445": "5ee5723341b0b81c9e0172fcb654f8b24322244bc2d1b55afcb78b180ada180b", "446": "8b2dcb0168e8701dc9da286489a1e68e43e1b17638e5990edd882196d7fd5a29", "447": "179af1c75faa5f42e89ce3b41496a64b2d2846361f76dd5d87f4ce97ec2bec07", "448": "18173b14e0c0bf403b5f0d4aa23515ecf44622b3a860d80e866cd498f107123c", "449": "22d7739bccf54ea1159ce6aca3e215482deba85a4db0676cf86d82a760c44a6c", "450": "938bf7cdedab94bd7208b69047014e3d9ab7b54d1223bd649eb3de0bd61ab47e", "451": "abd88e378f54b649e818d6e1d8e06c9f8cf225ac96b4085523acbb1f0c1df24b", "452": "4119701c51dd8c457b74a19ed7ae3bdf069f5fd915c8085e9a15d909a39db036", "453": "381ba093e8ece9e14efc965ee94bb8adbd1c0bf140875ef95f8f11050d5ed489", "454": "b7613128b0401fdbc07a4015eb3935f6677b84dff936fc5e7e9f424d0ba1006e", "455": "35ee11c9763f48a68f2b60b4b9c3919d3a895afc7071e8dcac5abd5845dfe79f", "456": "8b129a3c7163dae86f1f43c18557296240a02bdac70ad29538eb5dce00e51f4d", "457": "629c99f9af0e962f00b812057c0967861a9b6db9dd652233ac4b37f368d09206", "458": "02df8a1d11130bde8af932dfc5cafe7d8e6c2fc12b82df5d222a91e4eed8e2f8", "459": "062b225facc7a897e0e42e6b0f95deeb8b02de64267bf5cea4cb5280ccec1562", "460": "a05f9a7cb049c40760ea2196eb41df1826ad492e6e5fc4696ce7bfcf7a842811", "461": "95e5e99da04c0cd73e1818a62be3fc0de98c76d5cbdc81261672824ed5b8c1a7", "462": "69eafed1b3d4022fc245a8416c1120bdcd039716db8cd43351a96e6c7d10691d", "463": "018efbd353bb456112cf2c760b4d96aef02aa899ef74d4aadfb3dcf374a22987", "464": "cd4447e836cdbed7f6a3998b50c4ab467aedaeb8e54c377da34245e90fddbe12", "465": "da0612471988c89ea2fb190838f9f5e9029fd106330a801e66280c967ff1c52b", "466": "8d16100c0148ed7bd41003b4a0612cbc5fa150ddabe5f9916ed6eac3fcfdefa4", "467": "d6ea164cb91d14d6aba2d482926cb6cbd1a3644737a0530abac635083a97b8a4", "468": "8d0e3f6bff322ff11d1267f1f8303a8ce1e2d796b7dc2d9eb3e3da939dd850b5", "469": "35e2072f22c7cb980fbe797e30c25e9224328813eb81d07d3c88820492ce9a1f", "470": "4993f275946ae0d444410821faa3ef4a448f10888c50ff59f7ae01d0b50328d9", "471": "b9af9323a0237fbf88fdb14b8bce95c084351325249629ffd4fbb32fe9d6da5d", "472": "5b278c08ab97d82c1779411fb1018b07feac7ddf38a69e4d398240a495c54271", "473": "4448b03417a784f554c44eb15ad2d4cc022bd9cb5abe2547811eb8085355aaaa", "474": "1c64fc4076d6b00aff86a180fd9af927b7c1c9ba87a2ca3c83dd80ba5e5ea973", "475": "e571b4b8218a2961ed2b04f62f816eb18686d82b7f2693694b9c774acef4a0ff", "476": "a6383ed918d7851ed7503921a64201a032a33c9e1cbd4e08d1233f543bd21be9", "477": "c871da03e684e099190c4ce787a9588ae85841246ad7bcc9cb4c302d617f881d", "478": "96d8bec6b787a7aea2da8dfa8a1226e00881afc218c211fc59da830775d55acb", "479": "b35720df96afbd98c6a4f081ae1173fdce21d63f75f7b455f4c2b9fc0aa672c2", "480": "2db876e9625c8638c66103ad0206c9a51b68d4c6a3222f403b195a81837856e3", "481": "bac35824e79af403a2058b08cbc84f8e4df93a21d1766e4ea1de6414e2a8a926", "482": "0f9797e2f3691bc7291d81d1ddd5d88cb4e10b0be555e2ebfbd3c5b12b7cd2b2", "483": "8f3348df383ec9ee00e18d41c419370d42ca6ebf71c510690aa5435a679b7e4f", "484": "3b3bac32669c5b66faaa42b89a2dcb4de0bb9aa0bd279d60061dbe9e7039f5dc", "485": "25d0335a0576f974617351ef5aec889f311fc8d7cddb997862b10b2496842d4d", "486": "93b9a59a937594d2196271416ea3b2221d32b3b40a04bbebbdf97e8bdc557e0a", "487": "a643c75a8d062b87a1c8635fdf439c04d949ce01f75dde10ab6edba90cbaee77", "488": "984593c12abbff5d009091cd3c1883c87efc535f760727ed12f06df0902bfa75", "489": "926ac61244f94e10270a2d40169de025be6db342b3de7f0db33a50b07176c143", "490": "e2c8142e501b0b0b808d2d36f5f38266f99cd3aaca7d2f70f4bba386ae1d2025", "491": "1a1c8b472424f8057c94a9f5e0c0b673551fbe9ea4cde5ca2d90df1de76a5c76", "492": "345a83966ead821efa2a9de93aeb0fd5bd60a8f50e162caae2447f1f4d9462bd", "493": "ee7018d63b08bc7226d6f77c2345a87e09fc7cc87b0a003aaf3a4a3f622edffd", "494": "3d69e540997d79f21f249d4d8f73cd75119d81bcfb8bd80782863249f0d7c62c", "495": "b717f1088b0ce24851c30d54bc8dad9f3ae93402b91c874e385e5c699323a5e2", "496": "fbe77ec1978ad86e73e5a3f494fa7c198fe334b511298f5a0f2d04d6a7f51d01", "497": "a4a66d6c7c555a2997ca59a8dbab512388adf20902293a5617132a16df76d954", "498": "d71813b8175fa2d70181d87ae8f839e79792516a1cfa99a7e6b29500c057617f", "499": "477d5b817df8c0b6f0928d02a58fc39fde2224493cec89393bd6dc349e5235bf", "500": "3ac8e26d4864c538936efa7c5920435107a50c01306adaee5a4aeaa2ef378f7d", "501": "766448b05b248ac3d6e991baa3e4b2d53b02aac426bda312c2299b2b983e145e", "502": "50218b55f5b7207438137f2b0c71e3f6d37afd76aa5b1f2106111f3432b4cef8", "503": "1d7c24799a287d42e97dd4ccc5bbd3713ce139e6294896cc5fe2efb80a1be7ad", "504": "9878db5eb2218b18568dc8cfa13bc8363a1c93e6a59a05cc76da0588fd54af46", "505": "872fc20275833f09c8aaef277abfe77f67be6bd443b489e0cb8bdf9d4ca9fac7", "506": "d66834cc7ebe58cce2ee1c02bb11ae69672d711ead6a0a58ab592339cddbf02e", "507": "ae955394665befbbc89e2ba85b5e520cb293b8d03209b1f71d78ce2cc807a437", "508": "3917ce4173af47bfaf8525f0917736bde3f4bee0ed5fae721c3e2fa957ab1675", "509": "2f64571cd71f0e59006da84808abf3d3ccff9a38884321533d448b3e8e3cae05", "510": "41ce72f4701e786427413b68fb70bd77d921c06648ca15033ce1926a9f1224cb", "511": "c9fc787389265492e60d5503f279714d5b19760ea7b2e1a720e6fc0251fe087c", "512": "a8af6acf3744af13cde63540e37bb9bc722ea19a012656e3a3c5bfff8292c423", "513": "506b90816555d1083be7d211f02a5db364e5c2337fc85b1ba845c1a806689373", "514": "e4e9536766181eda627721723bfbdbca85859a3ba92d439f58ac0009c102430c", "515": "16daaa62fa87776bc4843d226988cc83ee846ceef7b885ab63e10789b30071ae", "516": "44b6de4eb51dd8f762142f284b154d3153592549cdea3b94467fa95484a4f172", "517": "bb72c6d437197a8c1f1132626b3b47adb9827f4f9b912d1069cfcc75575371b5", "518": "ff57c1f518651af805bb4b258130c7c5b0726422c3390327217562088785b4ba", "519": "159b59f1261b7a31d7172cdc28d9515d0731e5117cb30f34a497bc3bd0496da2", "520": "bdfb7f17c8c841c0b61ee7f00e51f09e4c78c90f7977548b72050a7aa12dfa3f", "521": "bd27ca9292c19160cbb0568f750b247fbb805b85f4a2316fcf2c3a35d3ae031d", "522": "98e0ef155297aac8a4060d204614753f26f6ba5357deb78c683783dc7ae30191", "523": "9bfc344c80d1200fe12bea3ba4cacf8d5ac9693258962f2f15f42b30ce8ef3ef", "524": "8df22d8716d7ca6354ea42b8e522d286ff9362cfa5881f527efcf1a953ed1151", "525": "13dc6d869fbe2c3d95f715e55f02bc3d5787874b4c88d7da1d05360afd2025fa", "526": "dfbe442040ce9afba654773fb14f307d67ab614267d3feb6b18df03182b5b60f", "527": "ba634833af68fcf0ca7bcb08fa699b2c5fab934eb81ecd85e7464b01bca131ca", "528": "016f7b569dc1c3466c97754c7dcc0f76c2a32a76c22357cc521bcc330d86daf5", "529": "4960ff863e3d21a58f9e81c3d94075cb7a4daea5fcf396812382111e462fc57f", "530": "6a2e45fdfcad65e0ee84d206d59cbac998026d7415d16a5c0b8c55e4a7d6bb3f", "531": "95ec72fa8c409255d43e7c8d4e957bcb9239534973187b3b4cc2557b09bdba98", "532": "fee6802490757983c499a08831d9bdc75a9eff08700bd29e8e5c134583ee07b3", "533": "8a056666bd75d853a12d22b8317042a3f5500cfb21f6698d90ab41e01edcf81d", "534": "8f65c9feb935e09a04c87143d1b2c63e38f08738199ebcc2758f67ee914d8a48", "535": "ed8970f8ef1e2374289fc735aedff90b010c311a3b80d16df6bca2d3c250fdeb", "536": "f82635851b442ec0ee95c5c2b7377ba382aa364cc49ff4e981d509ef324bb356", "537": "54fc97bb6f3d7c724d4e245df37111c20334972300297fe38b590354fb9dfe92", "538": "650c7f5f382c295cf6e7fb092db6fdfff164c861bcfcfe1fb38a50268f53f50a", "539": "0bfb3df290912d8a70dc5e1e2761151cdf2c4b75d4b37c8fdcbed7483ada85fd", "540": "08f1b2bffa88a9d01eecb8c9da6636b5e668a5478d8876a63ec3a74d7f932205", "541": "5e59cf440336e86b67c17ed61f7bee7e548c434f475c415294b3b652d1aec606", "542": "1257b6a3ad900df97f5aabc1e18b9f7ddae8c7d7ad60216ae21b5b7310cbda84", "543": "8a783bfbe11c7f7b24431a15a0eb582f6fe5f75d1d21a3d55f8d8d81ba6b411c", "544": "ce93bedef94ffbf62ad449cb0c68e8103a0bd005563ab854daa5e470664b4d7b", "545": "40c253003d601fd2c90908bffcd8133e77489fe247e74ec03901895318fe69de", "546": "d40739115f18fee96817266232ff1b8845e7966778fdcc644028fe5c759469be", "547": "fa32a8de8fdcfc551d808c5dd0ff5545a199027acd32e380959b91f3b3d04643", "548": "72e66168068b6ffcd2988e24124c8b1dba9a5b52a383a937397575e3c1e3f031", "549": "a23baaa745a976b4f212836beb81a0a7b42d9f2e923c2412e2c07c63ff660ceb", "550": "f58ff320639b2c47c76ed8aba487e31da0fd4656c3be6e33807cd00f77456e5d", "551": "0449ec4d6d5b2e88603e62f3ec0287ed711cff682bbdfe298a197144ab24e80b", "552": "f125761e8a0d02b17b1dc4be40216f2791727fd4e4bc56f60ebea1925c2fbf36", "553": "dbb93b2a6cbf972bb1f94d1f8656cd113a09a02cbc44f25737e7d75c986646e1", "554": "dcfd1e7a4a32ff0fae296b8211b5c9e91ab81844a0308933f598c712c1bc313d", "555": "cebbca914f917f990202f110e77285132d2a5a3ba9a7475c93e3561d8ba88ea0", "556": "0d5518ef165979b758fcc8df9c8cf536861f376f8640541ba6112ee7610ed82e", "557": "0547c86b57c7c8c590f6d7a5131778f5b6ab2eeccc5e819e5fd095a6d4e68b08", "558": "e763aa1dd494e097251484381ddb057c7d79b739c3f8644b1759e786e12f5b40", "559": "e48eea4c3b4c9d58fe02739accf31bb64dd9c31623ad4cc06c740463d664c098", "560": "77a09dc1ea6f1ae669004b8c9429dd83ead1148c62e0d945173edac45d9000a4", "561": "756d226727e611d4bd22aa33747da2f635eeec070906dbc3262ef29e341e2a6d", "562": "29de450d6e440c528287b98bcb4b76fb5155ab573df4721467446114661936ed", "563": "7703d943dbbfdccb90acad65ed7c0eb13a10034ad01809472a55eb3162b7e53b", "564": "65712c105411e6fc0ed35b9347de8cbaea33b0c5e57cf162f48dc257dd4f05b5", "565": "2945ef4779089c9e49a9a9f5e2a67ba7e393aa20a955ed9302da6677cb03a9cd", "566": "95d936e1d454df2e1e7d486c43af387b39a50cb57e57c7712d967bc9ec556f41", "567": "2abe8af9ee20c6b8ad5034bc31fc1f4f16769595d5b4fc2837db3e76a90ac405", "568": "fdc104338866e50ae2bffc1ea19719136f639df6c25f38a8680a70e9375a9378", "569": "25677266de2b900788dfa047cb53f5585c37b564b3a711243fad52e186ec184a", "570": "9101edb48d98c3742ceb713de591d261b79e90481d28f83f2d2c74d7034f4b46", "571": "c364dde8cce2080d073eb1f9666cca97ccdeba61b2bf19ca0c84987e6f8d3576", "572": "9cc3049e9464376b95fb88d6fff4331e0e40196f92a0a9aa1c5d10dfe33079f7", "573": "2ade73491e183608b340f312d08cfd39c10ecb581c87b873443590452580a43e", "574": "96325b210d18a7a1d6873e00a859648c4754bd4c91c324aa812ed78bd047118b", "575": "33942a261a9150e2b5ce2ffe5b934a81f3972cf5aa5a9414a9d5f63f6b55324b", "576": "7fca01a835681914b5fe5014d5649b5170faf459375ccc2bf9ad71ebaa73940c", "577": "2bdc7a0e8adacf885c6ea0f6534b935b8a9dd338c5dcff05a74c162c3e9dd531", "578": "ce6b6de1d907c8839b84f5f3967f6af7e9a3644a0bd7dffe80cfe531de08f8ca", "579": "03dbff2575902a3c56a64483c8e8ca38d9888f72c6a71a6236eb07b808fb24ab", "580": "96892003c30358ed55a39e13e6159fad09ebc3916e34492b91d63832fa86f731", "581": "4fc5533c52133e54f8b54dcbfc4555638ae809676dbfec9d1400ab032f30648d", "582": "7ba9b154acf699c8a123df5471fd40ad556cf6fc630136c686c87b09c88ff546", "583": "ec10ea6801eadac9ae8ead5f222e0580f419b67d2ad5cd5c8ac914dcf5cfd69f", "584": "510001c4104c80517a13f967df6ee071f15fb7b65e97229bc91b2925cbe4e93e", "585": "ced737da53940337c5dff81720024fbaf4cee38aed1d3514d2a75c7b1271acf8", "586": "9ab074d1d480d718930c9abac8b616a0bc5c30846381d6d9bce1741e9bca1991", "587": "ec3fdcd8136188e3b476270894351cdc05dc44a4df50d1c4ed727294fb89430f", "588": "31400607f95129fcc531604b7b0478a748d2495746280dc07ff30e39cd6f4a97", "589": "3051de9b2a7ced941140aa1074952029f532e133beb41c18bfd990f43bfbd9ae", "590": "4af295f83800334d77a04d56be7524ff6241e3d8b2f23820c9c54580b7996086", "591": "2ecf2c1ab8d9e5cef5224842732af17bd2259598e4363e1d46cb172dccc39022", "592": "2e71a26370d45781f31ede0c7810c2705706ce63291a52d5cd6f060ae16aeb01", "593": "423867f77b64f725f823204796301ae09b427190cdbb62d472bc1395507da9a2", "594": "6c28830e35913c59000dfce4432db255f7dd34809285881f05a9e9749f5d8452", "595": "53fc00ae32e0b0d701175ac17ac0b91e05859ae6d7f3e5bf0548dad36e3d68f9", "596": "9ccbee33387383d458e7ffa2c9c0cb9e4f5bbe3d1b949463a98232ae67d29956", "597": "921102754e24e8ba99480e77652d88764020202e6dcd67adddbb1660204e8e78", "598": "430f975f490ce37df74bc346556cb2186f7a47a58d3b282ab42f35b33a812f7c", "599": "b603988248769444a1566b058ef3660cac528086b8193efd6d0be4080b834780", "600": "dd539cd38fade63aa0d14899c7c75ff459ab839148b15b4efacd4bdfa0408dae", "601": "571c5ade4cd89b460b7d2568a44d1efb05e2927ec840d8ecf149dc9e0ff09734", "602": "edef32d6c2c7193b4b30a0e2c7d3ab37e0ec21db62543f4bf78169b683792e41", "603": "cce7491b7ddf0e3ebde191e0e57614e61602cfaa2b52be5c2d657d9ae5e1f1b1", "604": "d08fe0e5c0fc10640043f9d645446e23fa8efbfdf29c93c87794e5b6405ff51e", "605": "1bdd74af73e2434db6149fd8089bd294defe3cedfaaf92f532568ddc6c48e2ea", "606": "30e44b49f18048323d1c1bf4631587df8f0dbd477ebc79b7ef860a792953d932", "607": "2d9b6a1b4810a39471e5dae85eadf595fc108097eeda746c8925a7be057464de", "608": "cd3fdc5ee5b6e606349b9e5775d6e632e0424d6190f632632bd7435d5622b20d", "609": "8b86933e27e64e6840bedc8087fa31326d9527a424c63ecc61823894c81f867d", "610": "a781fd7cb6970e8f6f679296be5bb0fe7ea62207caa7ce86635257186a5a70d9", "611": "4a3a0b9877d68deb8d7db624ec2d7f4b1c467fe337f803a220292ac6131acc05", "612": "6e95bb170c3a521fc7befa446cad879a36b7b3d0e0e8eab1df6ddbd753156ab7", "613": "afe8c7002c5e15859be829b4b69f0da00c1298971d5afa469b050016fc021978", "614": "f85495a58ad9d5c4d16167084bbc3581ea22e6dfc39423b70d7fe486e316d951", "615": "8da9fc3356df220081c71ccfc9c67251e6dd7058fb11258ecfc88ea9b8c00c92", "616": "0fadf4975e2c27aae12447e080505d604258102f61c8667a5c2594ee033567e8", "617": "06d9e8723de7ffd20129f1d8b5993926a97cad1261dc0cf01a37d8fa728ee996", "618": "04d0dc62694f26c61871d8129259540884ad2296a3cf455f6b92fc911f98c336", "619": "a93d0ec83cbbd4ec0866c97b372e4374a9d6724cc3767f5230e8316734cbb0eb", "620": "071da5dc1dd87c2558b45247c29a92092bc5a00ef3cd46d70d08e18b791d2926", "621": "458ca388a6b74c57ae13d1233984d5b66abb1f18dbfa12aa14ba868a9b5a708d", "622": "1ad0227dc5f8c259ada5120d9db05ac7a013bd1bd84cbbca2f0ae6b174dac129", "623": "d82d0401e10767b022417dbb64d348bc6c03ed4bb7e4553493e8d9e65525d229", "624": "1d25005c86a9635d3483ea63ce95fa097f95792ebab86319c12bc66ea1d2ac83", "625": "3fc397ed884cabc16bf30bb7487c8211424a08279a166d4fa4da6dc151a02cd1", "626": "7c42e09e504cb269512dae989ee7fffe1f3bfea499c990e8edea796761331ccb", "627": "5062b75aa39c974a579b0a3360c4da32e481d2242de72106f651c7d7de631cf1", "628": "dc656eef13928f18d14a9265be6a923bc7d76048b861cdf1523e397801a8ef52", "629": "9eefedc5b5995658be337f48146e37020db4ed3bb61e2af1fc57f698bd398b0d", "630": "6e17ecc4a4d07ffbd67c49a59d31b7efeabd3bfead49fdf1ec005836e6030ebf", "631": "781372694518c122f62566aec8867772e492fefef32c00e24b5604297dc1d44c", "632": "c978055ae1d71dfdfd8bb4e845bb82fc4211b14560bf6001edefa4367e1d4403", "633": "af4ff4b546369974642b3f68d4d3e90f0a0496b3b5d1572b638378fb49c7b4fa", "634": "f6af89331ee087a2fc03e0bddd738e2716b49ed616ceb3b47743cf3806c6d8c2", "635": "e4251ea6989571d8b83993560b537b7a9d0777ba54e6941757580cbfc14aab5f", "636": "dc15b5ccabd8fd3141c244b7dbc6fe95078299ea3ce3016cbb483893fcdd4236", "637": "053571be83ed06ab23a96d4e8fa129a4ce7e740de17dc35b000fb56c35a5ab80", "638": "df57e1f418a24e38b39011048084c6b5cc91a56c1deb643ab605e0350f329b4b", "639": "56930902baea90d1a8e505a227e5d7ac4da6b60f6c370ab75a0011cb3746818f", "640": "c105d171242fa8e35f26491ba2f932d1577dfab2a4a6e75034ae69f062e8aa71", "641": "0f6c3873a87ce630accf7f3b19feb764aac3fa0c3933042a817a82e6a9963aea", "642": "c20081830b70a00d1bcc6f4b6572d511d534986c10ea3c057db304a1f26df2da", "643": "143de023a92c7c8ce5fc0b839644e897267c44c8ba4e715743dc99686415a8b5", "644": "7a8c9f1db1b1bce9a3b8d91e5b1a39a92a478029d975f5e45d593b7ca81a7134", "645": "932a51e4c0cc5e30041ca5db1fd0674820638563a9df1300bece7df12c23017e", "646": "a49cbd2966ea8248816b0a53b6eedea4aef2525aac45272b862d7d52e604625a", "647": "40ad98735f3b5417ea1916f6146b69b7659963263caed186abf0790de0d9dae9", "648": "53b288529a83c376f2399e986e5ca25c5993a6640063386fdb2de491afba2e81", "649": "c0bebda0473186148087feb9828a418ab8d50726a1ff5c39ec69c4a6232c6b67", "650": "98ac68d2bc42f89dbe97b3392ac691ed6c2c4f36a44665555bf7f816ca97cd27", "651": "81f8287532f504b4f4a21e6d6ed573845bff197c479fb52e4c5b6f2fc1cfc40f", "652": "fa32d8e7c1c766a6126b0f1cdd9d752cad55f54d0c05839e89d4da238615d9ed", "653": "311cec39a42837f803ce8cfa5e6df32cc27fe541de108e3e7cf7ba3242e414ee", "654": "f2b3d205c2da66cdf9a596e2caa1098132b832758eea2b14da071b8dd9584ec9", "655": "39517ea688972769cccd46ad15b4f06ac2a6175d053dc97f849fa11a63a163e8", "656": "2a21e5e89d9b019c1195c50af7c6e1864cbab05068d10e11519fb6d4766ceae5", "657": "bbf54db41dc18753a3caa5001aae99c0c998e8a07b6e7390932054d7882498e3", "658": "ca8e7b53b095939e5fafefa56e9b45b40c396145acf2a767f9f2430fbba75a79", "659": "3d6c8492fbfe1c76e3f9d66485a7447489b89763623127deb6ed327a0c2a011b", "660": "23d754ebe35981ad5de850f66bb2294a22280a8ad0b4160b1c29dfb5487505d9", "661": "fd7eaca9690ee0384770e855ed600c96080c5c23565bfdae01c6045a87d9550a", "662": "b93bc0a52860ee0a1fdc28adeca7b39288b1119e0f318467f0a193236e00f99c", "663": "f73e3335b21c11b78987deb5a6eace1cef327981322f53a070adfbe31b56e7d0", "664": "f3f0de955603850bd411690d11a5391e63f515a29e31e9241c66c62d688bcf72", "665": "f2650e75f39098e5a114077b6e07bc15325adce22e1ab4b20569a4eeda5c6ca6", "666": "a01a34d1c29aff5618a96046605adb74fa49b834975051d4ac82672567727a21", "667": "2db51646a4038b38c88512738f79bb21776d39c7bfa3086538cccba0b63024db", "668": "2f3336b7f1211fcc180cd76dc6442fecb412771aa45ef1a7675aa437d04e582b", "669": "28bf022d827392eff1ec8ec121767ec24778f1b69da8605b4ab059023b8ad28a", "670": "38db5dbb2a3ce2d31d1958f5b3ca4c3555eb0ac4193ebffa3f42ffd6bb4806e3", "671": "0580cf2ef8abd3afbf91fba2032c2d51e43306bebb7f979bb750c3d7bd14c961", "672": "394f1b74ccfac5a4fa958d813b5932371c5f8c2f3dbd1eb7202af2223aa08afb", "673": "61c90400cd197b8ea6d7de90fcd1af0959fc37625fe163363fdae0ac4a724bfd", "674": "6037c38f696b10fb531c26396890cd3b48d5408c5b37e61d03a72ae2f7b64ed6", "675": "39c8b1bd1d534381b811bd8050e54b753106c1bfaf5d3cc63d8fe92a94471915", "676": "346d1e2de9915fa2f4ce3675ccebadccb8e9d14239f1e53b6d08d09f5c26297d", "677": "36841bba8f77d669e9d8f4e09ec580ce2c7a36c37da719815e65cc641eb1fdeb", "678": "09532ddbaffb710f02964e270f8658bd8a09149744726a82f618708b35a5fa26", "679": "774f8d6f89a5875342b21e8337aa5e3ab0539960a5b42554bc8d8a0fffce7d65", "680": "48d62baa62c2a9c561612192ec39a7dbcecc8badadc0ddc755191648597a42f9", "681": "7adc09dd86f3e73979d9f8a4b3232102ca52bc41d043614fe989cd908ed88c76", "682": "522f0ff3ae2f1761dca78207dec1c9b52556eba2db7503ca03441abf62f65c76", "683": "376e3c3e4b88ee76cb0f02390751a7248fcf1562013b1390b1e276a3f3d7da63", "684": "6363f306f081683781908acd4bedd92b3a75c796243cdacadc4b9896d8cfaaaa", "685": "29f2c4c5325cf626b392a910e6e22b6d2a989bfbb38439c20162b7b786b5e2f8", "686": "990ae3583a1f7a32b7581a8ace626511c812e0bd910b8064fefb31e625b9c22d", "687": "7e78b4b91851b976f5cc2a1341b9389ae7bdd0248ae7f7c53e7ebb2d86bbc73c", "688": "1ada92e769892b4bb540d75cbf40017a24b5b309b28a097ed62eb7f2727518e7", "689": "17a0ba5b100d0a92f3f82e2e6f31c71a6ca53a0f043094a6419331e22036150b", "690": "f9658a8f0687d69f420f655c500304c3c0888f298a68075ab6a2165a3bc47c53", "691": "3ff8aa53eb2f7e700fdc7cb838ca7f7b495948bb997ef70d196c10592fa64680", "692": "c01c3e579b2743866cd3d0c1d9039871356143a99c572593d2702f387e9f629f", "693": "c08e2dd3686459c2989cd6a367d2cc64b2bc2af460417102e9856e91b5f78fa4", "694": "063e59bfd9cbed08afa508954ac9c1c313b80331d6a917fd2202e15e1eeb00e9", "695": "c3259eeed96a5837a6630fd9d1245de7c77e10d0733b6129a3dc99548bd92800", "696": "9ab20a4d8c3c0de897a1c8afa95733d0f7f79870c6379064ef4cf1f5baae67e6", "697": "62c07adf4da24a20a723f6c32e35a51f2b942e363dc9fa35070e34991a5a9c1d", "698": "632f1a4eba12f5c80401d82c4bad7c5679f55ccc89bf2da3e3930ff3d6671ba1", "699": "8c40c5c92fad7ed2774080ddd39f62cdc94ca05dde4273344497ab4206499484", "700": "3dccee8e873d2c9c2f8359417e666b702f97b60b90b229e3c41190909ff9388b", "701": "65a57fc7ebcdab77821276a1eba1c1a625bf2bae575b025359de492592ded205", "702": "c1b0ade78aadbf0d5576489c2200439ef825fe74452115edbc908e9ff955efc0", "703": "1e5ea7fffdcdbca5fc91694b200db8e2e3737e829b7694e4dcf3b937b41be330", "704": "9ddf38880f294ac1a759c764c394cacd4635735880f326a0b5e4a896e4fdce8c", "705": "2bb033d9eeb9157fc6ae835e99b9523bfb1d61173cfb34941cbfdc4c0d3ea67e", "706": "51a0e8daacbd6537efd583c48c5815a9bd22fef0eb9b8e15dbe2ee87c76e2a6b", "707": "9f50d3b52dc4ebae279c6f6021258ca8cd60b8cd13e358f29a2879caa390a774", "708": "42e0a9be7737aaab1fd27543c0273f4c97dd3bd6471e6ec04b1fc7b79542db71", "709": "ac2605c16873ea2b5f0ce5008089a55e37588f45313ad06ccc7dfd96f407eb8a", "710": "09214942caed4184e7155b4016b1e0de37c0a142deaebee3879c770438a28276", "711": "8d8ea19a78bcb10e502f91a057bac1b200ab17db66e11cdf42b63ec65a8e6c18", "712": "001493340cc232a48125f958308be6d0567ff2684e0625e55af8b0a024c4ccca", "713": "98a124df4ffa11cca86fbd959f4d091665fc871a4a86cc1024429d1c116b556e", "714": "cd175b00873a9a3369c628861c1f20df57a4ca75074530ebf5b974d04b8b93c4", "715": "cdb954d8620ad2d95915f94243cdcf71170cfc363334b2f831544f55f0d15746", "716": "abb62293fb9df9bc7a6e80ea24f0da1049f894ade937367e24563a3277f953ef", "717": "319369720bf1831be4c73600c26f5d08dcf6cf85fd32340c28263e39c1dda5e6", "718": "412ce061b1ae228d2226fdb3bf2cb68421870465d6a8cf7ae58515c02fe54684", "719": "c461587d4f3a41c375628e94fb9f971cc2829b8608d3c7aca840e62a6c8f1929", "720": "3651d0d1f023c90e42be5c6ccf28ca71203d1c67d85249323d35db28f146786f", "721": "8430fc43038ba44efb6e9ecbd5aa3dfeaeaf73f2d04a2d5596855c7de5de9c20", "722": "9687101dfe209fd65f57a10603baa38ba83c9152e43a8b802b96f1e07f568e0e", "723": "74832787e7d4e0cb7991256c8f6d02775dffec0684de234786f25f898003f2de", "724": "fa05e2b497e7eafa64574017a4c45aadef6b163d907b03d63ba3f4021096d329", "725": "005c873563f51bbebfdb1f8dbc383259e9a98e506bc87ae8d8c9044b81fc6418" }
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
""" 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 which R(k) is divisible by n, and let A(n) be the least such value of k; for example, A(7) = 6 and A(41) = 5. The least value of n for which A(n) first exceeds ten is 17. Find the least value of n for which A(n) first exceeds one-million. """ def least_divisible_repunit(divisor: int) -> int: """ Return the least value k such that the Repunit of length k is divisible by divisor. >>> least_divisible_repunit(7) 6 >>> least_divisible_repunit(41) 5 >>> least_divisible_repunit(1234567) 34020 """ if divisor % 5 == 0 or divisor % 2 == 0: return 0 repunit = 1 repunit_index = 1 while repunit: repunit = (10 * repunit + 1) % divisor repunit_index += 1 return repunit_index def solution(limit: int = 1000000) -> int: """ Return the least value of n for which least_divisible_repunit(n) first exceeds limit. >>> solution(10) 17 >>> solution(100) 109 >>> solution(1000) 1017 """ divisor = limit - 1 if divisor % 2 == 0: divisor += 1 while least_divisible_repunit(divisor) <= limit: divisor += 2 return divisor if __name__ == "__main__": print(f"{solution() = }")
""" 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 which R(k) is divisible by n, and let A(n) be the least such value of k; for example, A(7) = 6 and A(41) = 5. The least value of n for which A(n) first exceeds ten is 17. Find the least value of n for which A(n) first exceeds one-million. """ def least_divisible_repunit(divisor: int) -> int: """ Return the least value k such that the Repunit of length k is divisible by divisor. >>> least_divisible_repunit(7) 6 >>> least_divisible_repunit(41) 5 >>> least_divisible_repunit(1234567) 34020 """ if divisor % 5 == 0 or divisor % 2 == 0: return 0 repunit = 1 repunit_index = 1 while repunit: repunit = (10 * repunit + 1) % divisor repunit_index += 1 return repunit_index def solution(limit: int = 1000000) -> int: """ Return the least value of n for which least_divisible_repunit(n) first exceeds limit. >>> solution(10) 17 >>> solution(100) 109 >>> solution(1000) 1017 """ divisor = limit - 1 if divisor % 2 == 0: divisor += 1 while least_divisible_repunit(divisor) <= limit: divisor += 2 return divisor if __name__ == "__main__": print(f"{solution() = }")
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
-1
TheAlgorithms/Python
4,927
[mypy] Fix type annotations for data_structures->linked_list directory files
```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
ParthSatodiya
2021-10-02T18:42:18Z
2021-10-07T15:18:23Z
d654806eae5dc6027911424ea828e566a64641fd
d324f91fe75cc859335ee1f7c9c6307d958d0558
[mypy] Fix type annotations for data_structures->linked_list directory files. ```Shell $ python -m mypy -V mypy 0.910 $ python -m mypy data_structures/linked_list/ Success: no issues found in 14 source files ``` Related Issue: #4052 ### **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 not plagiarized. * [x] I know that pull requests will not be merged if they fail the automated tests. * [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. * [ ] All new Python files are placed inside an existing directory. * [ ] All filenames are in all lowercase characters with no spaces or dashes. * [ ] All functions and variable names follow Python naming conventions. * [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). * [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. * [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. * [ ] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.
def is_palindrome(s: str) -> bool: """ Determine whether the string is palindrome :param s: :return: Boolean >>> is_palindrome("a man a plan a canal panama".replace(" ", "")) True >>> is_palindrome("Hello") False >>> is_palindrome("Able was I ere I saw Elba") True >>> is_palindrome("racecar") True >>> is_palindrome("Mr. Owl ate my metal worm?") True """ # Since Punctuation, capitalization, and spaces are usually ignored while checking # Palindrome, we first remove them from our string. s = "".join([character for character in s.lower() if character.isalnum()]) return s == s[::-1] if __name__ == "__main__": s = input("Enter string to determine whether its palindrome or not: ").strip() if is_palindrome(s): print("Given string is palindrome") else: print("Given string is not palindrome")
def is_palindrome(s: str) -> bool: """ Determine whether the string is palindrome :param s: :return: Boolean >>> is_palindrome("a man a plan a canal panama".replace(" ", "")) True >>> is_palindrome("Hello") False >>> is_palindrome("Able was I ere I saw Elba") True >>> is_palindrome("racecar") True >>> is_palindrome("Mr. Owl ate my metal worm?") True """ # Since Punctuation, capitalization, and spaces are usually ignored while checking # Palindrome, we first remove them from our string. s = "".join([character for character in s.lower() if character.isalnum()]) return s == s[::-1] if __name__ == "__main__": s = input("Enter string to determine whether its palindrome or not: ").strip() if is_palindrome(s): print("Given string is palindrome") else: print("Given string is not palindrome")
-1