Improve Project Euler problem 112 solution 1 (#4808)

This commit is contained in:
Maxim Smolskiy
2021-10-06 17:11:50 +03:00
committed by GitHub
parent 629369a34f
commit d654806eae

View File

@ -47,7 +47,9 @@ def check_bouncy(n: int) -> bool:
""" """
if not isinstance(n, int): if not isinstance(n, int):
raise ValueError("check_bouncy() accepts only integer arguments") raise ValueError("check_bouncy() accepts only integer arguments")
return "".join(sorted(str(n))) != str(n) and "".join(sorted(str(n)))[::-1] != str(n) str_n = str(n)
sorted_str_n = "".join(sorted(str_n))
return sorted_str_n != str_n and sorted_str_n[::-1] != str_n
def solution(percent: float = 99) -> int: def solution(percent: float = 99) -> int: