Opening your workspace…
Workspace/Coding room
Opening your workspace…
Take the Planet Express ship to the used-spaceship lot. The Professor promises Fry he'll explain what they're delivering once they're airborne. Leela has a chart of the lot's crusher gates. Each entry [offset, period] means the ship crosses that gate exactly offset seconds after launch, and the gate slams shut at every multiple of period, including time zero. Leela can wait on the pad, but once she launches she can't slow down. Return the smallest whole number of seconds she must wait from time zero to cross every gate while it's open, or -1 if that's impossible. As for the cargo, the Professor left the buyer's receipt in the glove box. It includes the glove box.
[[0,2],[2,3]]Output3The first gate rules out waits of 0 and 2. A wait of 1 puts the ship at the second gate at time 3, just as it shuts. A wait of 3 gives crossing times 3 and 5, when both gates are open.
[[1,2],[2,3]]Output0Launching immediately takes the ship through the first gate at time 1 and the second at time 2. Both are open.
The closure pattern repeats after the least common multiple of all periods.
function solve(gates) { // 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.