From e89223eecb7dbb67a45afccfc843b936be3e3efd Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 8 Dec 2021 15:32:04 +0100 Subject: Optimize the condition, thanks Stefan! --- 2020/19/puzzles.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to '2020') diff --git a/2020/19/puzzles.py b/2020/19/puzzles.py index f2a4bcf..abd0df2 100644 --- a/2020/19/puzzles.py +++ b/2020/19/puzzles.py @@ -21,16 +21,11 @@ def check(test: str, patterns: dict[str, list[str]]) -> bool: # 42 = 0, 31 = 1 res = search(r"^(0)+(1)+$", search_str) - return not (not res or search_str.count("0") <= search_str.count("1")) + return res and not search_str.count("0") <= search_str.count("1") def string_divide(string: str, div: int) -> list[str]: - l: list[str] = [] - for i in range(0, len(string), div): - l.append(string[i : i + div]) - return l - - + return [string[i : i + div] for i in range(0, len(string), div)] # END PART 2 -- cgit v1.2.3