day14 - sub 1s

This commit is contained in:
Stefan Harmuth 2024-12-14 09:04:13 +01:00
parent 9aecc95f30
commit d1ccb8222c

View File

@ -48,26 +48,17 @@ class Day(AOCDay):
def part2(self) -> Any: def part2(self) -> Any:
robots = self.parse_input() robots = self.parse_input()
num_robots = len(robots)
count = 0 count = 0
while True: while True:
count += 1 count += 1
_, new_robots = self.move_robots(robots, steps=1) _, robots = self.move_robots(robots, steps=1)
g = Grid()
for robot in new_robots:
g.set(Coordinate(robot[0][0], robot[0][1]))
found = False # We assume, there is only one case where no robots overlap
for c in g.getActiveCells(): if len(set(x[0] for x in robots)) == num_robots:
if len(set(g.getRegion(c))) > 50:
found = True
break
if found:
break break
robots = new_robots
return count return count