From 1180c8b9e19bdfa2e13fc5063aba639e6ee0640d Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 2 Dec 2021 10:01:14 +0100 Subject: Use python3.10 pattern matching --- 2015/21/puzzles.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/2015/21/puzzles.py b/2015/21/puzzles.py index 48e8c4e..d355c77 100644 --- a/2015/21/puzzles.py +++ b/2015/21/puzzles.py @@ -38,12 +38,13 @@ def wins(d: int, hp: int) -> bool: def valid(e: tuple[tuple[str, int, int, int], ...]) -> bool: w = a = r = 0 for i in e: - if i[0] == "Weapon": - w += 1 - elif i[0] == "Armor": - a += 1 - elif i[0] == "Ring": - r += 1 + match i[0]: + case "Weapon": + w += 1 + case "Armor": + a += 1 + case "Ring": + r += 1 return (w == 1) and (a <= 1) and (r <= 2) -- cgit v1.2.3