A giant six-sided die lies on a board grid (a list of equal-length strings). Opposite faces of the
die always add up to 7. It starts on 'S' with 1 on top, 2 facing south (towards larger row
numbers) and 3 facing east (towards larger column numbers); so 6 is at the bottom, 5 faces north
and 4 faces west.
In one move the die rolls over one of its bottom edges onto the neighbouring cell to the north,
south, east or west. Rolling east, for example, tips the west face (4 at the start) onto the top.
The die may not leave the board or roll onto '#'. A cell holding a digit '1' to '6' is a
pressure pad: the die may roll onto it only if, after the roll, that digit is on top. '.',
'S' and 'G' are plain floor.
Return the fewest rolls needed to stand on 'G' with the number want on top, or -1 if that is
impossible.
The setup provides dice_board(rows, cols, seed, rocks=15, pads=35), which builds a random board
with S in the top-left and G in the bottom-right corner; the larger tests use it. Try it with
Run: print("\n".join(dice_board(8, 10, 1))).
Examples
Input: grid = ["SG"], want = 4
Output: 1
Explanation: rolling east brings the west face, 4, to the top.
Input: grid = ["S...G"], want = 1
Output: 4
Explanation: rolling east four times shows 4, 6, 3 and then 1 again on top.
Input: grid = ["S..G"], want = 1
Output: -1
Explanation: after three rolls east 3 is on top, and there is no room to turn.
Constraints
1 <= len(grid), len(grid[0]) <= 40- exactly one
Sand oneG, on different cells;1 <= want <= 6
Goals
- Add an orientation to a grid position to form the search state
- Update a die's faces correctly for each of the four rolls