day16: muuuuch nicer code

This commit is contained in:
Stefan Harmuth 2021-12-17 16:39:20 +01:00
parent 23f9d800f8
commit c05092a123

View File

@ -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