From d654806eae5dc6027911424ea828e566a64641fd Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 6 Oct 2021 17:11:50 +0300 Subject: [PATCH] Improve Project Euler problem 112 solution 1 (#4808) --- project_euler/problem_112/sol1.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/project_euler/problem_112/sol1.py b/project_euler/problem_112/sol1.py index d8cb334c9..b3ea6b356 100644 --- a/project_euler/problem_112/sol1.py +++ b/project_euler/problem_112/sol1.py @@ -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: