The black formatter is no longer beta (#5960)

* The black formatter is no longer beta

* pre-commit autoupdate

* pre-commit autoupdate

* Remove project_euler/problem_145 which is killing our CI tests

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss 2022-01-30 20:29:54 +01:00 committed by GitHub
parent c15a4d5af6
commit 24d3cf8244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
81 changed files with 139 additions and 228 deletions

View File

@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.1.0
hooks:
- id: check-executables-have-shebangs
- id: check-yaml
@ -14,26 +14,26 @@ repos:
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: 21.4b0
rev: 22.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.8.0
rev: 5.10.1
hooks:
- id: isort
args:
- --profile=black
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.0
rev: v2.31.0
hooks:
- id: pyupgrade
args:
- --py39-plus
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.1
rev: 3.9.2
hooks:
- id: flake8
args:
@ -42,7 +42,7 @@ repos:
- --max-line-length=88
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v0.931
hooks:
- id: mypy
args:
@ -51,11 +51,11 @@ repos:
- --non-interactive
- repo: https://github.com/codespell-project/codespell
rev: v2.0.0
rev: v2.1.0
hooks:
- id: codespell
args:
- --ignore-words-list=ans,crate,fo,followings,hist,iff,mater,secant,som,tim
- --ignore-words-list=ans,crate,fo,followings,hist,iff,mater,secant,som,sur,tim
- --skip="./.*,./strings/dictionary.txt,./strings/words.txt,./project_euler/problem_022/p022_names.txt"
exclude: |
(?x)^(

View File

@ -856,8 +856,6 @@
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_135/sol1.py)
* Problem 144
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_144/sol1.py)
* Problem 145
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_145/sol1.py)
* Problem 173
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_173/sol1.py)
* Problem 174

View File

@ -1,87 +0,0 @@
"""
Problem 145: https://projecteuler.net/problem=145
Name: How many reversible numbers are there below one-billion?
Some positive integers n have the property that the
sum [ n + reverse(n) ] consists entirely of odd (decimal) digits.
For instance, 36 + 63 = 99 and 409 + 904 = 1313.
We will call such numbers reversible; so 36, 63, 409, and 904 are reversible.
Leading zeroes are not allowed in either n or reverse(n).
There are 120 reversible numbers below one-thousand.
How many reversible numbers are there below one-billion (10^9)?
Solution:
Here a brute force solution is used to find and count the reversible numbers.
"""
from __future__ import annotations
def check_if_odd(sum: int = 36) -> int:
"""
Check if the last digit in the sum is even or odd. If even return 0.
If odd then floor division by 10 is used to remove the last number.
Process continues until sum becomes 0 because no more numbers.
>>> check_if_odd(36)
0
>>> check_if_odd(33)
1
"""
while sum > 0:
if (sum % 10) % 2 == 0:
return 0
sum = sum // 10
return 1
def find_reverse_number(number: int = 36) -> int:
"""
Reverses the given number. Does not work with number that end in zero.
>>> find_reverse_number(36)
63
>>> find_reverse_number(409)
904
"""
reverse = 0
while number > 0:
temp = number % 10
reverse = reverse * 10 + temp
number = number // 10
return reverse
def solution(number: int = 1000000000) -> int:
"""
Loops over the range of numbers.
Checks if they have ending zeros which disqualifies them from being reversible.
If that condition is passed it generates the reversed number.
Then sum up n and reverse(n).
Then check if all the numbers in the sum are odd. If true add to the answer.
>>> solution(1000000000)
608720
>>> solution(1000000)
18720
>>> solution(1000000)
18720
>>> solution(1000)
120
"""
answer = 0
for x in range(1, number):
if x % 10 != 0:
reversed_number = find_reverse_number(x)
sum = x + reversed_number
answer += check_if_odd(sum)
return answer
if __name__ == "__main__":
print(f"{solution() = }")