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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,9 @@ def check_bouncy(n: int) -> bool:
"""
if not isinstance(n, int):
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: