File tree 1 file changed +13
-7
lines changed 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change 1
1
from GhostyUtils import aoc
2
- from GhostyUtils .vec2 import Vec2
2
+ from GhostyUtils .vec2 import Vec2 , Dir
3
3
from GhostyUtils .grid import Grid
4
4
from collections import Counter
5
5
import math
@@ -94,18 +94,24 @@ def main():
94
94
most_horz_robots = 0
95
95
best_second = 0
96
96
for s in range (aoc .args .seconds , dimensions .x * dimensions .y ):
97
- horz_robots = [0 ] * dimensions .y
98
97
for robot in robots :
99
98
robot .step (grid )
100
- horz_robots [robot .pos .y ] += 1
101
99
102
- if max (horz_robots ) > most_horz_robots :
103
- most_horz_robots = max (horz_robots )
104
- best_second = s
100
+ robots .sort (key = lambda robot : robot .pos .as_tuple ()[::- 1 ])
101
+ horz_robots = 1
102
+ for r1 , r2 in zip (robots , robots [1 :]):
103
+ if r1 .pos + Dir .RIGHT == r2 .pos :
104
+ horz_robots += 1
105
+ else :
106
+ if horz_robots > most_horz_robots :
107
+ most_horz_robots = horz_robots
108
+ best_second = s + 1
109
+ horz_robots = 1
110
+
105
111
if aoc .args .progress or aoc .args .verbose :
106
112
render_robots (robots , grid , seconds = s + 1 )
107
113
108
- print (f"p2: { best_second } { most_horz_robots } " )
114
+ print (f"p2: { best_second } " )
109
115
110
116
111
117
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments