mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-30 22:23:42 +00:00
Merge branch 'TheAlgorithms:master' into game_of_life_tests
This commit is contained in:
commit
ff2b4e2705
|
@ -16,7 +16,7 @@ repos:
|
||||||
- id: auto-walrus
|
- id: auto-walrus
|
||||||
|
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.6.9
|
rev: v0.7.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
|
@ -29,7 +29,7 @@ repos:
|
||||||
- tomli
|
- tomli
|
||||||
|
|
||||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
- repo: https://github.com/tox-dev/pyproject-fmt
|
||||||
rev: "2.3.0"
|
rev: "2.4.3"
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyproject-fmt
|
- id: pyproject-fmt
|
||||||
|
|
||||||
|
@ -42,12 +42,12 @@ repos:
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
|
|
||||||
- repo: https://github.com/abravalheri/validate-pyproject
|
- repo: https://github.com/abravalheri/validate-pyproject
|
||||||
rev: v0.20.2
|
rev: v0.21
|
||||||
hooks:
|
hooks:
|
||||||
- id: validate-pyproject
|
- id: validate-pyproject
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v1.11.2
|
rev: v1.12.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
args:
|
args:
|
||||||
|
|
|
@ -24,7 +24,7 @@ from functools import lru_cache
|
||||||
def unique_prime_factors(n: int) -> set:
|
def unique_prime_factors(n: int) -> set:
|
||||||
"""
|
"""
|
||||||
Find unique prime factors of an integer.
|
Find unique prime factors of an integer.
|
||||||
Tests include sorting because only the set really matters,
|
Tests include sorting because only the set matters,
|
||||||
not the order in which it is produced.
|
not the order in which it is produced.
|
||||||
>>> sorted(set(unique_prime_factors(14)))
|
>>> sorted(set(unique_prime_factors(14)))
|
||||||
[2, 7]
|
[2, 7]
|
||||||
|
@ -58,7 +58,7 @@ def upf_len(num: int) -> int:
|
||||||
|
|
||||||
def equality(iterable: list) -> bool:
|
def equality(iterable: list) -> bool:
|
||||||
"""
|
"""
|
||||||
Check equality of ALL elements in an iterable
|
Check the equality of ALL elements in an iterable
|
||||||
>>> equality([1, 2, 3, 4])
|
>>> equality([1, 2, 3, 4])
|
||||||
False
|
False
|
||||||
>>> equality([2, 2, 2, 2])
|
>>> equality([2, 2, 2, 2])
|
||||||
|
@ -69,7 +69,7 @@ def equality(iterable: list) -> bool:
|
||||||
return len(set(iterable)) in (0, 1)
|
return len(set(iterable)) in (0, 1)
|
||||||
|
|
||||||
|
|
||||||
def run(n: int) -> list:
|
def run(n: int) -> list[int]:
|
||||||
"""
|
"""
|
||||||
Runs core process to find problem solution.
|
Runs core process to find problem solution.
|
||||||
>>> run(3)
|
>>> run(3)
|
||||||
|
@ -77,7 +77,7 @@ def run(n: int) -> list:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Incrementor variable for our group list comprehension.
|
# Incrementor variable for our group list comprehension.
|
||||||
# This serves as the first number in each list of values
|
# This is the first number in each list of values
|
||||||
# to test.
|
# to test.
|
||||||
base = 2
|
base = 2
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ def run(n: int) -> list:
|
||||||
# Increment each value of a generated range
|
# Increment each value of a generated range
|
||||||
group = [base + i for i in range(n)]
|
group = [base + i for i in range(n)]
|
||||||
|
|
||||||
# Run elements through out unique_prime_factors function
|
# Run elements through the unique_prime_factors function
|
||||||
# Append our target number to the end.
|
# Append our target number to the end.
|
||||||
checker = [upf_len(x) for x in group]
|
checker = [upf_len(x) for x in group]
|
||||||
checker.append(n)
|
checker.append(n)
|
||||||
|
@ -98,7 +98,7 @@ def run(n: int) -> list:
|
||||||
base += 1
|
base += 1
|
||||||
|
|
||||||
|
|
||||||
def solution(n: int = 4) -> int:
|
def solution(n: int = 4) -> int | None:
|
||||||
"""Return the first value of the first four consecutive integers to have four
|
"""Return the first value of the first four consecutive integers to have four
|
||||||
distinct prime factors each.
|
distinct prime factors each.
|
||||||
>>> solution()
|
>>> solution()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user