Skip to content

Commit f0cd9d5

Browse files
committed
Merge branch 'master' into 'test/string-conversion'
1 parent a889959 commit f0cd9d5

File tree

376 files changed

+19248
-0
lines changed

Some content is hidden

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

376 files changed

+19248
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.github/CODEOWNERS

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# More details are here: https://help.github.com/articles/about-codeowners/
5+
6+
# The '*' pattern is global owners.
7+
8+
# Order is important. The last matching pattern has the most precedence.
9+
10+
/.* @cclauss @dhruvmanila
11+
12+
# /arithmetic_analysis/
13+
14+
# /backtracking/
15+
16+
# /bit_manipulation/
17+
18+
# /blockchain/
19+
20+
# /boolean_algebra/
21+
22+
# /cellular_automata/
23+
24+
# /ciphers/ @cclauss # TODO: Uncomment this line after Hacktoberfest
25+
26+
# /compression/
27+
28+
# /computer_vision/
29+
30+
# /conversions/ @cclauss # TODO: Uncomment this line after Hacktoberfest
31+
32+
# /data_structures/ @cclauss # TODO: Uncomment this line after Hacktoberfest
33+
34+
/digital_image_processing/ @mateuszz0000
35+
36+
# /divide_and_conquer/
37+
38+
/dynamic_programming/ @Kush1101
39+
40+
# /file_transfer/
41+
42+
# /fuzzy_logic/
43+
44+
# /genetic_algorithm/
45+
46+
# /geodesy/
47+
48+
# /graphics/
49+
50+
# /graphs/
51+
52+
# /greedy_method/
53+
54+
# /hashes/
55+
56+
# /images/
57+
58+
# /linear_algebra/
59+
60+
# /machine_learning/
61+
62+
/maths/ @Kush1101
63+
64+
# /matrix/
65+
66+
# /networking_flow/
67+
68+
# /neural_network/
69+
70+
# /other/ @cclauss # TODO: Uncomment this line after Hacktoberfest
71+
72+
/project_euler/ @dhruvmanila @Kush1101
73+
74+
# /quantum/
75+
76+
# /scheduling/
77+
78+
# /scripts/
79+
80+
# /searches/
81+
82+
/sorts/ @mateuszz0000
83+
84+
# /strings/ @cclauss # TODO: Uncomment this line after Hacktoberfest
85+
86+
# /traversals/
87+
88+
/web_programming/ @cclauss

.github/workflows/build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "build"
2+
3+
on:
4+
pull_request:
5+
schedule:
6+
- cron: "0 0 * * *" # Run everyday
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-python@v2
14+
with:
15+
python-version: "3.9"
16+
- uses: actions/cache@v2
17+
with:
18+
path: ~/.cache/pip
19+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip setuptools six wheel
23+
python -m pip install pytest-cov -r requirements.txt
24+
- name: Run tests
25+
run: pytest --doctest-modules --ignore=project_euler/ --cov-report=term-missing:skip-covered --cov=. .
26+
- if: ${{ success() }}
27+
run: scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md

.github/workflows/pre-commit.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: pre-commit
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
pre-commit:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/cache@v2
11+
with:
12+
path: |
13+
~/.cache/pre-commit
14+
~/.cache/pip
15+
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
16+
- uses: actions/setup-python@v2
17+
- name: Install pre-commit
18+
run: |
19+
python -m pip install --upgrade pip
20+
python -m pip install --upgrade pre-commit
21+
- run: pre-commit run --verbose --all-files --show-diff-on-failure

.github/workflows/project_euler.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
on:
2+
pull_request:
3+
# only check if a file is changed within the project_euler directory and related files
4+
paths:
5+
- 'project_euler/**'
6+
- '.github/workflows/project_euler.yml'
7+
- 'scripts/validate_solutions.py'
8+
9+
name: 'Project Euler'
10+
11+
jobs:
12+
project-euler:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-python@v2
17+
- name: Install pytest and pytest-cov
18+
run: |
19+
python -m pip install --upgrade pip
20+
python -m pip install --upgrade pytest pytest-cov
21+
- run: pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
22+
validate-solutions:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/setup-python@v2
27+
- name: Install pytest
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install --upgrade pytest
31+
- run: pytest scripts/validate_solutions.py

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: check-executables-have-shebangs
6+
- id: check-yaml
7+
- id: end-of-file-fixer
8+
types: [python]
9+
- id: trailing-whitespace
10+
exclude: |
11+
(?x)^(
12+
data_structures/heap/binomial_heap.py
13+
)$
14+
- id: requirements-txt-fixer
15+
- repo: https://github.com/psf/black
16+
rev: stable
17+
hooks:
18+
- id: black
19+
- repo: https://github.com/PyCQA/isort
20+
rev: 5.5.3
21+
hooks:
22+
- id: isort
23+
args:
24+
- --profile=black
25+
- repo: https://gitlab.com/pycqa/flake8
26+
rev: 3.8.3
27+
hooks:
28+
- id: flake8
29+
args:
30+
- --ignore=E203,W503
31+
- --max-complexity=25
32+
- --max-line-length=88
33+
# FIXME: fix mypy errors and then uncomment this
34+
# - repo: https://github.com/pre-commit/mirrors-mypy
35+
# rev: v0.782
36+
# hooks:
37+
# - id: mypy
38+
# args:
39+
# - --ignore-missing-imports
40+
- repo: https://github.com/codespell-project/codespell
41+
rev: v1.17.1
42+
hooks:
43+
- id: codespell
44+
args:
45+
- --ignore-words-list=ans,fo,followings,hist,iff,mater,secant,som,tim
46+
- --skip="./.*,./other/dictionary.txt,./other/words,./project_euler/problem_022/p022_names.txt"
47+
- --quiet-level=2
48+
exclude: |
49+
(?x)^(
50+
other/dictionary.txt |
51+
other/words |
52+
project_euler/problem_022/p022_names.txt
53+
)$
54+
- repo: local
55+
hooks:
56+
- id: validate-filenames
57+
name: Validate filenames
58+
entry: ./scripts/validate_filenames.py
59+
language: script
60+
pass_filenames: false

