Skip to content

writing test for min cost string conversion #2392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
88 changes: 88 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# More details are here: https://help.github.com/articles/about-codeowners/

# The '*' pattern is global owners.

# Order is important. The last matching pattern has the most precedence.

/.* @cclauss @dhruvmanila

# /arithmetic_analysis/

# /backtracking/

# /bit_manipulation/

# /blockchain/

# /boolean_algebra/

# /cellular_automata/

# /ciphers/ @cclauss # TODO: Uncomment this line after Hacktoberfest

# /compression/

# /computer_vision/

# /conversions/ @cclauss # TODO: Uncomment this line after Hacktoberfest

# /data_structures/ @cclauss # TODO: Uncomment this line after Hacktoberfest

/digital_image_processing/ @mateuszz0000

# /divide_and_conquer/

/dynamic_programming/ @Kush1101

# /file_transfer/

# /fuzzy_logic/

# /genetic_algorithm/

# /geodesy/

# /graphics/

# /graphs/

# /greedy_method/

# /hashes/

# /images/

# /linear_algebra/

# /machine_learning/

/maths/ @Kush1101

# /matrix/

# /networking_flow/

# /neural_network/

# /other/ @cclauss # TODO: Uncomment this line after Hacktoberfest

/project_euler/ @dhruvmanila @Kush1101

# /quantum/

# /scheduling/

# /scripts/

# /searches/

/sorts/ @mateuszz0000

# /strings/ @cclauss # TODO: Uncomment this line after Hacktoberfest

# /traversals/

/web_programming/ @cclauss
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "build"

on:
pull_request:
schedule:
- cron: "0 0 * * *" # Run everyday

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.9"
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools six wheel
python -m pip install pytest-cov -r requirements.txt
- name: Run tests
run: pytest --doctest-modules --ignore=project_euler/ --cov-report=term-missing:skip-covered --cov=. .
- if: ${{ success() }}
run: scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md
21 changes: 21 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: pre-commit

on: [push, pull_request]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cache/pre-commit
~/.cache/pip
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- uses: actions/setup-python@v2
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pre-commit
- run: pre-commit run --verbose --all-files --show-diff-on-failure
31 changes: 31 additions & 0 deletions .github/workflows/project_euler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
pull_request:
# only check if a file is changed within the project_euler directory and related files
paths:
- 'project_euler/**'
- '.github/workflows/project_euler.yml'
- 'scripts/validate_solutions.py'

name: 'Project Euler'

jobs:
project-euler:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install pytest and pytest-cov
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pytest pytest-cov
- run: pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
validate-solutions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install pytest
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pytest
- run: pytest scripts/validate_solutions.py
60 changes: 60 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-executables-have-shebangs
- id: check-yaml
- id: end-of-file-fixer
types: [python]
- id: trailing-whitespace
exclude: |
(?x)^(
data_structures/heap/binomial_heap.py
)$
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.5.3
hooks:
- id: isort
args:
- --profile=black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
args:
- --ignore=E203,W503
- --max-complexity=25
- --max-line-length=88
# FIXME: fix mypy errors and then uncomment this
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.782
# hooks:
# - id: mypy
# args:
# - --ignore-missing-imports
- repo: https://github.com/codespell-project/codespell
rev: v1.17.1
hooks:
- id: codespell
args:
- --ignore-words-list=ans,fo,followings,hist,iff,mater,secant,som,tim
- --skip="./.*,./other/dictionary.txt,./other/words,./project_euler/problem_022/p022_names.txt"
- --quiet-level=2
exclude: |
(?x)^(
other/dictionary.txt |
other/words |
project_euler/problem_022/p022_names.txt
)$
- repo: local
hooks:
- id: validate-filenames
name: Validate filenames
entry: ./scripts/validate_filenames.py
language: script
pass_filenames: false
Empty file added arithmetic_analysis/__init__.py
Empty file.
Empty file.
6 changes: 5 additions & 1 deletion arithmetic_analysis/newton_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@


