# Define the cube size
n = 3
# Create a 3D list to represent the magic cube
cube = [[[0 for _ in range(n)] for _ in range(n)] for _ in range(n)]
# Fill the cube with numbers from 1 to n^3
num = 1
for i in range(n):
for j in range(n):
for k in range(n):
cube[i][j][k] = num
num += 1
# Rotate the cube along the x-axis
def rotate_x(cube):
new_cube = [[[0 for _ in range(n)] for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
new_cube[i][j][k] = cube[n-1-k][j][i]
return new_cube
# Rotate the cube along the y-axis
def rotate_y(cube):
new_cube = [[[0 for _ in range(n)] for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
new_cube[i][j][k] = cube[i][n-1-k][j]
return new_cube
# Rotate the cube along the z-axis
def rotate_z(cube):
new_cube = [[[0 for _ in range(n)] for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
new_cube[i][j][k] = cube[j][i][n-1-k]
return new_cube
# Print the original cube
print("Original Cube:")
for i in range(n):
for j in range(n):
for k in range(n):
print(cube[i][j][k], end=" ")
print()
print()
# Rotate the cube along the x-axis and print
cube = rotate_x(cube)
print("Rotated Cube along the x-axis:")
for i in range(n):
for j in range(n):
for k in range(n):
print(cube[i][j][k], end=" ")
print()
print()
# Rotate the cube along the y-axis and print
cube = rotate_y(cube)
print("Rotated Cube along the y-axis:")
for i in range(n):
for j in range(n):
for k in range(n):
print(cube[i][j][k], end=" ")
print()
print()
# Rotate the cube along the z-axis and print
cube = rotate_z(cube)
print("Rotated Cube along the z-axis:")
for i in range(n):
for j in range(n):
for k in range(n):
print(cube[i][j][k], end=" ")
print()
print()
Original Cube: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Rotated Cube along the x-axis: 19 10 1 22 13 4 25 16 7 20 11 2 23 14 5 26 17 8 21 12 3 24 15 6 27 18 9 Rotated Cube along the y-axis: 25 22 19 16 13 10 7 4 1 26 23 20 17 14 11 8 5 2 27 24 21 18 15 12 9 6 3 Rotated Cube along the z-axis: 19 22 25 20 23 26 21 24 27 10 13 16 11 14 17 12 15 18 1 4 7 2 5 8 3 6 9