Skip to main content
Fixed math error
Source Link
Spencer Rathbun
  • 3.6k
  • 1
  • 22
  • 28

How about nodes and pointers?

Assuming there is always 6 faces, and that 1 node represents 1 square on 1 face:

r , g , b
r , g , b
r , g , b
|   |   |
r , g , b - r , g , b
r , g , b - r , g , b
r , g , b - r , g , b

A node has a pointer to each node next to it. A circle rotation just migrates the pointer Height(Number of nodes/Number of faces)-1 nodes over, in this case 2. Since all rotations are circle rotations from the perspective of that facing, you just build one rotate function. It is recursive, moving each node one space, and checking if it has moved them enough, since it will have collected the number of nodes, and there is always four faces. If not, increment the number of times moved value and call rotate again.

Don't forget it's doubly linked, so update the newly pointed nodes as well. There will always be HeightWidth number of nodes moved, with one pointer updated per node, so there should be HeightWidth*2 number of pointers updated.

Since all the nodes point to each other, just walk around on circle updating each node as you come to it.

This should work for any sized cube, without edge cases or complex logic. It's just a pointer walk/update.

How about nodes and pointers?

Assuming there is always 6 faces, and that 1 node represents 1 square on 1 face:

r , g , b
r , g , b
r , g , b
|   |   |
r , g , b - r , g , b
r , g , b - r , g , b
r , g , b - r , g , b

A node has a pointer to each node next to it. A circle rotation just migrates the pointer Height-1 nodes over, in this case 2. Since all rotations are circle rotations from the perspective of that facing, you just build one rotate function. Don't forget it's doubly linked, so update the newly pointed nodes as well. There will always be HeightWidth number of nodes moved, with one pointer updated per node, so there should be HeightWidth*2 number of pointers updated.

Since all the nodes point to each other, just walk around on circle updating each node as you come to it.

This should work for any sized cube, without edge cases or complex logic. It's just a pointer walk/update.

How about nodes and pointers?

Assuming there is always 6 faces, and that 1 node represents 1 square on 1 face:

r , g , b
r , g , b
r , g , b
|   |   |
r , g , b - r , g , b
r , g , b - r , g , b
r , g , b - r , g , b

A node has a pointer to each node next to it. A circle rotation just migrates the pointer (Number of nodes/Number of faces)-1 nodes over, in this case 2. Since all rotations are circle rotations, you just build one rotate function. It is recursive, moving each node one space, and checking if it has moved them enough, since it will have collected the number of nodes, and there is always four faces. If not, increment the number of times moved value and call rotate again.

Don't forget it's doubly linked, so update the newly pointed nodes as well. There will always be HeightWidth number of nodes moved, with one pointer updated per node, so there should be HeightWidth*2 number of pointers updated.

Since all the nodes point to each other, just walk around on circle updating each node as you come to it.

This should work for any sized cube, without edge cases or complex logic. It's just a pointer walk/update.

added 203 characters in body
Source Link
Spencer Rathbun
  • 3.6k
  • 1
  • 22
  • 28

How about nodes and pointers?

Assuming there is always 6 faces, and that 1 node represents 1 square on 1 face:

r , g , b
r , g , b
r , g , b
|   |   |
r , g , b - r , g , b
r , g , b - r , g , b
r , g , b - r , g , b

A node has a pointer to each node next to it. A circle rotation just migrates the pointer 2Height-1 nodes over, in this case 2. Since all rotations are circle rotations from the perspective of that facing, you just build one rotate function. Don't forget it's doubly linked, so update the newly pointed nodes as well. There will always be HeightWidth number of nodes moved, with one pointer updated per node, so there should be HeightWidth*2 number of pointers updated.

Since all the nodes point to each other, just walk around on circle updating each node as you come to it.

This should work for any sized cube, without edge cases or complex logic. It's just a pointer walk/update.

How about nodes and pointers?

Assuming there is always 6 faces, and that 1 node represents 1 square on 1 face:

r , g , b
r , g , b
r , g , b
|   |   |
r , g , b - r , g , b
r , g , b - r , g , b
r , g , b - r , g , b

A node has a pointer to each node next to it. A circle rotation just migrates the pointer 2 nodes over. Since all rotations are circle rotations from the perspective of that facing, you just build one rotate function. Don't forget it's doubly linked, so update the newly pointed nodes as well. There will always be HeightWidth number of nodes moved, with one pointer updated per node, so there should be HeightWidth*2 number of pointers updated.

This should work for any sized cube.

How about nodes and pointers?

Assuming there is always 6 faces, and that 1 node represents 1 square on 1 face:

r , g , b
r , g , b
r , g , b
|   |   |
r , g , b - r , g , b
r , g , b - r , g , b
r , g , b - r , g , b

A node has a pointer to each node next to it. A circle rotation just migrates the pointer Height-1 nodes over, in this case 2. Since all rotations are circle rotations from the perspective of that facing, you just build one rotate function. Don't forget it's doubly linked, so update the newly pointed nodes as well. There will always be HeightWidth number of nodes moved, with one pointer updated per node, so there should be HeightWidth*2 number of pointers updated.

Since all the nodes point to each other, just walk around on circle updating each node as you come to it.

This should work for any sized cube, without edge cases or complex logic. It's just a pointer walk/update.

Source Link
Spencer Rathbun
  • 3.6k
  • 1
  • 22
  • 28

How about nodes and pointers?

Assuming there is always 6 faces, and that 1 node represents 1 square on 1 face:

r , g , b
r , g , b
r , g , b
|   |   |
r , g , b - r , g , b
r , g , b - r , g , b
r , g , b - r , g , b

A node has a pointer to each node next to it. A circle rotation just migrates the pointer 2 nodes over. Since all rotations are circle rotations from the perspective of that facing, you just build one rotate function. Don't forget it's doubly linked, so update the newly pointed nodes as well. There will always be HeightWidth number of nodes moved, with one pointer updated per node, so there should be HeightWidth*2 number of pointers updated.

This should work for any sized cube.