clean up
This commit is contained in:
parent
51b30d3ed2
commit
bba2db3b17
|
@ -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)}')
|
||||||
|
|
Loading…
Reference in New Issue