Skip to content

Commit 76f5287

Browse files
authored
Merge pull request #1 from TheAlgorithms/master
update-19-11-06
2 parents e22ea7e + a9d5378 commit 76f5287

File tree

537 files changed

+31593
-11681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

537 files changed

+31593
-11681
lines changed

.github/FUNDING.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: TheAlgorithms
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['http://paypal.me/TheAlgorithms/1000', 'https://donorbox.org/thealgorithms']

.github/stale.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Number of days of inactivity before an issue becomes stale
2+
daysUntilStale: 30
3+
# Number of days of inactivity before a stale issue is closed
4+
daysUntilClose: 7
5+
# Issues with these labels will never be considered stale
6+
exemptLabels:
7+
- bug
8+
- help wanted
9+
- OK to merge
10+
# Label to use when marking an issue as stale
11+
staleLabel: wontfix
12+
# Comment to post when marking an issue as stale. Set to `false` to disable
13+
markComment: >
14+
This issue has been automatically marked as stale because it has not had
15+
recent activity. It will be closed if no further activity occurs. Thank you
16+
for your contributions.
17+
# Comment to post when closing a stale issue. Set to `false` to disable
18+
closeComment: true

.github/workflows/autoblack.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
2+
# If all Python code in the pull request is complient with Black then this Action does nothing.
3+
# Othewrwise, Black is run and its changes are committed back to the incoming pull request.
4+
# https://github.com/cclauss/autoblack
5+
6+
name: autoblack
7+
on: [pull_request]
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
max-parallel: 1
13+
matrix:
14+
python-version: [3.7]
15+
steps:
16+
- uses: actions/checkout@v1
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v1
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install psf/black
22+
run: pip install black
23+
- name: Run black --check .
24+
run: black --check .
25+
- name: If needed, commit black changes to the pull request
26+
if: failure()
27+
run: |
28+
black .
29+
git config --global user.name 'autoblack'
30+
git config --global user.email '[email protected]'
31+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
32+
git checkout $GITHUB_HEAD_REF
33+
git commit -am "fixup: Format Python code with psf/black"
34+
git push

.gitignore

+25-8
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ __pycache__/
77
*.so
88

99
# Distribution / packaging
10-
.vscode/
1110
.Python
12-
env/
1311
build/
1412
develop-eggs/
1513
dist/
@@ -21,9 +19,11 @@ lib64/
2119
parts/
2220
sdist/
2321
var/
22+
wheels/
2423
*.egg-info/
2524
.installed.cfg
2625
*.egg
26+
MANIFEST
2727

2828
# PyInstaller
2929
# Usually these files are written by a python script from a template
@@ -43,8 +43,9 @@ htmlcov/
4343
.cache
4444
nosetests.xml
4545
coverage.xml
46-
*,cover
46+
*.cover
4747
.hypothesis/
48+
.pytest_cache/
4849

4950
# Translations
5051
*.mo
@@ -53,6 +54,7 @@ coverage.xml
5354
# Django stuff:
5455
*.log
5556
local_settings.py
57+
db.sqlite3
5658

5759
# Flask stuff:
5860
instance/
@@ -67,7 +69,7 @@ docs/_build/
6769
# PyBuilder
6870
target/
6971

70-
# IPython Notebook
72+
# Jupyter Notebook
7173
.ipynb_checkpoints
7274

7375
# pyenv
@@ -76,17 +78,32 @@ target/
7678
# celery beat schedule file
7779
celerybeat-schedule
7880

79-
# dotenv
80-
.env
81+
# SageMath parsed files
82+
*.sage.py
8183

82-
# virtualenv
84+
# Environments
85+
.env
86+
.venv
87+
env/
8388
venv/
8489
ENV/
90+
env.bak/
91+
venv.bak/
8592

8693
# Spyder project settings
8794
.spyderproject
95+
.spyproject
8896

8997
# Rope project settings
9098
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
106+
.DS_Store
91107
.idea
92-
.DS_Store
108+
.try
109+
.vscode/

.lgtm.yml

-12
This file was deleted.

