Update day 16 solution
This commit is contained in:
@@ -73,38 +73,23 @@ def calc_result(packets):
|
||||
return res
|
||||
|
||||
|
||||
def part_1(input):
|
||||
result = 0
|
||||
def solve(input):
|
||||
result_p1 = 0
|
||||
line = input[0].rstrip().strip('0')
|
||||
msg = bin(int(line, 16))
|
||||
msg = msg[2:]
|
||||
while len(msg) % 4:
|
||||
msg = bin(int(line, 16))[2:]
|
||||
while len(msg) < len(line) * 4:
|
||||
msg = '0' + msg
|
||||
packets = []
|
||||
next = 0
|
||||
while -1 != next:
|
||||
next, result = get_next_packet(msg, next, packets, result)
|
||||
print("Part 1 result:", result)
|
||||
|
||||
|
||||
def part_2(input):
|
||||
result = 0
|
||||
line = input[0].rstrip().strip('0')
|
||||
msg = bin(int(line, 16))
|
||||
msg = msg[2:]
|
||||
while len(msg) % 4:
|
||||
msg = '0' + msg
|
||||
packets = []
|
||||
next = 0
|
||||
while -1 != next:
|
||||
next, _ = get_next_packet(msg, next, packets)
|
||||
result = calc_result(packets)
|
||||
print("Part 2 result:", result)
|
||||
next, result_p1 = get_next_packet(msg, next, packets, result_p1)
|
||||
result_p2 = calc_result(packets)
|
||||
print("Part 1 result:", result_p1)
|
||||
print("Part 2 result:", result_p2)
|
||||
|
||||
|
||||
input = list()
|
||||
p = Path(__file__).with_name('input.txt')
|
||||
with open(p) as f:
|
||||
input = f.readlines()
|
||||
part_1(input)
|
||||
part_2(input)
|
||||
solve(input)
|
||||
|
||||
Reference in New Issue
Block a user