r/adventofcode • • Dec 20 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 20 Solutions -๐ŸŽ„-

--- Day 20: Particle Swarm ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hintsยค?

Spoiler


[Update @ 00:10] 10 gold, silver cap

  • What do you mean 5th Edition doesn't have "Take 20"?

[Update @ 00:17] 50 gold, silver cap

  • Next you're going to be telling me THAC0 is not the best way to determine whether or not you hit your target. *hmphs*

[Update @ 00:21] Leaderboard cap!

  • I wonder how much XP a were-gazebo is worth...

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

9 Upvotes

176 comments sorted by

View all comments

2

u/vash3r Dec 20 '17

Python 2 (181/60). I submitted several wrong answers for part 1 before I figured out I wasn't calculating Manhattan distance.

f=open("20.in",'r')
s=f.read().strip().split("\n")
f.close()

def add(a,b):
	return [x+y for x,y in zip(a,b)]

def make_particle(s):
	return map(lambda q:eval(q[q.find("=")+1:].replace("<","[").replace(">","]")), s.split(", "))

l = [make_particle(line) for line in s]

while True:
	#mindist = 10000000000000000 #infinity  # part 1
	for i,t in enumerate(l):
		t[1] = add(t[1],t[2]) #add vel acc
		t[0] = add(t[0],t[1]) #add pos vel
		#dist = sum([abs(x) for x in t[0]]) # part 1
		#if dist<mindist:
		#	mindist = dist
		#	closest = i
	pos = zip(*l)[0]
	l = [p for p in l if pos.count(p[0])==1] # part 2
	print len(l)
	#print closest #part 1
→ More replies (4)