From 3718e83b5de3f570060c67430ee725b788ac9084 Mon Sep 17 00:00:00 2001 From: Stegallo Date: Sun, 5 Nov 2023 20:30:22 -0800 Subject: [PATCH 1/2] simplify day5 --- y_2015/day5.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/y_2015/day5.py b/y_2015/day5.py index 3ee3a5b..41d5d6e 100644 --- a/y_2015/day5.py +++ b/y_2015/day5.py @@ -38,19 +38,18 @@ def nice(self) -> bool: def __has_pair_twice(self) -> bool: twice_pair = False - for c in range(len(self.text) - 2): - for j in range(c + 2, len(self.text) - 1): - if self.text[c : c + 2] == self.text[j : j + 2]: + len_text = len(self.text) + for i in range(len_text - 2): + for j in range(i + 2, len_text - 1): + if self.text[i : i + 2] == self.text[j : j + 2]: twice_pair = True break return bool(twice_pair) def __has_letter_repeats_with_one_between(self) -> bool: letter_repeat = False - for c, i in enumerate(self.text): - if c >= len(self.text) - 2: - break - if self.text[c] == self.text[c + 2]: + for i in range(len(self.text) - 2): + if self.text[i] == self.text[i + 2]: letter_repeat = True break return bool(letter_repeat) From 970e4aa5bd9addc504e10180aab06687c189fad6 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Mon, 6 Nov 2023 04:31:52 +0000 Subject: [PATCH 2/2] 'Refactored by Sourcery' --- y_2015/day5.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/y_2015/day5.py b/y_2015/day5.py index 41d5d6e..5849db8 100644 --- a/y_2015/day5.py +++ b/y_2015/day5.py @@ -47,12 +47,7 @@ def __has_pair_twice(self) -> bool: return bool(twice_pair) def __has_letter_repeats_with_one_between(self) -> bool: - letter_repeat = False - for i in range(len(self.text) - 2): - if self.text[i] == self.text[i + 2]: - letter_repeat = True - break - return bool(letter_repeat) + return any(self.text[i] == self.text[i + 2] for i in range(len(self.text) - 2)) @property def correct_nice(self) -> bool: