day16: muuuuch nicer code
This commit is contained in:
parent
23f9d800f8
commit
c05092a123
8
day16.py
8
day16.py
@ -1,6 +1,6 @@
|
|||||||
from math import prod
|
from math import prod
|
||||||
from tools.aoc import AOCDay
|
from tools.aoc import AOCDay
|
||||||
from typing import Any, List
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class Packet:
|
class Packet:
|
||||||
@ -15,11 +15,11 @@ class Packet:
|
|||||||
|
|
||||||
def __parse(self):
|
def __parse(self):
|
||||||
if self.p_type == 4:
|
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.value = self.value * 16 + int(self.packet_str[self.p_len + 1:self.p_len + 5], 2)
|
||||||
self.p_len += 5
|
self.p_len += 5
|
||||||
self.value = self.value * 16 + int(self.packet_str[self.p_len + 1:self.p_len + 5], 2)
|
if self.packet_str[self.p_len - 5] == "0":
|
||||||
self.p_len += 5
|
break
|
||||||
else:
|
else:
|
||||||
op_type = self.packet_str[self.p_len]
|
op_type = self.packet_str[self.p_len]
|
||||||
self.p_len += 1
|
self.p_len += 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user