-
-
Save pawlos/2dbbe0fb1e227b4468e34a0fddea2bbf to your computer and use it in GitHub Desktop.
Solution to Day 20: Particle Swarm - Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#aoc_d20.py | |
inp = open('input_d20.txt').readlines() | |
import re | |
data = {} | |
idx = 0 | |
for i in inp: | |
m = re.match("p=<(-?\d+),(-?\d+),(-?\d+)>,\sv=<(-?\d+),(-?\d+),(-?\d+)>,\sa=<(-?\d+),(-?\d+),(-?\d+)>",i) | |
data[idx] = {'px':int(m.group(1)),'py':int(m.group(2)),'pz':int(m.group(3)), | |
'vx':int(m.group(4)),'vy':int(m.group(5)),'vz':int(m.group(6)), | |
'ax':int(m.group(7)),'ay':int(m.group(8)),'az':int(m.group(9))} | |
idx += 1 | |
distances = {} | |
r = 0 | |
br = int(input('Podaj breaker: ')) | |
while True: | |
if r > br: | |
break | |
r += 1 | |
for k,v in data.items(): | |
v['vx'] += v['ax'] | |
v['vy'] += v['ay'] | |
v['vz'] += v['az'] | |
v['px'] += v['vx'] | |
v['py'] += v['vy'] | |
v['pz'] += v['vz'] | |
new_data = {} | |
for k,v in data.items(): | |
add = True | |
for k2,v2 in data.items(): | |
if k == k2: | |
continue | |
if v['px'] == v2['px'] and v['py'] == v2['py'] and v['pz'] == v2['pz']: | |
add = False | |
break | |
if add: | |
new_data[k] = v | |
data = new_data | |
print 'Survived: ',len(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment