Skip to content

Commit 90ed7e7

Browse files
committed
init
0 parents  commit 90ed7e7

20 files changed

+654
-0
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# EditorConfig
3+
# https://EditorConfig.org
4+
#
5+
# Build with init-editorconfig
6+
# https://github.com/abranhe/init-editorconfig
7+
8+
root = true
9+
10+
[*]
11+
indent_style = tab
12+
end_of_line = lf
13+
charset = utf-8
14+
trim_trailing_whitespace = true
15+
insert_final_newline = true
16+
17+
[*.yml]
18+
indent_style = space
19+
indent_size = 2

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
group: travis_latest
2+
language: python
3+
cache:
4+
directories:
5+
- $HOME/.cache/pip
6+
matrix:
7+
include:
8+
- python: 3.4
9+
env: TOX_ENV=py34
10+
- python: 3.5
11+
env: TOX_ENV=py35,coverage
12+
- python: 3.6
13+
env: TOX_ENV=py36
14+
install:
15+
- pip install -r tests/test_requirements.txt
16+
before_script:
17+
# stop the build if there are Python syntax errors or undefined names
18+
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
19+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
20+
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
21+
script:
22+
- pip3 install -e .
23+
- tox -e $TOX_ENV
24+
# Check python uninstall package
25+
- pip3 uninstall -y algorithms
26+
notifications:
27+
email: false
28+
29+
30+
language: python
31+
32+
python:
33+
- "3.3"
34+
- "3.4"
35+
36+
install:
37+
- pip install codecov
38+
39+
script:
40+
- coverage run test.py
41+
42+
notifications:
43+
email: false

allalgorithms/.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EditorConfig
2+
# https://EditorConfig.org
3+
#
4+
# Build with init-editorconfig
5+
# https://github.com/abranhe/init-editorconfig
6+
7+
root = true
8+
9+
[*]
10+
indent_style = tab
11+
end_of_line = lf
12+
charset = utf-8
13+
trim_trailing_whitespace = true
14+
insert_final_newline = true
15+
16+
[*.yml]
17+
indent_style = space
18+
indent_size = 2

allalgorithms/__init__.py

Whitespace-only changes.

allalgorithms/searches/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .binary_search import *
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: UTF-8 -*-
2+
#
3+
# Binary search works for a sorted array.
4+
# The All ▲lgorithms library for python
5+
#
6+
# Contributed by: Carlos Abraham Hernandez
7+
# Github: @abranhe
8+
#
9+
def binary_search(arr, query):
10+
lo, hi = 0, len(arr) - 1
11+
while lo <= hi:
12+
mid = (hi + lo) // 2
13+
val = arr[mid]
14+
if val == query:
15+
return mid
16+
elif val < query:
17+
lo = mid + 1
18+
else:
19+
hi = mid - 1
20+
return None

allalgorithms/sorting/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .merge_sort import *

allalgorithms/sorting/merge_sort.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: UTF-8 -*-
2+
#
3+
# Merge Sort Algorithm
4+
# The All ▲lgorithms library for python
5+
#
6+
# Contributed by: Carlos Abraham Hernandez
7+
# Github: @abranhe
8+
#
9+
def merge_sort(arr):
10+
if len(arr) == 1:
11+
return arr
12+
13+
left = merge_sort(arr[:(len(arr)//2)])
14+
right = merge_sort(arr[(len(arr)//2):])
15+
out = []
16+
17+
while bool(left) or bool(right):
18+
if bool(left) ^ bool(right):
19+
alias = left if left else right
20+
else:
21+
alias = left if left[0] < right[0] else right
22+
23+
out.append(alias[0])
24+
alias.remove(alias[0])
25+
26+
return out

changelog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div align="left">
2+
<img src="https://cdn.abraham.gq/projects/algorithms/algorithms.svg" alt="Algorithms"> <img src="http://konpa.github.io/devicon/devicon.git/icons/python/python-original.svg" width="50px">
3+
<div>
4+
5+
# Version `0.0.0`
6+
7+
Date: October 9, 2018
8+
9+
### Algorithms:
10+
11+
- Sorting
12+
- Bubble Sort
13+
- Searches
14+
- Merge Sort

0 commit comments

Comments
 (0)