mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 17:20:16 +00:00
4d0a8f2355
* optimized recursive_bubble_sort * Fixed doctest error due whitespace * reduce loop times for optimization * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
30 lines
678 B
Python
30 lines
678 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
module to operations with prime numbers
|
|
"""
|
|
|
|
|
|
def check_prime(number):
|
|
"""
|
|
it's not the best solution
|
|
"""
|
|
special_non_primes = [0, 1, 2]
|
|
if number in special_non_primes[:2]:
|
|
return 2
|
|
elif number == special_non_primes[-1]:
|
|
return 3
|
|
|
|
return all([number % i for i in range(2, number)])
|
|
|
|
|
|
def next_prime(value, factor=1, **kwargs):
|
|
value = factor * value
|
|
first_value_val = value
|
|
|
|
while not check_prime(value):
|
|
value += 1 if not ("desc" in kwargs.keys() and kwargs["desc"] is True) else -1
|
|
|
|
if value == first_value_val:
|
|
return next_prime(value + 1, **kwargs)
|
|
return value
|