Simplified 2027/20 part 1
This commit is contained in:
parent
38567d32ab
commit
bb50af5bbf
@ -6,7 +6,7 @@ from fred import get_re,list2int
|
|||||||
|
|
||||||
input_f = 'input'
|
input_f = 'input'
|
||||||
|
|
||||||
part = 1
|
part = 2
|
||||||
#########################################
|
#########################################
|
||||||
# #
|
# #
|
||||||
# Part 1 #
|
# Part 1 #
|
||||||
@ -19,38 +19,49 @@ if part == 1:
|
|||||||
with open(input_f) as file:
|
with open(input_f) as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
lines.append(get_re(r"^p=<(.*)>.*v=<(.*)>.*a=<(.*)>$",line.rstrip()))
|
lines.append(get_re(r"^p=<(.*)>.*v=<(.*)>.*a=<(.*)>$",line.rstrip()))
|
||||||
|
|
||||||
#pprint(lines)
|
|
||||||
|
|
||||||
magnitude = []
|
min_acc = float('inf')
|
||||||
|
acc_idx = 0
|
||||||
|
|
||||||
def calculate_magnitude(vector):
|
for idx,i in enumerate(lines):
|
||||||
return math.sqrt(sum(component ** 2 for component in vector))
|
tmp = math.sqrt(sum(component ** 2 for component in list2int(i.group(3).split(','))))
|
||||||
|
if tmp < min_acc:
|
||||||
def find_slowest_as_time_infinite(vectors):
|
min_acc = tmp
|
||||||
min_acceleration = float('inf')
|
acc_idx = idx
|
||||||
slowest_item = None
|
print(acc_idx)
|
||||||
|
|
||||||
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 #
|
# Part 2 #
|
||||||
# #
|
# #
|
||||||
#########################################
|
#########################################
|
||||||
|
if part == 2:
|
||||||
|
continue
|
||||||
|
|
||||||
|
#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))
|
||||||
|
Loading…
Reference in New Issue
Block a user