.travis.yml

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
language: python
2+
python: 3.7
23
cache: pip
3-
python:
4-
- 2.7
5-
- 3.6
6-
#- nightly
7-
#- pypy
8-
#- pypy3
9-
matrix:
10-
allow_failures:
11-
- python: nightly
12-
- python: pypy
13-
- python: pypy3
14-
install:
15-
#- pip install -r requirements.txt
16-
- pip install flake8 # pytest # add another testing frameworks later
4+
before_install: pip install --upgrade pip setuptools
5+
install: pip install -r requirements.txt
176
before_script:
18-
# stop the build if there are Python syntax errors or undefined names
19-
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
20-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
21-
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
7+
- black --check . || true
8+
- flake8 . --count --select=E9,F4,F63,F7,F82 --show-source --statistics
229
script:
23-
- true # pytest --capture=sys # add other tests here
24-
notifications:
25-
on_success: change
26-
on_failure: change # `always` will be the setting once code changes slow down
10+
- scripts/validate_filenames.py # no uppercase, no spaces, in a directory
11+
- mypy --ignore-missing-imports .
12+
- pytest . --doctest-modules
13+
after_success:
14+
- scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md

.vs/Python/v15/.suo

-16.5 KB
Binary file not shown.

.vs/slnx.sqlite

-172 KB
Binary file not shown.

