A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/wimglenn/advent-of-code-wim/commit/31e454270001c6d06b46014fe5dafd03e29507b8 below:

fix algorithm · wimglenn/advent-of-code-wim@31e4542 · GitHub

File tree Expand file treeCollapse file tree 1 file changed

+19

-2

lines changed

Filter options

Expand file treeCollapse file tree 1 file changed

+19

-2

lines changed Original file line number Diff line number Diff line change

@@ -15,7 +15,7 @@

15 15

p=<3,0,0>, v=<-1,0,0>, a=<0,0,0>

16 16

"""

17 17 18 -

template = 'p=<{:d},{:d},{:d}>, v=<{:d},{:d},{:d}>, a=<{:d},{:d},{:d}>'

18 +

template = "p=<{:d},{:d},{:d}>, v=<{:d},{:d},{:d}>, a=<{:d},{:d},{:d}>"

19 19 20 20 21 21

def parsed(data):

@@ -26,10 +26,27 @@ def key(p):

26 26

return [abs(x) + abs(y) + abs(z) for x, y, z in chunks(reversed(p), 3)]

27 27 28 28 29 +

def abs_accel(p):

30 +

px, py, pz, vx, vy, vz, ax, ay, az = p

31 +

a = abs(ax) + abs(ay) + abs(az)

32 +

return a

33 + 34 + 35 +

def pos(p0, t):

36 +

px0, py0, pz0, vx0, vy0, vz0, ax0, ay0, az0 = p0

37 +

px1 = px0 + vx0 * t + (ax0 * t ** 2) // 2

38 +

py1 = py0 + vy0 * t + (ay0 * t ** 2) // 2

39 +

pz1 = pz0 + vz0 * t + (az0 * t ** 2) // 2

40 +

d = abs(px1) + abs(py1) + abs(pz1)

41 +

return d

42 + 43 + 29 44

def part_a(data):

30 45

particles = parsed(data)

31 46

p_min = min(particles, key=key)

32 -

return particles.index(p_min)

47 +

a_min = abs_accel(p_min)

48 +

d = {i: pos(p, 100) for i, p in enumerate(particles) if abs_accel(p) == a_min}

49 +

return min(d, key=d.get)

33 50 34 51 35 52

def part_b(data):

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4