Resolve simultaneous moves in a shared aisle
Resolve collisions against a common snapshot instead of iterating one robot at a time.
Your task
Two robots occupy distinct unblocked cells in a one-dimensional aisle. Input has aisle length, walls (blocked cell numbers), positions (two cells, in robot order), and moves (two integers from -1, 0, 1). Compute both proposals from the original positions. A move past an edge or into a wall becomes a stay. If both proposals target the same cell or swap the two starting cells, both robots stay and conflict is true. Otherwise apply both proposals and set conflict to false. Return positions in the original robot order and conflict.
Expected behavior
A robot may follow another into a vacated cell. Both robots stay for conflicting destinations and head-on swaps.
Examples
{"length":5,"walls":[],"positions":[0,2],"moves":[1,-1]}{"positions":[0,2],"conflict":true}{"length":5,"walls":[],"positions":[0,1],"moves":[1,1]}{"positions":[1,2],"conflict":false}{"length":5,"walls":[],"positions":[1,2],"moves":[0,0]}{"positions":[1,2],"conflict":false}Before you begin
- Python functions, lists, and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.