This was done solely in Maya. First I have made a script which rotated the cubes around.
For solving the cube i have made a Python script which used a solution I extracted from a Java applet.