From bba2db3b1711bb60ba92e2a0e2d52729091e6002 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Tue, 20 Dec 2022 23:33:39 +1030 Subject: [PATCH] clean up --- 2022/day20.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/2022/day20.py b/2022/day20.py index 0f506f6..5bff465 100644 --- a/2022/day20.py +++ b/2022/day20.py @@ -28,21 +28,20 @@ def mix(numbers: list[int], n=1): queue.append(v) return [v for i,v in queue] +def get_coords(numbers: list[int]) -> tuple[int,int,int]: + N = len(numbers) + i = numbers.index(0) + return (numbers[(i+1000)%N], numbers[(i+2000)%N], numbers[(i+3000)%N]) + def p1(lines: list[str]) -> str: - N = len(lines) numbers = [int(x) for x in lines] - final_queue = mix(numbers) - i = final_queue.index(0) - values = (final_queue[(i+1000)%N], final_queue[(i+2000)%N], final_queue[(i+3000)%N]) - return f'coords: {values} have sum {sum(values)}' + coords = get_coords(mix(numbers)) + return f'coords: {coords} have sum {sum(coords)}' def p2(lines: list[str]) -> str: - N = len(lines) numbers = [int(x)*811589153 for x in lines] - final_queue = mix(numbers, 10) - i = final_queue.index(0) - values = (final_queue[(i+1000)%N], final_queue[(i+2000)%N], final_queue[(i+3000)%N]) - return f'coords: {values} have sum {sum(values)}' + coords = get_coords(mix(numbers, 10)) + return f'coords: {coords} have sum {sum(coords)}' print(f'Part 1 (sample): {p1(sample_lines)}') print(f'Part 1: {p1(lines)}')