puzzleup2015::coloredcubes

COLORED CUBES

You have red, blue and green unit cubes. You will create a 2x2x2 cube by using 8 of these unit cubes. What is the maximum number of different cubes you can create?

Note: If a cube can be obtained by rotating another one, these two cubes are not considered to be different.

If the problem was asked for only red and blue unit cubes, the answer would be 23.


Below the code is to solve the problem for two colors. If You modify it according to the constraint given in the puzzle and run the code, You may view the result. 

You should change the colortable array, its size should be equal to pow(3,8) as there will be 3 colors. One more thing to be changed is the loop end in 'Solve' function.

The code starts here:
colortable=[[] for i in range(256)]

#The table below holds the same configuration of a cube labeled (1-2-3-4 (On top) 
and (5-6-7-8 (On bottom). The table's size is 24.
cubes=[[1,2,3,4,5,6,7,8],[1,3,5,7,2,4,6,8],[1,5,2,6,3,7,4,8],
       [2,1,6,5,4,3,8,7],[2,4,1,3,6,8,5,7],[2,6,4,8,1,5,3,7],
       [3,1,4,2,7,5,8,6],[3,4,7,8,1,2,5,6],[3,7,1,5,4,8,2,6],
       [4,3,2,1,8,7,6,5],[4,2,8,6,3,1,7,5],[4,8,3,7,2,6,1,5],
       [5,6,1,2,7,8,3,4],[5,1,7,3,6,2,8,4],[5,7,6,8,1,3,2,4],
       [6,8,2,4,5,7,1,3],[6,5,8,7,2,1,4,3],[6,2,5,1,8,4,7,3],
       [7,8,5,6,3,4,1,2],[7,3,8,4,5,1,6,2],[7,5,3,1,8,6,4,2],
       [8,6,7,5,4,2,3,1],[8,7,4,3,6,5,2,1],[8,4,6,2,7,3,5,1]]

lis,count=[],0
#This is for generating all possible colors and the count of them is 256 for two colors.
def GenerateAllColors(lis):
    global count
    for i in range(2):
        lis.append(i)
        if len(lis)<8:
            GenerateAllColors(lis)
        else:
        
            colortable[count][0:8]=lis[0:8]
            count+=1

        lis.pop()

GenerateAllColors([])



def Solve():
    indexes=[]
    for i in range(256):
        colors=colortable[i]
        
        for j in range(len(cubes)):
            newcolor=[-1]*8
            for k in range(8):
                newcolor[k]=colors[cubes[j][k]-1]

            #print(colors,newcolor,cubes[j])

            for m in range(i+1,len(colortable)):
                if colortable[m]==newcolor and m not in indexes:
                    indexes.append(m)

    print(indexes,len(indexes))
    # The result is 256-len(indexes) and this means 23. 
                
            
               
            

Solve()