day16: don't play with strings when calculating values ...
This commit is contained in:
parent
09d316941e
commit
c527de2e10
8
day16.py
8
day16.py
@ -80,12 +80,12 @@ def get_value(packet: str) -> int:
|
||||
return max(get_value(p) for p in get_subpackages(this_packet))
|
||||
elif pkg_type == 4:
|
||||
index = 6
|
||||
pkg_bits = ""
|
||||
value = 0
|
||||
while this_packet[index] == "1":
|
||||
pkg_bits += this_packet[index + 1:index + 5]
|
||||
value = value * 16 + int(this_packet[index + 1:index + 5], 2)
|
||||
index += 5
|
||||
pkg_bits += this_packet[index + 1:index + 5]
|
||||
return int(pkg_bits, 2)
|
||||
value = value * 16 + int(this_packet[index + 1:index + 5], 2)
|
||||
return value
|
||||
elif pkg_type == 5:
|
||||
sub_pkg = get_subpackages(this_packet)
|
||||
return get_value(sub_pkg[0]) > get_value(sub_pkg[1])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user