From c365cc5b642ccd058bdb05b802a15223495f9f9c Mon Sep 17 00:00:00 2001 From: Pascal Lais Date: Thu, 16 Dec 2021 16:41:06 +0100 Subject: [PATCH] Update day 16 solution --- day-16/day-16.py | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/day-16/day-16.py b/day-16/day-16.py index 1ecf1d2..4c42f22 100644 --- a/day-16/day-16.py +++ b/day-16/day-16.py @@ -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)