arithmetic_analysis/__init__.py

Whitespace-only changes.

arithmetic_analysis/image_data/__init__.py

Whitespace-only changes.

backtracking/__init__.py

Whitespace-only changes.

bit_manipulation/__init__.py

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
2+
3+
4+
def binary_and(a: int, b: int):
5+
"""
6+
Take in 2 integers, convert them to binary,
7+
return a binary number that is the
8+
result of a binary and operation on the integers provided.
9+
10+
>>> binary_and(25, 32)
11+
'0b000000'
12+
>>> binary_and(37, 50)
13+
'0b100000'
14+
>>> binary_and(21, 30)
15+
'0b10100'
16+
>>> binary_and(58, 73)
17+
'0b0001000'
18+
>>> binary_and(0, 255)
19+
'0b00000000'
20+
>>> binary_and(256, 256)
21+
'0b100000000'
22+
>>> binary_and(0, -1)
23+
Traceback (most recent call last):
24+
...
25+
ValueError: the value of both input must be positive
26+
>>> binary_and(0, 1.1)
27+
Traceback (most recent call last):
28+
...
29+
TypeError: 'float' object cannot be interpreted as an integer
30+
>>> binary_and("0", "1")
31+
Traceback (most recent call last):
32+
...
33+
TypeError: '<' not supported between instances of 'str' and 'int'
34+
"""
35+
if a < 0 or b < 0:
36+
raise ValueError("the value of both input must be positive")
37+
38+
a_binary = str(bin(a))[2:] # remove the leading "0b"
39+
b_binary = str(bin(b))[2:] # remove the leading "0b"
40+
41+
max_len = max(len(a_binary), len(b_binary))
42+
43+
return "0b" + "".join(
44+
str(int(char_a == "1" and char_b == "1"))
45+
for char_a, char_b in zip(a_binary.zfill(max_len), b_binary.zfill(max_len))
46+
)
47+
48+
49+
if __name__ == "__main__":
50+
import doctest
51+
52+
doctest.testmod()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
def binary_count_setbits(a: int) -> int:
2+
"""
3+
Take in 1 integer, return a number that is
4+
the number of 1's in binary representation of that number.
5+
6+
>>> binary_count_setbits(25)
7+
3
8+
>>> binary_count_setbits(36)
9+
2
10+
>>> binary_count_setbits(16)
11+
1
12+
>>> binary_count_setbits(58)
13+
4
14+
>>> binary_count_setbits(4294967295)
15+
32
16+
>>> binary_count_setbits(0)
17+
0
18+
>>> binary_count_setbits(-10)
19+
Traceback (most recent call last):
20+
...
21+
ValueError: Input value must be a positive integer
22+
>>> binary_count_setbits(0.8)
23+
Traceback (most recent call last):
24+
...
25+
TypeError: Input value must be a 'int' type
26+
>>> binary_count_setbits("0")
27+
Traceback (most recent call last):
28+
...
29+
TypeError: '<' not supported between instances of 'str' and 'int'
30+
"""
31+
if a < 0:
32+
raise ValueError("Input value must be a positive integer")
33+
elif isinstance(a, float):
34+
raise TypeError("Input value must be a 'int' type")
35+
return bin(a).count("1")
36+
37+
38+
if __name__ == "__main__":
39+
import doctest
40+
41+
doctest.testmod()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from math import log2
2+
3+
4+
def binary_count_trailing_zeros(a: int) -> int:
5+
"""
6+
Take in 1 integer, return a number that is
7+
the number of trailing zeros in binary representation of that number.
8+
9+
>>> binary_count_trailing_zeros(25)
10+
0
11+
>>> binary_count_trailing_zeros(36)
12+
2
13+
>>> binary_count_trailing_zeros(16)
14+
4
15+
>>> binary_count_trailing_zeros(58)
16+
1
17+
>>> binary_count_trailing_zeros(4294967296)
18+
32
19+
>>> binary_count_trailing_zeros(0)
20+
0
21+
>>> binary_count_trailing_zeros(-10)
22+
Traceback (most recent call last):
23+
...
24+
ValueError: Input value must be a positive integer
25+
>>> binary_count_trailing_zeros(0.8)
26+
Traceback (most recent call last):
27+
...
28+
TypeError: Input value must be a 'int' type
29+
>>> binary_count_trailing_zeros("0")
30+
Traceback (most recent call last):
31+
...
32+
TypeError: '<' not supported between instances of 'str' and 'int'
33+
"""
34+
if a < 0:
35+
raise ValueError("Input value must be a positive integer")
36+
elif isinstance(a, float):
37+
raise TypeError("Input value must be a 'int' type")
38+
return 0 if (a == 0) else int(log2(a & -a))
39+
40+
41+
if __name__ == "__main__":
42+
import doctest
43+
44+
doctest.testmod()

0 commit comments

Comments
 (0)