@@ -38,27 +38,15 @@ def impossible_count(self, y):
38
38
return len (impossible_x )
39
39
40
40
def distress_tuning (self , min = 0 , max = 4_000_000 ):
41
- possible = {}
42
41
for y in range (min , max + 1 ):
43
- possible [y ] = set ()
44
42
for x in range (min , max + 1 ):
45
- possible [y ].add (x )
46
- for sensor in self .sensors :
47
- if (sensor ['coords' ][1 ] in possible ) and (sensor ['coords' ][0 ] in possible [sensor ['coords' ][1 ]]):
48
- possible [sensor ['coords' ][1 ]].pop (sensor ['coords' ][0 ])
49
- elif (sensor ['closest_beacon' ][1 ] in possible ) and (sensor ['closest_beacon' ][0 ] in possible [sensor ['closest_beacon' ][1 ]]):
50
- possible [sensor ['closest_beacon' ][1 ]].pop (sensor ['closest_beacon' ][0 ])
51
- while True :
52
- y = next (iter (possible .keys ()))
53
- x = next (iter (possible [y ]))
54
- if len (possible ) == 1 and len (possible [y ]) == 1 :
55
- return (x * 4_000_000 ) + y
56
- for sensor in self .sensors :
57
- if ((abs (sensor ['coords' ][0 ] - x ) + abs (sensor ['coords' ][1 ] - y )) <= sensor ['distance' ]
58
- and ((x , y ) not in [s ['coords' ] for s in self .sensors ])
59
- and ((x , y ) not in [s ['closest_beacon' ] for s in self .sensors ])):
60
- possible [y ].pop (x , None )
61
-
43
+ possible = True
44
+ for sensor in self .sensors :
45
+ if (abs (sensor ['coords' ][0 ] - x ) + abs (sensor ['coords' ][1 ] - y )) <= sensor ['distance' ]:
46
+ possible = False
47
+ break
48
+ if possible :
49
+ return (x * 4_000_000 ) + y
62
50
63
51
64
52
def main ():
0 commit comments