AdventOfCode/2017/20/solution.py

68 lines
1.8 KiB
Python
Raw Normal View History

2024-11-28 15:10:22 +01:00
#!/bin/python3
import sys,re,math
from pprint import pprint
sys.path.insert(0, '../../')
from fred import get_re,list2int
input_f = 'input'
2024-11-28 22:48:07 +01:00
part = 2
2024-11-28 15:10:22 +01:00
#########################################
# #
# 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()))
2024-11-28 22:48:07 +01:00
min_acc = float('inf')
acc_idx = 0
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
for idx,i in enumerate(lines):
tmp = math.sqrt(sum(component ** 2 for component in list2int(i.group(3).split(','))))
if tmp < min_acc:
min_acc = tmp
acc_idx = idx
print(acc_idx)
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
#########################################
# #
# Part 2 #
# #
#########################################
if part == 2:
continue
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
#pprint(lines)
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
# magnitude = []
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
# def calculate_magnitude(vector):
# return math.sqrt(sum(component ** 2 for component in vector))
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
# def find_slowest_as_time_infinite(vectors):
# min_acceleration = float('inf')
# slowest_item = None
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
# 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
2024-11-28 15:10:22 +01:00
2024-11-28 22:48:07 +01:00
# 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))