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)}')