From c05092a1237a963ace27762750f9f03ba6dd2baf Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Fri, 17 Dec 2021 16:39:20 +0100 Subject: [PATCH] day16: muuuuch nicer code --- day16.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/day16.py b/day16.py index 373dc9c..cd3f5a2 100644 --- a/day16.py +++ b/day16.py @@ -1,6 +1,6 @@ from math import prod from tools.aoc import AOCDay -from typing import Any, List +from typing import Any class Packet: @@ -15,11 +15,11 @@ class Packet: def __parse(self): if self.p_type == 4: - while self.packet_str[self.p_len] == "1": + while True: self.value = self.value * 16 + int(self.packet_str[self.p_len + 1:self.p_len + 5], 2) self.p_len += 5 - self.value = self.value * 16 + int(self.packet_str[self.p_len + 1:self.p_len + 5], 2) - self.p_len += 5 + if self.packet_str[self.p_len - 5] == "0": + break else: op_type = self.packet_str[self.p_len] self.p_len += 1