The TransCompilator

Solved LeetCode program · 911 of 1,000

#1263 · Minimum Moves to Move a Box to Their Target Location

Hard Array chunk-19.md

Original English source

Keep a shared grid holding 1, 1, 1, 1, 1, 1, 0, 0, 4, 1, 1, 0, 0, 0, 1, 1, 0, 2, 0, 1, 1, 0, 3, 0, and 1. Keep a shared seen as an empty list of whole numbers. Keep a shared distance as an empty list of whole numbers. Keep a shared queue as an empty list of whole numbers.
For every state from 0 to 624.
Place 0 into seen. Place 0 into distance. Place 0 into queue.

Keep a shared count of 0.

To expand from state (a whole number) with offset (a whole number).
The boxcell is state divided by 25. The playercell is state modulo 25. The nextcell is playercell plus offset.
If item nextcell of grid is 1, return.
If nextcell is boxcell and item (boxcell plus offset) of grid is 1, return.
The newboxcell is boxcell. The newplayercell is nextcell.
If nextcell is boxcell, set newboxcell to boxcell plus offset, set newplayercell to boxcell.
The freshstate is newboxcell times 25 plus newplayercell.
If item freshstate of seen is 1, return.
Set item freshstate of seen to 1. Set item freshstate of distance to item state of distance plus 1. The slot is count. Set item slot of queue to freshstate. Add 1 to count.

The start is 447. Set item 447 of seen to 1. Set item 0 of queue to start. Set count to 1. The head is 0. The answer is -1.
Repeat while head is less than count and answer is less than 0.
The state is item head of queue. Add 1 to head. The boxcell is state divided by 25. If boxcell is 8, set answer to item state of distance.
If boxcell is not 8.
The playercell is state modulo 25. The band is playercell divided by 5. The file is playercell modulo 5. If band is more than 0, Expand from state with -5. If band is less than 4, Expand from state with 5. If file is more than 0, Expand from state with -1. If file is less than 4, Expand from state with 1.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

5