diff --git a/day18.py b/day18.py index 62c8ca1..0dbbb8f 100644 --- a/day18.py +++ b/day18.py @@ -17,7 +17,7 @@ class Snailfish: while self.reduce(): pass - def __add__(self, other): + def __add__(self, other: 'Snailfish'): return Snailfish("[%s,%s]" % (self.pairs, other.pairs)) def reduce(self): @@ -65,8 +65,8 @@ class Snailfish: def getMagnitude(self) -> int: pairs = self.pairs - while re_pair.search(pairs): - for num1, num2 in re_pair.findall(pairs): + while match := re_pair.findall(pairs): + for num1, num2 in match: pairs = pairs.replace("[%s,%s]" % (num1, num2), str(int(num1) * 3 + int(num2) * 2)) return int(pairs)