diff options
author | b-idea <test@test.com> | 2023-10-20 23:22:25 +0200 |
---|---|---|
committer | b-idea <test@test.com> | 2023-10-20 23:22:25 +0200 |
commit | 61073dcec8e896b84fafbd6110e2da55a0dd2d5e (patch) | |
tree | 22f2f3c647f02102974df58f727601e0c66d429e /2018/aoc2018-d23-p1.py | |
parent | 5b8623d06472ec9a4bcac8ea1e201b7ae528d7af (diff) |
added days: 15_p1, 17, 20, 21, 22, 23_p1, 24, 25
Diffstat (limited to '2018/aoc2018-d23-p1.py')
-rw-r--r-- | 2018/aoc2018-d23-p1.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/2018/aoc2018-d23-p1.py b/2018/aoc2018-d23-p1.py new file mode 100644 index 0000000..a387337 --- /dev/null +++ b/2018/aoc2018-d23-p1.py @@ -0,0 +1,47 @@ +#advent of code 2018 +#day 23 +#part 1 and part 2 + + +f = open("input.txt",'r'); +Testing = False; +#Testing = True; +if Testing: + f.close(); + f = open("testinput.txt",'r'); + +def manhattan(pos1, pos2): + mx = abs(pos1[0] - pos2[0]); + my = abs(pos1[1] - pos2[1]); + mz = abs(pos1[2] - pos2[2]); + return mx + my + mz; + +class nanobot: + def __init__(self, pos, r): + self.pos = pos; + self.radius = r; + def __str__(self): + return f'pos={self.pos}, r={self.radius}'; + +bots = []; +for l in f: + l = l.replace("<","("); + l = l.replace(">",")"); + l = l.replace("r=",""); + l = l.replace("pos=",""); + p, r = eval(l); + bots.append(nanobot(p,r)); + +f.close(); + +strongest_radius = 0; +strongest_pos = None; +for bot in bots: + if bot.radius > strongest_radius: + strongest_radius = bot.radius; + strongest_pos = bot.pos; + +part1 = 0; +for bot in bots: + if (manhattan(strongest_pos, bot.pos) <= strongest_radius): part1 += 1; +print("part1 = ", part1); |