Opening your workspace…
Workspace/Coding room
Opening your workspace…
You only meant to buy a lamp, but the IKEA has no walls and every doorway leads to another numbered showroom. You start in showroom 1. From showroom n, one door leads to n + 1, and a blue shortcut door leads to showroom 2n. Your shopping list is in showroom target; find the fewest doorways you must pass through to reach it.
1Output0You are already in showroom 1, so you do not need to pass through a doorway.
7Output4One shortest route is 1 -> 2 -> 3 -> 6 -> 7: three shortcut or forward moves, then one final forward move, for four doors total.
Trace the route backward. A halving step can replace many single steps.
function solve(target) { // 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.