[Question]
  [
[*Super Mario Galaxy*](https://www.mariowiki.com/Super_Mario_Galaxy) features two [rhombicuboctahedron](https://en.wikipedia.org/wiki/Rhombicuboctahedron)-shaped\* planets tiled with platforms that shrink as Mario runs across. Should Mario fall into a triangular hole or a gap left by a tile he previously touched, he will be consumed by the black hole at the core. (Watch: [Hurry-Scurry Galaxy](https://youtu.be/xfFBi7z_8cQ?t=1m12s), [Sea Slide Galaxy](https://youtu.be/xOl7au63XNg?t=1m30s))
[![Image: MarioWiki.com](https://i.stack.imgur.com/oQAwF.png)](https://i.stack.imgur.com/oQAwF.png)
Image: [MarioWiki.com](https://www.mariowiki.com/Hurry-Scurry_Galaxy)
(You can think of the planet as a 2x2x2 cube whose faces have been detached and connected to each other by 2x3 "bridges".)
Unfortunately, since my controller is very broken, Mario cannot jump and is limited to the four cardinal directions. Additionally, Mario moves very slowly and cannot retrace even one step without first having the platform behind him disappear.
Let's assume the camera is always above Mario's head and he starts at the bottom right of a 2x2 face:
```
      ■ ■
      ■ ■
      ■ ■
■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ M ■ ■ ■
      ■ ■
      ■ ■
      ■ ■
```
Your program will take a list or string of directions, `U` `D` `L` `R` (up, down, left, right), representing Mario's walk around the planet so far as a series of steps. The program can output one of two distinct outputs: one representing that Mario is still alive and walking, and the other representing that somewhere along his walk, Mario has fallen into the Shrinking Satellite.
```
RR:   ■ ■                 RRD:  ■ ■                 RRL:  ■ ■      
      ■ ■                       ■ ■                       ■ ■      
      ■ ■                       ■ ■                       ■ ■      
■ ■ ■ ■ ■ ■ ■ ■           ■ ■ ■ ■ ■ ■ ■ ■           ■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ □ □ M ■           ■ ■ ■ ■ □ □ □ ■           ■ ■ ■ ■ □ M □ ■
      ■ ■    \                  ■ ■   M                   ■ ■  \
      ■ ■     Let's-a go!       ■ ■    \                  ■ ■   W-aaaaaaaaaahh!
      ■ ■                       ■ ■     W-aaaaaaaaaahh!   ■ ■
```
Of course, unlike the above diagrams, you'll have to take the 3D into account. Here's a diagram that might help you visualize the scenario better:
```
                Top 2x2 face
   <- clockwise           anticlockwise ->
   -   ■    -    ■    -    ■    -    ■   -
     /   \     /   \     /   \     /   \  
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
   ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■    Left and right
   ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ M ■ ■ ■ ■ ■ ■ ■ ■ ■    edges wrap around.
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
     \   /     \   /     \   /     \   /  
   -   ■    -    ■    -    ■    -    ■   -
   <- anticlockwise           clockwise ->
               Bottom 2x2 face
```
So according to this diagram, `UUUUURRRR` might look like this:
```
   -   ■    -    ■    -    □    -    ■   -
     /   \     /   \     /   \     /   \  
   ■       ■ ■       ■ □       □ ■       ■
   ■       ■ ■       ■ □       □ ■       ■
   ■       ■ ■       ■ □       □ ■       ■
   ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ □ ■ ■ ■ M ■ ■ ■ ■ ■
   ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ □ ■ ■ ■ ■ ■ ■ ■ ■ ■
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
     \   /     \   /     \   /     \   /  
   -   ■    -    ■    -    ■    -    ■   -
```
And `UUUUUUUUULURRRRRR` might look like this:
```
   -   ■    -    ■    -    □    -    □   -
     /   \     /   \     /   \     /   \  
   ■       ■ ■       ■ □       ■ ■       □
   ■       ■ ■       ■ □       ■ ■       □
-> □       ■ ■       ■ □       ■ ■       □ ->
<- □ ■ ■ ■ ■ ■ ■ ■ ■ ■ □ ■ ■ ■ M □ □ □ □ □ <-
   ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ □ ■ ■ ■ ■ ■ ■ ■ ■ ■
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
   ■       ■ ■       ■ ■       ■ ■       ■
     \   /     \   /     \   /     \   /  
   -   ■    -    ■    -    ■    -    ■   -
```
May the shortest program in bytes w-aaaaaaaaaahh!
## Test Cases
### Output 1: Still Alive
`DDDDDLUUUUU` - Mario walks across a bridge and back.
`RRRRDDDDLLL` - Mario walks in a triangle.
`LLLLLLUUUUUURRRRR` - Mario walks in a bigger triangle.
`ULLDRDDDRU` - Mario puts himself in peril.
`RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRR` - Mario takes an unconventional route... and puts himself in peril.
Mario crosses every tile exactly once.
`DDDDLUUUULLLLDDDLUUULLLLDDDDLUUUULLLLDDDLUUULLLURRRUUURDDDRRRRUUURDDDRRRRUUURDDDRRRRUUUUURDDDDD`
`DLDRDLDLLLDRRRDDDDLLLLLLLLLDRRRRRRRRRDDDDLLLDRRRDDDRUUURRRRULLLLUUUURRRULLLUUUUURDRURDRUURULURU`
### Output 2: W-aaaaaaaaaahh!
`LLR` - Mario attempts to retrace a step and falls off.
`UULDR` - Mario attempts to cross a tile twice and steps into air.
`RRDDDDD` - Mario walks off a bridge at the first D (ignore any following steps).
`RRRRDDDDLLLL` - Mario walks in a triangle and falls through the starting tile.
`LLLLLLUUUUUURRRRRR` - Mario walks in a bigger triangle and falls through the starting tile.
`UUUUUUUUUUUUUUUUUUUU` - Mario walks all the way around the planet and falls through the starting tile.
`RURDRURDRDLDRDLDLDLULDLLUU` - Mario takes an unconventional route and becomes disoriented.
Mario, realizing the peril he is in, is left with no choice.
`ULLDRDDDRUUU` `ULLDRDDDRUUL` `ULLDRDDDRUUR` `ULLDRDDDRUUD` `RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRRR` `RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRRU` `RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRRL` `RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRRD`
Finally, copy any test case from "Mario crosses every tile exactly once" and change or add one step at random. Mario should fall. (If you add a step to the end, Mario falls to grab the Power Star!)
\*[Cantellated cube](https://en.wikipedia.org/wiki/Cantellation_(geometry)) would be a more correct term as some faces aren't square, but you've got to admit - "rhombicuboctahedron" flows nicer.
  
[Answer]
# APL (Dyalog), ~~457~~ 441 bytes ([Classic Dyalog Character Set](https://codegolf.meta.stackexchange.com/questions/9428/when-can-apl-characters-be-counted-as-1-byte-each))
```
r←'RULD'
S←{(r⍳⍵)⌷4 4⍴2 3 4 1 4 3 1 2 4,(⍳3),3 4 2 1}
C←{(⊂⍺)⌷⍵}
P←,⍉0 1 2 3∘.{2 4 1 3(C⍨⍣⍺)⍵}(⊂⍳4),C\S¨'LUULU'
v←6 6⍴(3⍴0),2(⊥⍣¯1)4512674568
a←1 4 4
N←{s y x←⍵+0,(r⍳⍺)⌷4 2⍴0 1 ¯1 0 0 ¯1 1 0
t Y X←⊃(1+(7<y+x)(0<y-x))⌷2 2⍴('U'5 0)('L'0 5)('R'0 ¯5)('D'¯5 0)
⊃(1+(1+y x)⌷(¯2⊖¯2⌽8 8↑4 4⍴1)∨¯1⊖¯1⌽8 8↑v)⌷((P⍳⊂(⊃s⌷P)C(S t)),(Y X+y x))(s y x)}
M←{T←24 6 6⍴0
~∨/,0>(6 6 6⍴v)-+/[2]6 4 6 6⍴↑(24⍴⍳4){{⊖⍉⍵}⍣⍺⊢⍵}¨⊂[2 3]T⊣{T[⊂⍵]+←1}¨(⊂a),{⊃N/(⌽⍵),⊂a}¨,\⍵}
```
*Thanks, Bubbler, for helping me shave off several bytes!*
[Try it online!](https://tio.run/##nVLBahsxEL3rK9STJHZd72rXGx9CL96jEsw6S1scHxZamoChJTHGxriHGEK6ZEt7aOm5oeBbDmkoBHrxp@hH3BlJdus05OBZpB3NzBu9mVHxrl97NS76b98slyf6/BPLcpUy0gF1wk90daOrW6Evf8U01tVPSSMa0xBWBLuksc8hJBI@miUNp6RlgLo809Ud4gA@JW0w@rr6EBhQpC@@PZ1IkyjiLV3NdXVlwiHWQm9i4bcOO4s5U3muckaGkCGhCVDgEWyB8CVE/gDg4joUcSOUyU7cSJqkgEDkF5N9ZHJKx3QECqT2At8VdGcLkpgIOEAGGsCHf9DIgL6kLxBTznjo8Z3dsTcSPNgd10YCkdIgOctZgwaCM8UC2oB/xjAHaimDP/iISxF6wAKhfHEtdfkV98vfTdrU559tY0OhL@ZAwDjDtXNoQLyNtMszqHh2Coa2aPEOHQjhc2BqcgtuKhVTsodlH8AmY2o7FpD3kLzuB8944kxDUfPqXdlL6CoILuMSmZjmTyZABAaGE7HD0eV3PCzmwKMLM@wd6PJqctA147rtedh28OL4CuEDfLZf51AHPh8fjeD0DzHFUn/8gg@tMzju92nRPx6@ZsTa9hZzylIUGDsIoywDMQal4KSMGF@OngxsuVIphmQmPM9Ss1JlFnzwntU9sdi1MHupyYtupzv1ITsmQAp47WOqPaQp3uAIIdt1SVbSNRNndhGZqzJfFe10l9jWmoMJFiOuh@x5rVjL0dGTjd4qZToGLclMb1fk/rn7wTZb1P/ySMeN8@9s7h/V5nFzkHm67SizbYFbPx61LTBlyz8)
To see how this works, let's learn some group theory! First, observe that the entire cuboid structure can be realized as the following shape, tessellated onto the six faces of a cube.
```
      .
    . .
. . . . .
  . . . . .
    . .
    .
```
Now, in our case, I won't be using just six faces. Because Mario's position doesn't just depend on which face he's on; it also depends on his current orientation (i.e. the direction he's facing). So I'll be using 24 states to represent his current state (24 = 6 faces × 4 orientations). Since this is APL, we'll do the calculation in a massive array. Specifically, we'll use a 24×6×6 array to store every position Mario steps on, and how many times he's been there. So Mario's position at a given moment with be a 3-vector `s y x`, where `s` is the cuboid state (face times orientation) and `y`, `x` are the coordinates within that face.
Now, if Mario is in the middle of a face, then when he moves we simply update the position vector accordingly. So a movement `U` (up) would add `0 ¯1 0` to his position. A movement `R` (right) would add `0 0 1`, etc., etc.
The tricky case comes into play when Mario is at an edge. So if we're here
```
      M
    . .
. . . . .
  . . . . .
    . .
    .
```
and we move up, what do we do? We end up moving four down (effectively wrapping around) and to some other cuboid state. So if we started as `s y x`, our new position will be `t (y + 4) x`. But what is `t`? To figure that out, we need to look at rotations of a cube.
As I already mentioned, there are 24 rotations of a cube. Let's try to represent the vertices of a cube numerically.
```
  5--6
 /| /|
1--2 |
| 7|-8
|/ |/
3--4
```
Okay, neat. But that's not all of the information we have. In particular, any rotation of a cube will take opposite vertices to opposite vertices. So, in the above diagram, 1 and 8 are at opposite sides. No matter which way I rotate this cube, 1 and 8 will still be opposites. So we really only have four points we care about, as the other four can be calculates from those.
```
  4--3
 /| /|
1--2 |
| 2|-1
|/ |/
3--4
```
As it turns out, this is all of the information we need. If we look at the cube head-on so that the above cube looks like
```
1--2
|  |
|  |
3--4
```
Then every permutation of those four points is a rotation of the cube, and every rotation of the cube can be represented as a permutation of those four points. You can read more about that [on Wikipedia](https://en.wikipedia.org/wiki/Octahedral_symmetry), but the basic idea is that rotations of the cube can be represented using the symmetric group S4, which has 24 elements. We'll represent it this way, since APL has some nice built-in functions to apply permutations.
Now, how does this help us? Well, we wanted to know, given a state `s` and a side of the screen we went off (say, to the right, for this example), what is our new state `t`? If we can enumerate the 24 elements of S4 in a nice order, then `s` is simply some element of that enumeration. Then we figure out what the permutation for "go off the screen to the right" is, and compose the two to get `t`. So, if our cube is
```
  5--6
 /| /|
1--2 |
| 7|-8
|/ |/
3--4
```
Then, if we go off the screen to the right, we rotate the cube so the face Mario is now on is facing frontward. We get
```
  1--5
 /| /|
2--6 |
| 3|-7
|/ |/
4--8
```
Remember that we're identifying opposite vertices, so
```
  1--4
 /| /|
2--3 |
| 3|-2
|/ |/
4--1
```
Looking from the front, we turned a `1 2 3 4` cube into a `2 3 4 1` cube. So our permutation group element is `2 3 4 1`. This works whenever we move right. If we take our current cuboid state (which is an element of S4), and compose it with `2 3 4 1`, we get the new state. A pencil and a bit of effort, and we can calculate the element of S4 representing right, up, left, and down movements.
```
Right 2 3 4 1
Up    4 3 1 2
Left  4 1 2 3
Down  3 4 2 1
*     2 4 1 3
```
That last one (with the `*`) is a rotation of the current face that doesn't change which face Mario is on. So it corresponds to Mario just facing a different direction without walking. In the problem statement, it's not possible for Mario to do that, but we'll need that permutation later for our calculations.
Alright, that should be all the background we need. Let's dig into the code.
```
r←'RULD'
```
Nothing to see here. We use the string `'RULD'` a few times, so it saves us a couple characters to store it.
```
S←{(r⍳⍵)⌷4 4⍴2 3 4 1 4 3 1 2 4,(⍳3),3 4 2 1}
```
`S` is the function which takes R, U, L, or D and converts it to the corresponding permutation we found above.
```
C←{(⊂⍺)⌷⍵}
```
Like I mentioned earlier, APL has nice built-ins for applying permutations. `C` composes two elements of S4. This is how we model multiple steps, like "go right, then go right again".
```
P←,⍉0 1 2 3∘.{2 4 1 3(C⍨⍣⍺)⍵}(⊂⍳4),C\S¨'LUULU'
```
`P` consists of all permutations of `1 2 3 4`, i.e. all elements of the group S4. Let's break it down.
```
(⊂⍳4),C\S¨'LUULU'
```
From the starting orientation, `LUULU` will visit each face of the cube exactly once. So the above expression consists of one permutation representing each face of the cube, ignoring rotations for the moment. We manually tack on the identity `1 2 3 4`, which is our starting state.
```
{2 4 1 3(C⍨⍣⍺)⍵}
```
I mentioned earlier that `2 4 1 3` corresponds to Mario turning his head 90 degrees. We have each face, so we'll want to rotate the faces to get every possible state. This function rotates a face once.
```
0 1 2 3∘.{2 4 1 3(C⍨⍣⍺)⍵}(⊂⍳4),C\S¨'LUULU'
```
Now we rotate every face zero times, once, twice, and thrice, to get every possible permutation.
```
,⍉0 1 2 3∘.{2 4 1 3(C⍨⍣⍺)⍵}(⊂⍳4),C\S¨'LUULU'
```
`⍉` will transpose the result, which gives us the permutations in a nice order (namely, every cube is represented contiguously, by its four rotations in a sequence in the array). Then we ravel `,` the array to get one nice, flat vector of vectors.
```
v←6 6⍴(3⍴0),2(⊥⍣¯1)4512674568
```
`v` is a representation of the below valid positions grid, encoded in base 10 for compactness.
```
0 0 0 1 0 0
0 0 1 1 0 0
1 1 1 1 1 0
0 1 1 1 1 1
0 0 1 1 0 0
0 0 1 0 0 0
```
 
```
a←1 4 4
```
Mario's starting state. Again, we use this twice, so it's just barely shorter to assign it to a variable.
```
N←{...}
```
`N` is a big one. Given a direction `⍺` (one of the letter RULD) and a position `⍵`, this moves Mario in that direction. Remember, our position is a 3-vector `s y x`, so we'll be moving in 3-dimensional space, where the third dimension is our state space.
```
s y x←⍵+0,(r⍳⍺)⌷4 2⍴0 1 ¯1 0 0 ¯1 1 0
```
In the easy case, we simply shift `y` and `x` and leave `s` alone. This is fine as long as we don't run off the edge. If we don't, then `s y x`, as declared above, is the correct answer. If we do, then we need to do some more work.
```
2 2⍴('U'5 0)('L'0 5)('R'0 ¯5)('D'¯5 0)
```
On the other hand, if we do run off the edge, this tells us what we have to do. In the first case, we shift the cube up and move Mario down 5. In the second case, we shift the cube left and shift Mario to the right 5, and so on.
```
t Y X←⊃(1+(7<y+x)(0<y-x))⌷...
```
To figure out which case we're in, we draw two diagonal lines along the grid as follows
```
\     .   /
  \ . . /
. . \ / .
  . / \ . .
  / . . \
/   .     \
```
This partitions our grid space into four sections. The lines are determined by `7<y+x` and `0<y-x`. Then we look up our cases in the previous 2×2 array. Note that if we're in the easy case, then this calculation is pointless but ultimately harmless. We'll determine which case we're in next.
```
(¯2⊖¯2⌽8 8↑4 4⍴1)∨¯1⊖¯1⌽8 8↑v
```
This expression uses `v` above and produces the array below
```
0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0
0 0 1 1 1 1 0 0
0 1 1 1 1 1 0 0
0 0 1 1 1 1 1 0
0 0 1 1 1 1 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0
```
Then, if Mario ends up on a `0`, we need to change cuboid state. If not, then we're good. Note that I include a few "out of bounds" points here where there aren't platforms. This prevents Mario from warping to out of the array bounds if he walks off the edge.
```
(1+y x)⌷(...)
```
Look at Mario's position and see if it's a zero in the above array.
```
⊃(1+(1+y x)⌷(¯2⊖¯2⌽8 8↑4 4⍴1)∨¯1⊖¯1⌽8 8↑v)⌷(...)(s y x)
```
We use the above `0` or `1` to index into our two cases. If it's a `1`, simply return `s y x`. If not, then we have more work to do.
```
(P⍳⊂(⊃s⌷P)C(S t)),(Y X+y x)
```
The Y and X coordinates are simply `y x` added to our shift amount we calculated earlier. As for the new cuboid state, we have our direction `t`. Then `S t` is the permutation, which we compose with our permutation for our current state `⊃s⌷P`, then we convert the permutation back to an index in state space `P⍳⊂`.
```
M←{...}
```
Now, `M` is the final piece. It's the function that, given a sequence of inputs, actually determines whether or not Mario falls. It will return `1` on success and `0` if he falls off.
```
T←24 6 6⍴0
```
Our initial state is a 24×6×6 state space, consisting of all zeroes, since Mario hasn't been anywhere yet.
```
(⊂a),{⊃N/(⌽⍵),⊂a}¨,\⍵
```
Now we take all of the prefixes of our input (`,\⍵`) and we move Mario along those paths (`{⊃N/(⌽⍵),⊂a}¨`). Then we tack on the initial state (`(⊂a),`), since Mario clearly starts off by visiting the initial position. Now we have a vector of all of Mario's positions at every moment.
```
{T[⊂⍵]+←1}¨...
```
For each position Mario ever visits, go to that place in the array `T` and add one to it.
```
(24⍴⍳4){{⊖⍉⍵}⍣⍺⊢⍵}¨⊂[2 3]T
```
We have 24 faces on our "cube". In reality, our cube only has 6 faces. So it's time to account for which faces are rotations of which others. Remember, we enumerated our permutations earlier so that the first four states are rotations of one another, then the next four are rotations of one another, and so on. So we'll take `T` (a 24×6×6 array) and, along the first axis (state space), we rotate. We'll rotate the first 6×6 once, the second twice, the third three times, then four times, then once, then twice, and so on. The actual rotation is done by `{⊖⍉⍵}`, which is a transpose followed by a flip. This corresponds to a 90 degree rotation. Now everything is oriented correctly.
```
+/[2]6 4 6 6⍴↑...
```
Now that everything has the right orientation, we want to add together the faces that are actually the same. So reshape the array to a 6×4×6×6 (where the dimensions are, respectively: face, orientation, y, x). Then we sum along the second axis, which represents orientation, giving us a 6×6×6 array of all of the actual positions on the grid.
```
(6 6 6⍴v)-...
```
`v` tells us which positions Mario is allowed to visit. So we subtract the ones we actually visited from this. If we ever end up with a negative number, that means Mario either went somewhere he shouldn't have or he revisited the same space twice.
```
R←~∨/,0>...
```
See if any positions are less than zero. Then invert the result (since success means they're all greater than zero, and failure means there is one which is less).
And that's all there is to it. If you actually read this dissertation of mine, then congratulations! This is my first APL golf, so I'm sure there's room for improvement. But I enjoyed the opportunity to use a bit of math in my answer as well.
[Answer]
# Ruby, golfed, ~~244~~ 230 bytes
Seems to work fine, will test a bit more.
```
->s{a=[8**8/5]*8
v=[-1,x=d=0,1,0]
y=m=4
s.chars{|c|a[y]&=~(1<<x) 
y+=v[e="URDL".index(c)+d&3]
x+=v[e-1]
r= ~0**q=x/4
i=q+x&1
j=q+y&1
y%9>7&&(y=4-i;x+=4-j*11-x%2;d+=r)
x&2>0&&-y/2==-2&&(y=i*7;x+=6-x%2*9+j;d-=r)
m*=1&a[y]>>x%=24}
m}
```
# Ruby, first working version, 260 bytes
[Try it online](https://tio.run/##pVRNb@IwEL37V4xARHyFAou2XbXmlGP2klVOiINJnGARHHAMJOrHX2dtJ9C0ha66HZQwtvPmjd@MLXaL4niMsD3NHgmeDfMfxubdO7RXw7496g/7oznKcYiHqMBrPEHZIFgSkT0@BU9kVswt/NIePTzkHUAUN3zPcRsDxkOat4NOL0R5D@9ntDWZo0J79ovxNzi37DHa4vxm0hqjovVremtZ7dDG2@7YHt0X/RxP7Pa2l3da43570zODQg26o5F6Tzoot8bToWXZxc0YY3us0BpUQbq3GvTTzpV716ugGncf9kqKDlp3sc5/Os2t0TNaPx@bfyRLEiAJ29M@CCp3gsOeJDsKE7TZyQyiWcPR5vraGnNowm8iWAoHkqwyIIFIM/UHC8HCmALhISxIsBqc0Z4yE8B1P6AZV0gpGOFxQl8hrjFD6Gu4dxm4YHFMxQW877qO5vTq@ZrFJVtnNIk0fkMFS2ppqjKax3HNo36@67jvrEznZLXokqyokoHDjgcp31MuWcpJAiLdSToYDIww/0jhLLNmqvzKvTSvc9EC6Y1@5pYDx1HZvlJVm9RCnctTmnPeXjVdfeFVxfBPtan8iqHUz1dTvpYdoaZDSfiup4aoVuNSvko/IiVdb9SSTDVEkED1EmSSboxyEUmSDNIoqhVZledqiFNXqu6mIA8sKDtTx9PNo74gTNR79KTQOVrZZ4qx1tsS5JJCxEQmwYE2i3kqdOACojRJ0gPjcUnRudj@7sf4bw5AbadyqRonXhq@TBIhdWi9mU8OiXcl/Ltj8jUW/4J95FHRTJADKYComIpBDzcJ4VR@jfDaOaxo0YVDbpYuzbtX5r0r82@OyP9cCGUNJM0lBCSjWv8tsAwOIuXxAFJOYa1bxgMShjTUnbpWF4fRY6Uu4u9dR/5303e/G0AJePwL)
Lambda function taking a string argument. Returns 4 for alive, 0 for dead.
```
->s{a=[0x333333]*8
v=[0,-1,0,1]
x=d=0
y=m=4
s.chars{|c|a[y]&=~(1<<x) 
e="URDL".index(c)+d
x+=v[e%4]
y+=v[-~e%4]
p=x&-2
q=x/4%2
y%9>7&&(d-=q*2-1;y,x=4-(q+x)%2,(p+4-(q+y)%2*11)%24)
x&2>0&&-y/2==-2&&(y,x=(q+x)%2*7,(p+6-x%2*8+(q+y)%2)%24;d+=q*2-1)
m*=a[y]>>x&1}
m}
```
**Explanation**
The board is unfolded into 6 strips of size 2x8, represented by the `/\` and `O` characters below. These are mapped onto a 24\*8 2D map, where x=(strip number)\*4+(horizontal position on strip) and y=vertical position on strip. 
```
       Map        4         2         0          Initial state of array a
                 /         /         /   
                / /       / /       / /          1100110011001100110011
               / /       / /       / /           1100110011001100110011 
              O /       O /       O /            1100110011001100110011
             O O       O O       O O             1100110011001100110011
      \     / O \     / O \     / X              110011001100110011001X
     \ \   / / \ \   / / \ \   / /               1100110011001100110011
      \ \ / /   \ \ / /   \ \ / /                1100110011001100110011
       \ O /     \ O /     \ O /                 1100110011001100110011
        O O       O O       O O 
         O \       O \       O \                 X=Mario's start point 
          \ \       \ \       \ \  
           \ \       \ \       \ \    
            \         \         \
             5         3         1
```
These are stored in an array of 8 binary numbers, so x increases going left and y increases going down.
The array is intialized with 8 copies of the number `0x33333333`. This forms the squares Mario is allowed to step on. As Mario moves around the square he is on is set to zero, and the square he is moving to is tested - he lives it contains a 1, and dies if it contains a 0.
If Mario walks off the top or bottom of the strip he is on, he moves to another strip. If he walks off the side of the strip he is on, if he is on a square with y=3 or y=4 he moves to another strip. If y is not 3 or 4, he does not move to another strip and ends up on a square which had 0 in it from the outset of the game, so he dies.
Because the camera is always above Mario's head, whenever Mario changes strip, the reference for the directions must be rotated by 90 degrees.
**Ungolfed in test program**
```
f=->s{                             #Move sequence is taken as string argument s.
  a=[0x333333]*8                   #Setup board as an array of 8 copies of 1100110011001100110011.
  v=[0,-1,0,1]                     #Displacements for moving.
  x=d=0                            #Mario starts at 0,4.
  y=m=4                            #d=offset for directions. m=4 when Mario is alive (value chosen for golfing reasons) 0 when dead.
  s.chars{|c|                      #For each character c in s
    a[y]&=~(1<<x)                  #Set the square where Mario is to 0.
    e="URDL".index(c)+d            #Decode the letter and add the offset 
    x+=v[e%4]                      #x movement direction is v[e%4]   
    y+=v[-~e%4]                    #y movement direction is v[(e+1)%4]
    p=x&-2                         #p is a copy of x with the last bit set to zero (righthand edge of strip).
    q=x/4%2                        #q is 0 for an even number strip, 1 for an odd number strip.
    y%9>7&&(                       #If y out of bounds (8 or -1)
      d-=q*2-1;                    #Adjust d so directions will be interpreted correctly on the next move.
      y,x=
        4-(q+x)%2,                 #y becomes 3 or 4 depending on the values of q and x.
        (p+4-(q+y)%2*11)%24        #If q+y is even, move 1 strip left. if even, move 2 strips right. Take x%24.  
    )
    x&2>0&&-y/2==-2&&(             #If x&2>0 Mario has walked sideways off a strip. If y is 3 or 4, move him to a different strip.
      y,x=                       
        (q+x)%2*7,                 #y becomes 0 or 7, depending on the values of q and x.
        (p+6-x%2*8+(q+y)%2)%24;    #If x%2 is even, move 2 strips left. If odd, move 1 strip right*. Pick the left or right column of the strip depending on (q+y)%2. Take x%24 
        d+=q*2-1                   #Adjust d so directions will be interpreted correctly on the next move.
    )
    m*=a[y]>>x&1                   #Multiply m by the value (0 or 1) of the current square. Mario is either alive (4) or dead (0).  
    #puts x,y,m,a.map{|i|"%022b"%i}#Uncomment this line for diagnostics.
  }
m}                                 #Return value of m.  
#Still alive, return value 4
puts f["DDDDDLUUUUU"] # Mario walks across a bridge and back.
puts f["RRRRDDDDLLL"] # Mario walks in a triangle.
puts f["LLLLLLUUUUUURRRRR"] # Mario walks in a bigger triangle.
puts f["ULLDRDDDRU"] # Mario puts himself in peril.
puts f["RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRR"] # Mario takes an unconventional route... and puts himself in peril.
puts f["DDDDLUUUULLLLDDDLUUULLLLDDDDLUUUULLLLDDDLUUULLLURRRUUURDDDRRRRUUURDDDRRRRUUURDDDRRRRUUUUURDDDDD"] 
puts f["DLDRDLDLLLDRRRDDDDLLLLLLLLLDRRRRRRRRRDDDDLLLDRRRDDDRUUURRRRULLLLUUUURRRULLLUUUUURDRURDRUURULURU"]
#Dead, return value 0
puts f["LLR"] #  Mario attempts to retrace a step and falls off.
puts f["UULDR"] #  Mario attempts to cross a tile twice and steps into air.
puts f["RRDDDDD"] #  Mario walks off a bridge at the first D (ignore any following steps).
puts f["RRRRDDDDLLLL"] #  Mario walks in a triangle and falls through the starting tile.
puts f["LLLLLLUUUUUURRRRRR"] #  Mario walks in a bigger triangle and falls through the starting tile.
puts f["UUUUUUUUUUUUUUUUUUUU"] #  Mario walks all the way around the planet and falls through the starting tile.
puts f["RURDRURDRDLDRDLDLDLULDLLUU"] # 
puts f["ULLDRDDDRUUU"] 
puts f["ULLDRDDDRUUL"] 
puts f["ULLDRDDDRUUR"] 
puts f["ULLDRDDDRUUD"] 
puts f["RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRRR"] #text case in q is wrong. one more R added to make the kill.
puts f["RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRU"] 
puts f["RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRL"] 
puts f["RURDRURDRDLDRDLDLDLULDLLLLLLLLLLLLLLLLURRRRRRRRRRRRRD"]
```
]