Super Mario Galaxy features two 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, Sea Slide Galaxy)
Image: MarioWiki.com
(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 would be a more correct term as some faces aren't square, but you've got to admit - "rhombicuboctahedron" flows nicer.
R
. I have worked this out on paper to be sure my code is correct. \$\endgroup\$