CONTRIBUTING.md

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Contributing guidelines
2+
3+
## Before contributing
4+
5+
Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before sending your pull requests, make sure that you **read the whole guidelines**. If you have any doubt on the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms).
6+
7+
## Contributing
8+
9+
### Contributor
10+
11+
We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
12+
13+
- You did your work - no plagiarism allowed
14+
- Any plagiarized work will not be merged.
15+
- Your work will be distributed under [MIT License](License) once your pull request is merged
16+
- You submitted work fulfils or mostly fulfils our styles and standards
17+
18+
**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity.
19+
20+
**Improving comments** and **writing proper tests** are also highly welcome.
21+
22+
### Contribution
23+
24+
We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work.
25+
26+
Your contribution will be tested by our [automated testing on Travis CI](https://travis-ci.org/TheAlgorithms/Python/pull_requests) to save time and mental energy. After you have submitted your pull request, you should see the Travis tests start to run at the bottom of your submission page. If those tests fail, then click on the ___details___ button try to read through the Travis output to understand the failure. If you do not understand, please leave a comment on your submission page and a community member will try to help.
27+
28+
#### Coding Style
29+
30+
We want your work to be readable by others; therefore, we encourage you to note the following:
31+
32+
- Please write in Python 3.7+. __print()__ is a function in Python 3 so __print "Hello"__ will _not_ work but __print("Hello")__ will.
33+
- Please focus hard on naming of functions, classes, and variables. Help your reader by using __descriptive names__ that can help you to remove redundant comments.
34+
- Single letter variable names are _old school_ so please avoid them unless their life only spans a few lines.
35+
- Expand acronyms because __gcd()__ is hard to understand but __greatest_common_divisor()__ is not.
36+
- Please follow the [Python Naming Conventions](https://pep8.org/#prescriptive-naming-conventions) so variable_names and function_names should be lower_case, CONSTANTS in UPPERCASE, ClassNames should be CamelCase, etc.
37+
38+
39+
40+
- We encourage the use of Python [f-strings](https://realpython.com/python-f-strings/#f-strings-a-new-and-improved-way-to-format-strings-in-python) where the make the code easier to read.
41+
42+
43+
44+
- Please consider running [__psf/black__](https://github.com/python/black) on your Python file(s) before submitting your pull request. This is not yet a requirement but it does make your code more readable and automatically aligns it with much of [PEP 8](https://www.python.org/dev/peps/pep-0008/). There are other code formatters (autopep8, yapf) but the __black__ style is now the recommendation of the Python Core Team. To use it,
45+
46+
```bash
47+
pip3 install black # only required the first time
48+
black .
49+
```
50+
51+
- All submissions will need to pass the test __flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics__ before they will be accepted so if possible, try this test locally on your Python file(s) before submitting your pull request.
52+
53+
```bash
54+
pip3 install flake8 # only required the first time
55+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
56+
```
57+
58+
59+
60+
- Original code submission require docstrings or comments to describe your work.
61+
62+
- More on docstrings and comments:
63+
64+
If you are using a Wikipedia article or some other source material to create your algorithm, please add the URL in a docstring or comment to help your reader.
65+
66+
The following are considered to be bad and may be requested to be improved:
67+
68+
```python
69+
x = x + 2 # increased by 2
70+
```
71+
72+
This is too trivial. Comments are expected to be explanatory. For comments, you can write them above, on or below a line of code, as long as you are consistent within the same piece of code.
73+
74+
We encourage you to put docstrings inside your functions but please pay attention to indentation of docstrings. The following is acceptable in this case:
75+
76+
```python
77+
def sumab(a, b):
78+
"""
79+
This function returns the sum of two integers a and b
80+
Return: a + b
81+
"""
82+
return a + b
83+
```
84+
85+
- Write tests (especially [__doctests__](https://docs.python.org/3/library/doctest.html)) to illustrate and verify your work. We highly encourage the use of _doctests on all functions_.
86+
87+
```python
88+
def sumab(a, b):
89+
"""
90+
This function returns the sum of two integers a and b
91+
Return: a + b
92+
>>> sumab(2, 2)
93+
4
94+
>>> sumab(-2, 3)
95+
1
96+
>>> sumab(4.9, 5.1)
97+
10.0
98+
"""
99+
return a + b
100+
```
101+
102+
These doctests will be run by pytest as part of our automated testing so please try to run your doctests locally and make sure that they are found and pass:
103+
104+
```bash
105+
python3 -m doctest -v my_submission.py
106+
```
107+
108+
The use of the Python builtin __input()__ function is **not** encouraged:
109+
110+
```python
111+
input('Enter your input:')
112+
# Or even worse...
113+
input = eval(input("Enter your input: "))
114+
```
115+
116+
However, if your code uses __input()__ then we encourage you to gracefully deal with leading and trailing whitespace in user input by adding __.strip()__ as in:
117+
118+
```python
119+
starting_value = int(input("Please enter a starting value: ").strip())
120+
```
121+
122+
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission.
123+
124+
```python
125+
def sumab(a: int, b: int) --> int:
126+
pass
127+
```
128+
129+
130+
131+
- [__List comprehensions and generators__](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) are preferred over the use of `lambda`, `map`, `filter`, `reduce` but the important thing is to demonstrate the power of Python in code that is easy to read and maintain.
132+
133+
134+
135+
- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.
136+
- If you need a third party module that is not in the file __requirements.txt__, please add it to that file as part of your submission.
137+
138+
#### Other Standard While Submitting Your Work
139+
140+
- File extension for code should be `.py`. Jupiter notebook files are acceptable in machine learning algorithms.
141+
- Strictly use snake_case (underscore_separated) in your file_name, as it will be easy to parse in future using scripts.
142+
- Please avoid creating new directories if at all possible. Try to fit your work into the existing directory structure.
143+
- If possible, follow the standard *within* the folder you are submitting to.
144+
145+
146+
147+
- If you have modified/added code work, make sure the code compiles before submitting.
148+
- If you have modified/added documentation work, ensure your language is concise and contains no grammar errors.
149+
- Do not update the README.md or DIRECTORY.md file which will be periodically autogenerated by our Travis CI processes.
150+
- Add a corresponding explanation to [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation) (Optional but recommended).
151+
- All submissions will be tested with [__mypy__](http://www.mypy-lang.org) so we encourage to add [__Python type hints__](https://docs.python.org/3/library/typing.html) where it makes sense to do so.
152+
153+
154+
155+
- Most importantly,
156+
- **Be consistent in the use of these guidelines when submitting.**
157+
- **Join** [Gitter](https://gitter.im/TheAlgorithms) **now!**
158+
- Happy coding!
159+
160+
Writer [@poyea](https://github.com/poyea), Jun 2019.

0 commit comments

Comments
 (0)