Algorithm rotating a multidimensional array of Rubik's cube states