Added 2017/20
This commit is contained in:
parent
81990b5833
commit
99982f4fb9
@ -53,7 +53,49 @@ particle `0`, and so, in the long run, particle `0` will stay closest.
|
||||
*Which particle will stay closest to position `<0,0,0>`* in the long
|
||||
term?
|
||||
|
||||
To begin, [get your puzzle input](20/input).
|
||||
Your puzzle answer was `258`.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: \*
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
To simplify the problem further, the GPU would like to remove any
|
||||
particles that *collide*. Particles collide if their positions ever
|
||||
*exactly match*. Because particles are updated simultaneously, *more
|
||||
than two particles* can collide at the same time and place. Once
|
||||
particles collide, they are removed and cannot collide with anything
|
||||
else after that tick.
|
||||
|
||||
For example:
|
||||
|
||||
p=<-6,0,0>, v=< 3,0,0>, a=< 0,0,0>
|
||||
p=<-4,0,0>, v=< 2,0,0>, a=< 0,0,0> -6 -5 -4 -3 -2 -1 0 1 2 3
|
||||
p=<-2,0,0>, v=< 1,0,0>, a=< 0,0,0> (0) (1) (2) (3)
|
||||
p=< 3,0,0>, v=<-1,0,0>, a=< 0,0,0>
|
||||
|
||||
p=<-3,0,0>, v=< 3,0,0>, a=< 0,0,0>
|
||||
p=<-2,0,0>, v=< 2,0,0>, a=< 0,0,0> -6 -5 -4 -3 -2 -1 0 1 2 3
|
||||
p=<-1,0,0>, v=< 1,0,0>, a=< 0,0,0> (0)(1)(2) (3)
|
||||
p=< 2,0,0>, v=<-1,0,0>, a=< 0,0,0>
|
||||
|
||||
p=< 0,0,0>, v=< 3,0,0>, a=< 0,0,0>
|
||||
p=< 0,0,0>, v=< 2,0,0>, a=< 0,0,0> -6 -5 -4 -3 -2 -1 0 1 2 3
|
||||
p=< 0,0,0>, v=< 1,0,0>, a=< 0,0,0> X (3)
|
||||
p=< 1,0,0>, v=<-1,0,0>, a=< 0,0,0>
|
||||
|
||||
------destroyed by collision------
|
||||
------destroyed by collision------ -6 -5 -4 -3 -2 -1 0 1 2 3
|
||||
------destroyed by collision------ (3)
|
||||
p=< 0,0,0>, v=<-1,0,0>, a=< 0,0,0>
|
||||
|
||||
In this example, particles `0`, `1`, and `2` are simultaneously
|
||||
destroyed at the time and place marked `X`. On the next tick, particle
|
||||
`3` passes through unharmed.
|
||||
|
||||
*How many particles are left* after all collisions are resolved?
|
||||
|
||||
Answer:
|
||||
|
||||
Although it hasn\'t changed, you can still [get your puzzle
|
||||
input](20/input).
|
||||
|
||||
|
56
2017/20/solution.py
Normal file
56
2017/20/solution.py
Normal file
@ -0,0 +1,56 @@
|
||||
#!/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 #
|
||||
# #
|
||||
#########################################
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user