# function is the f(x) and derivative is the f'(x)
def newton(function: RealFunc, derivative: RealFunc, starting_int: int,) -> float:
def newton(
function: RealFunc,
derivative: RealFunc,
starting_int: int,
) -> float:
"""
>>> newton(lambda x: x ** 3 - 2 * x - 5, lambda x: 3 * x ** 2 - 2, 3)
2.0945514815423474
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_raphson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def newton_raphson(func: str, a: int, precision: int = 10 ** -10) -> float:
""" Finds root from the point 'a' onwards by Newton-Raphson method
"""Finds root from the point 'a' onwards by Newton-Raphson method
>>> newton_raphson("sin(x)", 2)
3.1415926536808043
>>> newton_raphson("x**2 - 5*x +2", 0.4)
Expand Down
Empty file added backtracking/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions backtracking/all_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def generate_all_permutations(sequence):

def create_state_space_tree(sequence, current_sequence, index, index_used):
"""
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.
"""
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)
Expand Down
8 changes: 4 additions & 4 deletions backtracking/all_subsequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def generate_all_subsequences(sequence):

def create_state_space_tree(sequence, current_subsequence, index):
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly two children.
It terminates when it reaches the end of the given sequence.
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly two children.
It terminates when it reaches the end of the given sequence.
"""

if index == len(sequence):
print(current_subsequence)
Expand Down
2 changes: 1 addition & 1 deletion backtracking/sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def sudoku(grid):
[7, 4, 5, 2, 8, 6, 3, 1, 9]]
>>> sudoku(no_solution)
False
"""
"""

if is_completed(grid):
return grid
Expand Down
12 changes: 6 additions & 6 deletions backtracking/sum_of_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def generate_sum_of_subsets_soln(nums, max_sum):

def create_state_space_tree(nums, max_sum, num_index, path, result, remaining_nums_sum):
"""
Creates a state space tree to iterate through each branch using DFS.
It terminates the branching of a node when any of the two conditions
given below satisfy.
This algorithm follows depth-fist-search and backtracks when the node is not
branchable.
Creates a state space tree to iterate through each branch using DFS.
It terminates the branching of a node when any of the two conditions
given below satisfy.
This algorithm follows depth-fist-search and backtracks when the node is not
branchable.

"""
"""
if sum(path) > max_sum or (remaining_nums_sum + sum(path)) < max_sum:
return
if sum(path) == max_sum:
Expand Down
Empty file added bit_manipulation/__init__.py
Empty file.
52 changes: 52 additions & 0 deletions bit_manipulation/binary_and_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm


def binary_and(a: int, b: int):
"""
Take in 2 integers, convert them to binary,
return a binary number that is the
result of a binary and operation on the integers provided.

>>> binary_and(25, 32)
'0b000000'
>>> binary_and(37, 50)
'0b100000'
>>> binary_and(21, 30)
'0b10100'
>>> binary_and(58, 73)
'0b0001000'
>>> binary_and(0, 255)
'0b00000000'
>>> binary_and(256, 256)
'0b100000000'
>>> binary_and(0, -1)
Traceback (most recent call last):
...
ValueError: the value of both input must be positive
>>> binary_and(0, 1.1)
Traceback (most recent call last):
...
TypeError: 'float' object cannot be interpreted as an integer
>>> binary_and("0", "1")
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'str' and 'int'
"""
if a < 0 or b < 0:
raise ValueError("the value of both input must be positive")

a_binary = str(bin(a))[2:] # remove the leading "0b"
b_binary = str(bin(b))[2:] # remove the leading "0b"

max_len = max(len(a_binary), len(b_binary))

return "0b" + "".join(
str(int(char_a == "1" and char_b == "1"))
for char_a, char_b in zip(a_binary.zfill(max_len), b_binary.zfill(max_len))
)


if __name__ == "__main__":
import doctest

doctest.testmod()
Loading