6
\$\begingroup\$

Your challenge is to translate a Cubically cube-dump to the format specified in this challenge.

Input

The input will represent a Rubik's Cube, formatted how Cubically prints its memory cube at the end of every program.

This is a solved cube:

   000
   000
   000
111222333444
111222333444
111222333444
   555
   555
   555

This is a cube scrambled with L2D2L2D2B2R2F2L2D2U2F2UF2U'R2UB2U'L2UB2U'LU'L2U'D'B2U'RBUBF'D' (Singmaster's notation):

   201
   501
   331
132505224540
512324533442
404513210411
   350
   254
   003

Output

If you already understand this format, hit page down a few times to skip lots of explanation.

The output will represent a Rubik's Cube, formatted how solutions to this challenge take input.

The first 12 values are the edge cubies, and the next eight are the corners. The faces are U(p), D(own), R(ight), L(eft), F(ront), and B(ack). First the cubie that's in the UF position is given, by the color (in UFRDBL notation) that's on top first, and then the other color next, and so on.

This format is a bit confusing, so here's a way to visualize it. This is the solved cube:

solved visualization

That renders the output UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR.

If we were to swap, for example, the red-white edge and the red-blue edge, the visualization would look like this (with no changes to the hidden faces):

swapped visualization

That renders the output UR UF UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR (which, btw, is an impossible cube state). Note that the order of the letters in cubies matter:

Above: UR UF UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR
Below: RU FU UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR

swapped reversed visualization

The cube scrambled with L2D2L2D2B2R2F2L2D2U2F2UF2U'R2UB2U'L2UB2U'LU'L2U'D'B2U'RBUBF'D' creates this cube (only the top, front, and right faces are shown):

scrambled visualization

Solved:    UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR
Scrambled: RU LF UB DR DL BL UL FU BD RF BR FD LDF LBD FUL RFD UFR RDB UBL RBU

As you can see in the comparison above and in the visualizations, the blue-red RU edge of the mixed cube is in the place of the red-white UF edge of the solved cube. The green-white LF edge is in the place of the red-blue UR edge, etc.

Rules

  • I/O will be done via any allowed means.
  • The output cubies must be delimited by any whitespace character you choose.
  • The input will be formatted exactly how it is shown in the challenge, including whitespace.
  • Your program may do whatever you like if the inputted cube is unsolvable.

Test cases

  • Input -> output: RU LF UB DR DL BL UL FU BD RF BR FD LDF LBD FUL RFD UFR RDB UBL RBU
  • Input -> output: UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR
  • Input -> output: FU DL LB BU RU BR RF DR BD DF LF LU FUL FLD URB BLU RUF DBR BDL RFD

Here's a reference program using parts of Cubically's rubiks.c.

Winner

As this is , the shortest answer in bytes wins!

\$\endgroup\$
2
\$\begingroup\$

Jelly, 87 73 62 61 60 bytes

fØDO“¬ụƘȷ$OkḌ×c¿?oƥ¤_Ọ6;ȤṚUȷ!8⁺⁻:ĠŻ’Œ?¤ịs24Ṗs"2,3ị“LFRBDU”ẎK

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Ruby, 115 bytes

->s{"29&,<&$?&*6&`S&hV&nY&fP&GH&ED&KJ&MB&3:;&%=>&#@5&178&aUT&_RQ&mOZ&oXW".bytes{|i|$><<"   ULFRBD"[s[i-32].ord%9]}}

Try it online!

A function taking the input as an argument and printing to stdout.

Iterate through the long string. Each byte(minus 32) represents the index of the next character to be transcribed.

To transcribe, take the ascii code of the character in the input (012345 or newline) and find the value modulo 9. This gives a number in the range 3 to 8, which is treated as an index in the string " ULFRBD" to transcribe. Thus the ascii code for 0 is 48, 48%9 is 3, which is the index of U in the string above.

The & signs in the long string point to the first newline in the input (character #10.) This is taken modulo 9 to give the value 1, which is looked up in " ULFRBD" and transcribed as a space.

The indices in the input are looked up as follows (extra spaces added for clarity)

    #$%
    *+,
    123
567 89: ;<= >?@
BCD EFG HIJ KLM
OPQ RST UVW XYZ
    _`a
    fgh
    mno
\$\endgroup\$
2
\$\begingroup\$

Clean, 150 145 143 bytes

Contains many non-printable characters.

import StdEnv
$d=map(\c=['ULFRBD ']!!(digitToInt(['96':d]!!(toInt c))))['!B5J8P;H2)*\'&-,/$ "C76A43O1<Q:9']

Try it online!

Defines the function $, taking [Char], and giving [Char].

This works by mapping each character position in the input to another character position in the output (using the character codes in a string), taking advantage of the swapped 'cubies' in the output being paralleled by swapped colors in the corresponding position in the input.

Output is separated by spaces.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.