7
Introduction:
I collect twisty puzzles, so I'm quite the fan of rubiks-cube-challenges (even though most are fairly difficult). So, let's try a fairly easy rubiks-cube-challenge for a change.
When an NxNxN Cube gets scrambled during a WCA (World Cubing Association) competition, the cube is always held in the same way before executing the scramble-algorithm:
Article 4: Scrambling
"NxNxN puzzles are scrambled starting with the white face on top and the green face on the front."
Challenge:
For the sake of this challenge we only have to look at the centers, so we'll use a 1x1x1 instead of a 3x3x3. Given a valid 1x1x1 Cube in any orientation, output which rotations of x
/x'
, y
/y'
, and/or z
/z'
are required to have green at the front and white at the top.
Input:
The input will be a 1x1x1 Cube layout in the following format (where F
is the front, and U
is the top):
U
LFRB
D
For example:
Y
BRGO
W
Output:
The output will be the least amount of rotations of x
/x'
, y
/y'
, and/or z
/z'
required to have the white center at the top and green center at the front.
x y z
x' y' z'
We basically always want to end up in this orientation:
W
OGRB
Y
The example given above would therefore result in either of these outputs: x2y
/xxy
/x'x'y
.
NOTE: In the still image of the gifs above, White is the Upper face and Red is the Front face. So the still image of the gif is:
W
GRBO
Y
Challenge rules:
- You are allowed to take the input in any reasonable format.
- You could use other characters or numbers (i.e.
0-5
/1-6
) instead ofWYROGB
- You can take the input as single String, as new-line delimiter single String, as String-array, character-array or -matrix, integer-array or -matrix, etc. Your call. (For example,
WOGRBY
is a valid input in the formatULFRBD
.) - Please specify what input-format you've used!
- You could use other characters or numbers (i.e.
- The output must use
xyz
, but instead ofx'
you are also allowed to usex3
orX
, or instead ofx2
you can also usexx
(NOTE: You are NOT allowed to usexxx
instead ofx'
/x3
/X
).- Always output the least amount of rotations. So although
x'x'y'y'y'
instead ofx2y
results in the same orientation of the Cube in the end, it's not a valid output because there is a better alternative. Same applies tox2y2
, becausexy'z
is one move shorter (x2
/xx
counts as two moves).
As thumb rule: every possible input results in 0-2x
, 0-2y
and/or 0-2z
rotations, and you'll never need more than three rotations in total (i.e.x2z2
→y2
)
- Always output the least amount of rotations. So although
- You can assume all inputs are valid 1x1x1 Cubes.
- If the input is already in the correct position (green front, white top), output nothing (or something indicating nothing, like
null
,false
,0
, an error, etc.)
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
Test cases:
Input: Output (multiple valid answers are possible for some):
Y
BRGO x2y y'x2 z2y' yz2 zy'x zxz xzx xyz
W
W
OGRB nothing
Y
G
RWOY y2x' z2x yzy xy2 x'z2 yx'z zxy zyz
B
W
RBOG y2
Y
R
BWGY yz zx xy
O
G
WOYR x'z zy yx'
B
@Arnauld About your first comment. Some of your answers seem to be slightly incorrect. It looks like you're mixing up moves sometimes. Just double checked, but all outputs currently given should be correct. I could have missed other valid outputs however. – Kevin Cruijssen – 2018-02-10T18:25:56.353
1There must be something that we're interpreting differently. The way I understand it, the still image in the GIF is
WRBOGY
inULFRBD
format. Is that correct? – Arnauld – 2018-02-10T19:17:36.887@Arnauld Ah, now I understand the confusion. I'll edit it, but in the still image of the gif it's
U=W; F=R; R=B; D=Y; B=O; L=G
. So White is the Top, Red is the Front. So used to that orientation on puzzles myself that I forgot that others might not.. – Kevin Cruijssen – 2018-02-10T19:23:16.980if all the puzzles cost $15, you spent ~ $6000 bro... solid life goals xD – FantaC – 2018-02-10T19:56:19.053
2Avatar checks out. – Rɪᴋᴇʀ – 2018-02-10T20:23:58.580
1Gotcha! Here is what I have now:
1:[ 'zzY', 'zYx', 'zxz', 'yzz', 'Yxx', 'xzx', 'xyz', 'xxy' ], 2:[ '' ], 3:[ 'zzx', 'zyz', 'zxy', 'yzy', 'yyX', 'yXz', 'xyy', 'Xzz' ], 4:[ 'yy' ], 5:[ 'zx', 'yz', 'xy' ], 6:[ 'zy', 'yX', 'Xz' ]
. – Arnauld – 2018-02-10T20:50:45.153@Arnauld All test cases check out, so I've added the ones I missed. Well done! – Kevin Cruijssen – 2018-02-11T10:41:30.440
@tfbninja Although I don't want to think about it, 6k seems about accurate. Cheapest puzzles were gifts (so free), most expensive 600 USD. I think average of about 17.5 is more accurate due to some expensive ones. Ah well. – Kevin Cruijssen – 2018-02-11T10:43:38.653