This commit is contained in:
Luke Hubmayer-Werner 2022-12-20 23:33:39 +10:30
parent 51b30d3ed2
commit bba2db3b17
1 changed files with 9 additions and 10 deletions

View File

@ -28,21 +28,20 @@ def mix(numbers: list[int], n=1):
queue.append(v) queue.append(v)
return [v for i,v in queue] 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: def p1(lines: list[str]) -> str:
N = len(lines)
numbers = [int(x) for x in lines] numbers = [int(x) for x in lines]
final_queue = mix(numbers) coords = get_coords(mix(numbers))
i = final_queue.index(0) return f'coords: {coords} have sum {sum(coords)}'
values = (final_queue[(i+1000)%N], final_queue[(i+2000)%N], final_queue[(i+3000)%N])
return f'coords: {values} have sum {sum(values)}'
def p2(lines: list[str]) -> str: def p2(lines: list[str]) -> str:
N = len(lines)
numbers = [int(x)*811589153 for x in lines] numbers = [int(x)*811589153 for x in lines]
final_queue = mix(numbers, 10) coords = get_coords(mix(numbers, 10))
i = final_queue.index(0) return f'coords: {coords} have sum {sum(coords)}'
values = (final_queue[(i+1000)%N], final_queue[(i+2000)%N], final_queue[(i+3000)%N])
return f'coords: {values} have sum {sum(values)}'
print(f'Part 1 (sample): {p1(sample_lines)}') print(f'Part 1 (sample): {p1(sample_lines)}')
print(f'Part 1: {p1(lines)}') print(f'Part 1: {p1(lines)}')