The TransCompilator

Solved LeetCode program · 804 of 1,000

#1041 · Robot Bounded In Circle

Medium String chunk-17.md

Original English source

Keep a shared instructions as empty text. Place "GGLLGG" into instructions. Keep a shared across of 0. Keep a shared down of 0. Keep a shared facing of 0. Keep a shared east holding 0, 1, 0, and -1. Keep a shared north holding 1, 0, -1, and 0.

To travel.
For every spot from 0 to the last position of instructions.
The symbol is the slice of instructions from spot to spot plus 1. The move is 0. If symbol is "G", set move to 1. If symbol is "L", subtract 1 from facing, set facing to facing modulo 4. If symbol is "R", add 1 to facing, set facing to facing modulo 4. If facing is less than 0, set facing to facing plus 4. The side is facing. If move is 1, set across to across plus item side of east, set down to down plus item side of north.

Travel. The bounded is 1. If across is 0 and down is 0, set bounded to 1. If across is not 0 or down is not 0, set bounded to 0. If facing is not 0, set bounded to 1. If bounded is 1, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true