generated from public/aoc_template
day14 - sub 1s
This commit is contained in:
parent
9aecc95f30
commit
d1ccb8222c
17
day14.py
17
day14.py
@ -48,26 +48,17 @@ class Day(AOCDay):
|
||||
|
||||
def part2(self) -> Any:
|
||||
robots = self.parse_input()
|
||||
num_robots = len(robots)
|
||||
|
||||
count = 0
|
||||
while True:
|
||||
count += 1
|
||||
_, new_robots = self.move_robots(robots, steps=1)
|
||||
g = Grid()
|
||||
for robot in new_robots:
|
||||
g.set(Coordinate(robot[0][0], robot[0][1]))
|
||||
_, robots = self.move_robots(robots, steps=1)
|
||||
|
||||
found = False
|
||||
for c in g.getActiveCells():
|
||||
if len(set(g.getRegion(c))) > 50:
|
||||
found = True
|
||||
break
|
||||
|
||||
if found:
|
||||
# We assume, there is only one case where no robots overlap
|
||||
if len(set(x[0] for x in robots)) == num_robots:
|
||||
break
|
||||
|
||||
robots = new_robots
|
||||
|
||||
return count
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user