aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-03 10:12:14 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-03 10:12:14 +0100
commitcacd416845e12bde1840508532474cb45e50a334 (patch)
treeddf2ae82749c6d46ddba7c3feb6e4464fe5f9167
parent49329c308630de66cd911edfe759ee82e8f084b5 (diff)
Remove the `while True` loop
-rwxr-xr-x2021/03/puzzle-2.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/2021/03/puzzle-2.py b/2021/03/puzzle-2.py
index 55513dd..103c64a 100755
--- a/2021/03/puzzle-2.py
+++ b/2021/03/puzzle-2.py
@@ -5,18 +5,19 @@ from typing import Callable
def solve(lines: list[str], comp: Callable[[int, int], bool]) -> int:
- while True:
- for i in range(len(lines[0])):
- if len(lines) == 1:
- return int(lines[0], 2)
-
- if comp(
- len([line for line in lines if line[i] == "0"]),
- len([line for line in lines if line[i] == "1"]),
- ):
- lines = [line for line in lines if line[i] == "0"]
- else:
- lines = [line for line in lines if line[i] == "1"]
+ for i in range(len(lines[0])):
+ if len(lines) == 1:
+ break
+
+ if comp(
+ len([line for line in lines if line[i] == "0"]),
+ len([line for line in lines if line[i] == "1"]),
+ ):
+ lines = [line for line in lines if line[i] == "0"]
+ else:
+ lines = [line for line in lines if line[i] == "1"]
+
+ return int(lines[0], 2)
def main() -> None: