Reduce iteration by cutting rectangle to circle
Verifying solution... All test cases passed. Use submit solution.py to submit your solution
This commit is contained in:
parent
23b848f68c
commit
10ea977e28
@ -6,7 +6,7 @@ def solution(dimentions, your_position, trainer_position, distance):
|
|||||||
direction = calc_direction(your_position, position)
|
direction = calc_direction(your_position, position)
|
||||||
if direction in nearest_target:
|
if direction in nearest_target:
|
||||||
prev_position, prev_is_trainer = nearest_target[direction]
|
prev_position, prev_is_trainer = nearest_target[direction]
|
||||||
if abs(position[0] - your_position[0]) < abs(prev_position[0] - your_position[0]):
|
if abs(position[0] - your_position[0]) < abs(prev_position[0] - your_position[0]) or abs(position[1] - your_position[1]) < abs(prev_position[1] - your_position[1]):
|
||||||
nearest_target[direction] = (position, is_trainer)
|
nearest_target[direction] = (position, is_trainer)
|
||||||
else:
|
else:
|
||||||
nearest_target[direction] = (position, is_trainer)
|
nearest_target[direction] = (position, is_trainer)
|
||||||
@ -17,9 +17,17 @@ def generate_room_id(dimentions, your_position, distance):
|
|||||||
room_height = dimentions[1]
|
room_height = dimentions[1]
|
||||||
x_range = distance / room_width + 1
|
x_range = distance / room_width + 1
|
||||||
y_range = distance / room_height + 1
|
y_range = distance / room_height + 1
|
||||||
for room_x in range(-x_range, x_range):
|
boundary = {0: y_range + 1}
|
||||||
for room_y in range(-y_range, y_range):
|
for x in range(1, x_range):
|
||||||
yield room_x, room_y
|
while line_length(your_position, (x*room_width, y_range*room_height)) > distance and y_range > 0:
|
||||||
|
y_range -= 1
|
||||||
|
boundary[x] = y_range + 1
|
||||||
|
for x in range(x_range):
|
||||||
|
for y in range(boundary[x]):
|
||||||
|
yield x, y
|
||||||
|
yield x, - y - 1
|
||||||
|
yield - x - 1, y
|
||||||
|
yield - x - 1, - y - 1
|
||||||
|
|
||||||
def generate_positions(dimentions, your_position, trainer_position, distance):
|
def generate_positions(dimentions, your_position, trainer_position, distance):
|
||||||
room_width, room_height = dimentions
|
room_width, room_height = dimentions
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user