Opening your workspace…
Workspace/Coding room
Opening your workspace…
Pac-Man eats a power pellet and chases a frightened ghost around a tunnel loop. The tiles are numbered from 0 to size − 1, with tile 0 next to tile size − 1. Each tick, the ghost moves first according to the next character in moves. Pac-Man sees the move, then must move one tile left or right. He eats the ghost if they end the tick on the same tile. Return the earliest tick when Pac-Man can eat it, counting from 1. The power pellet wears off after the last tick in moves. Return -1 if the ghost escapes.
8, 0, 6, "RLL"Output1The ghost moves right to tile 7. Pac-Man goes left through the tunnel from 0 to 7 and eats it.
10, 0, 4, "RLL"Output3The ghost visits tiles 5, 4, and 3. Pac-Man cannot reach 5 on tick 1 or 4 on tick 2. By going right three times, he reaches tile 3 on tick 3.
A displacement around the ring must be reachable with exactly the given number of steps, including parity.
function solve(size, pacman, ghost, moves) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.