# Implement the Cubically Cube

Cubically is a fairly new esoteric language capable of creating short, golf-like answers for a very specific subset of problems. It is unique in that it stores memory in the form of a 3x3 Rubik's cube, making calculations far less trivial than in most languages. In Cubically, the programmer must rotate the internal cube in order to manipulate the values stored on the faces, then use those values in their calculations. Calculations are performed on a single 32-bit integer stored on an imaginary face known as the "notepad". Additionally, Cubically can request user input and store it in an input buffer consisting of only a single integer value.

## The Cube

The faces of the cube are Up, Down, Left, Right, Front, and Back:

   UUU
UUU
UUU
LLLFFFRRRBBB
LLLFFFRRRBBB
LLLFFFRRRBBB
DDD
DDD
DDD


When the program starts, the cube is initialized such that each square on that face is equal to that face's 0-based index:

   000
000
000
111222333444
111222333444
111222333444
555
555
555


Whenever a face is rotated, it is always rotated clockwise:

Cubically> F1

000
000
111
115222033444
115222033444
115222033444
333
555
555


The value of a face is defined as being the sum of every square on that face. For example, in the above cube, the value of face 0 is 3.

## Syntax

Commands are executed by first loading a command into memory, then passing arguments to it to execute the command. For example, the command F1 will load the command F into memory, then call it with the argument 1. Additionally, F13 will load the command F into memory, then call it with the argument 1, then call it with the argument 3. Any non-digit character is treated as a command, and any digit is treated as an argument.

Your task is to implement Cubically's internal memory cube in a language of your choice. Your code should be able to execute a very small subset of the language.

Commands

• R - Rotate the right face of the cube clockwise the specified number of times.
• L - Rotate the left face of the cube clockwise the specified number of times.
• U - Rotate the top face of the cube clockwise the specified number of times.
• D - Rotate the bottom face of the cube clockwise the specified number of times.
• F - Rotate the front face of the cube clockwise the specified number of times.
• B - Rotate the back face of the cube clockwise the specified number of times.
• % - Outputs the value on the given face. The value of a face is defined as the sum of all squares on that face.

## Rules

• You may use any language created before or after the date this challenge was posted to write a program or function capable of solving this challenge.
• Input will be passed in either through STDIN, as a string, or as a character array (you choose, please specify).
• Output must be passed either to STDOUT or as the output of the function, and it must be either an integer, a string containing only digits, or an array of digits. If your language requires you to output a trailing newline, you may do so.
• The input will always be in the following format: ([UDLRFB]\d*)*%[0-5]. There will be no whitespace characters in the input.
• The input for % will always use a 0-based index.

This is , so shortest answer in bytes wins.

## Test Cases

%0 -> 0
%1 -> 9
%2 -> 18
%3 -> 27
%4 -> 36
%5 -> 45
R1%2 -> 27
RD3F2%5 -> 32
L1R23F1B5U9D2%3 -> 17


For more test cases, check out the TIO interpreter. If TIO isn't working, you may use the Lua interpreter instead.

• Is this question a duplicate of this? Aug 8, 2017 at 22:00
• Related. Aug 8, 2017 at 22:01
• @TehPers I think it's very similar. For future challenges, I recommend leaving them in the sandbox for at least 24 hours, longer if you still have questions about it. (I had to learn this the hard way; my first challenges were not well-received at all. This isn't closed or downvoted yet so it's not bad, but had it been left in the sandbox for longer, other users might've noticed flaws that I didn't.) Aug 8, 2017 at 22:46
• @MDXF I'll keep that in mind for next time. Thanks! Aug 9, 2017 at 0:08
• Did you miss out a multiple of 4 between R and D in the example RD3F2%5 -> 30? Aug 9, 2017 at 2:58

# Python 2, 476 bytes

import re
c=[[i]*9for i in range(6)]
r=lambda f:[f[a+b]for a in(0,1,2)for b in(6,3,0)]
U=lambda c:[r(c)]+[c[j+1][:3]+c[j or 4][3:]for j in(1,2,3,0)]+[c]
y=lambda c:[r(c)]+c[2:5]+[c,r(r(r(c)))]
z=lambda c:[c,r(r(r(c))),c,r(c),c[::-1],c[::-1]]
s=input()
exec("c="+"(c);c=".join("".join("zzzUz U zzUzz yyyzUzzzy zUzzz yzUzzzyyy".split()[ord(t)%11%7]*sum(map(int,n))for t,n in re.findall("([BUDLFR])(\d*)",s[:-2])))+"(c)")
print sum(c[int(s[-1])])


Try it online!

A port from my Simulate A Rubik's Cube answer. The revisit prompted me to golf that by 47 bytes.

# Cubically, 1 byte

¶


Non-competing 'cause it's lame. Don't accept this.

¶  Read a line from stdin and evaluate


I added that this afternoon :P

• Well, I think you have the shortest code. Dec 1, 2017 at 2:08
• @TehPers I do, but like I said, it's lame. Cubically can win other rubiks-cube challenges with this builtin, it doesn't need to win this one. Dec 1, 2017 at 2:09