Opening your workspace…
Workspace/Coding room
Opening your workspace…
The sleeping giant turns over without waking. How wide must his bed be to hold him through a whole night? Viewed from the foot of the bed, his body is a rectangle. He starts on his back, resting on its broad edge. Each turn rolls him a quarter turn about his lower left or lower right corner, without sliding. The bed must support his full resting footprint at the start and after every turn. You may choose where he starts on the bed.
5, 2, "RRR"Output14Rolling right each time, he rests on four adjoining stretches of width 5, 2, 5, and 2. Together they span 14 units.
5, 2, "LRR"Output9The first turn needs 2 units to the left of his starting spot. The second rolls him back onto his back. The last needs 2 units to the right, so the bed must span 2 + 5 + 2 = 9 units.
Record the leftmost and rightmost occupied coordinates after each roll.
function solve(breadth, thickness, turns) { // 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.