56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
|
#!/bin/python3
|
||
|
import sys,re,math
|
||
|
from pprint import pprint
|
||
|
sys.path.insert(0, '../../')
|
||
|
from fred import get_re,list2int
|
||
|
|
||
|
input_f = 'input'
|
||
|
|
||
|
part = 1
|
||
|
#########################################
|
||
|
# #
|
||
|
# Part 1 #
|
||
|
# #
|
||
|
#########################################
|
||
|
|
||
|
lines = []
|
||
|
|
||
|
if part == 1:
|
||
|
with open(input_f) as file:
|
||
|
for line in file:
|
||
|
lines.append(get_re(r"^p=<(.*)>.*v=<(.*)>.*a=<(.*)>$",line.rstrip()))
|
||
|
|
||
|
#pprint(lines)
|
||
|
|
||
|
magnitude = []
|
||
|
|
||
|
def calculate_magnitude(vector):
|
||
|
return math.sqrt(sum(component ** 2 for component in vector))
|
||
|
|
||
|
def find_slowest_as_time_infinite(vectors):
|
||
|
min_acceleration = float('inf')
|
||
|
slowest_item = None
|
||
|
|
||
|
for i, (_, a) in enumerate(vectors):
|
||
|
acceleration_magnitude = calculate_magnitude(a)
|
||
|
if acceleration_magnitude < min_acceleration:
|
||
|
min_acceleration = acceleration_magnitude
|
||
|
slowest_item = i
|
||
|
|
||
|
return slowest_item
|
||
|
|
||
|
|
||
|
vectors = []
|
||
|
|
||
|
for i in lines:
|
||
|
v = list2int(i.group(2).split(','))
|
||
|
a = list2int(i.group(3).split(','))
|
||
|
vectors.append((v,a))
|
||
|
|
||
|
print(find_slowest_as_time_infinite(vectors))
|
||
|
|
||
|
#########################################
|
||
|
# #
|
||
|
# Part 2 #
|
||
|
# #
|
||
|
#########################################
|