mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 10:31:29 +08:00
refactor: Move constants outside of variable scope (#7262)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
@ -185,12 +185,12 @@ def test_compare_random(hand, other, expected):
|
||||
|
||||
|
||||
def test_hand_sorted():
|
||||
POKER_HANDS = [PokerHand(hand) for hand in SORTED_HANDS] # noqa: N806
|
||||
list_copy = POKER_HANDS.copy()
|
||||
poker_hands = [PokerHand(hand) for hand in SORTED_HANDS]
|
||||
list_copy = poker_hands.copy()
|
||||
shuffle(list_copy)
|
||||
user_sorted = chain(sorted(list_copy))
|
||||
for index, hand in enumerate(user_sorted):
|
||||
assert hand == POKER_HANDS[index]
|
||||
assert hand == poker_hands[index]
|
||||
|
||||
|
||||
def test_custom_sort_five_high_straight():
|
||||
|
@ -33,13 +33,13 @@ def continuous_fraction_period(n: int) -> int:
|
||||
"""
|
||||
numerator = 0.0
|
||||
denominator = 1.0
|
||||
ROOT = int(sqrt(n)) # noqa: N806
|
||||
integer_part = ROOT
|
||||
root = int(sqrt(n))
|
||||
integer_part = root
|
||||
period = 0
|
||||
while integer_part != 2 * ROOT:
|
||||
while integer_part != 2 * root:
|
||||
numerator = denominator * integer_part - numerator
|
||||
denominator = (n - numerator**2) / denominator
|
||||
integer_part = int((ROOT + numerator) / denominator)
|
||||
integer_part = int((root + numerator) / denominator)
|
||||
period += 1
|
||||
return period
|
||||
|
||||
|
@ -34,9 +34,9 @@ def solution(n: int = 10) -> str:
|
||||
"""
|
||||
if not isinstance(n, int) or n < 0:
|
||||
raise ValueError("Invalid input")
|
||||
MODULUS = 10**n # noqa: N806
|
||||
NUMBER = 28433 * (pow(2, 7830457, MODULUS)) + 1 # noqa: N806
|
||||
return str(NUMBER % MODULUS)
|
||||
modulus = 10**n
|
||||
number = 28433 * (pow(2, 7830457, modulus)) + 1
|
||||
return str(number % modulus)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -13,6 +13,8 @@ Find the sum of all the numbers less than 10^8 that are both palindromic and can
|
||||
be written as the sum of consecutive squares.
|
||||
"""
|
||||
|
||||
LIMIT = 10**8
|
||||
|
||||
|
||||
def is_palindrome(n: int) -> bool:
|
||||
"""
|
||||
@ -35,7 +37,6 @@ def solution() -> int:
|
||||
Returns the sum of all numbers less than 1e8 that are both palindromic and
|
||||
can be written as the sum of consecutive squares.
|
||||
"""
|
||||
LIMIT = 10**8 # noqa: N806
|
||||
answer = set()
|
||||
first_square = 1
|
||||
sum_squares = 5
|
||||
|
Reference in New Issue
Block a user