# Thread: Typedef Structs inside Typdef structs

1. Originally Posted by CommonTater
Seems to me the representation is much simpler than that...

You have 6 faces, each a 3x3 matrix...
Code:
`int rubic[6][3][3];`
The problem is not in how you depict it in data... the real task is how do you rotate the faces when rotating one of the 6 faces also rotates one row of the 4 adjoining faces... Seems to me the real magic is in the code not the picture.
I understand your point of view, and you are completely right when you say that the problem is rotating it. That is why, the closer I can find how it works in reality, the closer I am so solving the problem "getting a working algorithm".

That is a much simpler representation, but then again, the problem of rotating it comes in the way. But if i have the [3][3][3] matrix, i can use simple matrix rotations. I've been googling around and found these solutions for the rotation:

c# - How to Rotate a 2D Array of Integers - Stack Overflow

java - Rotate array clockwise - Stack Overflow

I think they would work with the cube.

Rubiks Cube Screen Saver - The Toids World

The problem with each face being a 3 x 3 x 3 is you don't actually have 27 elements... you have 9.
Where the logic of this would drive me batty is working out the agacency issues... As you say, rotating one face is actually pretty easy, but rotating one row of each adjacent face ... onto another face ... now that's some true digital legerdemain.

Although... I shold warn you, I'm probably not the right person to talk to about Rubik's Cube...
Back when they first came out a friend gave me one, nicely pre-scrambled, for my birthday. Well, I'm a sucker for a good puzzle and ended up spending most of my holiday from work on it, took it to work after, kept twisting away on it, almost all of my spare them, for upwards of 3 months before I solved it... And even then I figure I did it by accident, not skill. So I went down to a local hobby shop and got a trophy base for it, finished it all up real nice in black walnut. Drilled a hole and tapped a spike through the base, glued the cube so it would never move again, heated up the spike and melted one corner of the the cube onto the spike, so it looked like a proper trophy. Then I got out the engraving tools and wrote a suggestion that my friend should perform a sexual impossibility on the little brass plaque... and gave it back to him for Christmas. To this day, he still won't give me birthday gifts...

3. Originally Posted by CommonTater

Rubiks Cube Screen Saver - The Toids World

The problem with each face being a 3 x 3 x 3 is you don't actually have 27 elements... you have 9.
Where the logic of this would drive me batty is working out the agacency issues... As you say, rotating one face is actually pretty easy, but rotating one row of each adjacent face ... onto another face ... now that's some true digital legerdemain.

Although... I shold warn you, I'm probably not the right person to talk to about Rubik's Cube...
Back when they first came out a friend gave me one, nicely pre-scrambled, for my birthday. Well, I'm a sucker for a good puzzle and ended up spending most of my holiday from work on it, took it to work after, kept twisting away on it, almost all of my spare them, for upwards of 3 months before I solved it... And even then I figure I did it by accident, not skill. So I went down to a local hobby shop and got a trophy base for it, finished it all up real nice in black walnut. Drilled a hole and tapped a spike through the base, glued the cube so it would never move again, heated up the spike and melted one corner of the the cube onto the spike, so it looked like a proper trophy. Then I got out the engraving tools and wrote a suggestion that my friend should perform a sexual impossibility on the little brass plaque... and gave it back to him for Christmas. To this day, he still won't give me birthday gifts...
Ahahah, funny story

About the 9 elements, which ones would you suggest? the [6][3][3] array you talked about earlier?

The problem here would probably be the rotation. Whilst with the [3][3][3] array, I think it's easier to rotate (not sure).

I really appreciate all this discussion. It's getting very interesting, and I noticed that some people might think the same. I'll be glad to post my full solution once I made it. Thank you.

4. It's not necessarily easier to rotate the 3x3x3 "piece-based" representation since you also have to calculate new orientations for the pieces, whereas with the 6x3x3 "square-based" representation, although the basic rotation is more complicated, the orientation problem goes away. Also, the square-based rep. works well with bare ints, but the other requires a struct with type, orientation, colors....

5. Originally Posted by oogabooga
It's not necessarily easier to rotate the 3x3x3 "piece-based" representation since you also have to calculate new orientations for the pieces, whereas with the 6x3x3 "square-based" representation, although the basic rotation is more complicated, the orientation problem goes away. Also, the square-based rep. works well with bare ints, but the other requires a struct with type, orientation, colors....
Yep... treat it as a hollow cube. In the multiple piece method you have an additional complexity in that some of your small cubes have 1 side showing, some have 2 and some have 3... but none of them have all 6 so it's just a lot easier to envision as 6 flat surfaces...

Just give each colour a number... and let the rotation wrangling begin...

6. If it were me then I'd start with the 3x3x3 voxel with a colour for each voxel's face. At least this way I know exactly how to rotate it already.

Hey CommonTater, if only you had a lot of programming experience back then. You could have written a program to tell you exactly what moves are required to solve it. .
I read on newscientist that every initial starting point is solvable in twenty moves. Edit: found it, here's the link: 'God couldn't do faster': Rubik's cube mystery solved - physics-math - 11 August 2010 - New Scientist
Ya know I'm almost tempted to write a rubik solver myself now, a bit like how I wrote a sudoku solver some time ago. Hmm, we could make it into a competition.

7. I think, not sure, that you could consider the center square fixed in color and just rotate the edges around it.

I can not see any easy way to represent the data.

But, I think I would try 6 faces; I just not what I would use as the face structure/type.

Edit: Decided that a simple one dim array would be my first try if I tried to solve this problem. I think 0-19 would hold all the pieces locations. 8 top, 8 bottom and 4 sides. (I consider the center positions to never change)
The logic would not be simple to write; but, I think it would be easier that an 2 or 3 dim array solution.

Tim S.