How would you represent a Rubik's Cube in code?

前端 未结 11 1777
清酒与你
清酒与你 2020-12-07 09:52

If you were developing software to solve a Rubik\'s Cube, how would you represent the cube?

11条回答
  •  清歌不尽
    2020-12-07 10:05

    This ACM Paper describes several alternative ways that it has used to represent a rubik's cube and compares them against eachother. Sadly, I don't have an account to get the full text but the description states:

    Seven alternative representations of Rubik's Cube are presented and compared: a 3-by-3-by-3 array of 3-digit integers; a 6-by-3-by-3 array of literals; a 5-by-12 literal matrix; an ll-by-ll sparse literal matrix; a 54-element vector; a 4-dimension array; and a 3-by-3-by-3 nested array. APL functions are given for orientation moves and quarter-turns plus several useful tools for solving the cube.

    Also, this RubiksCube.java file contains a pretty clean representation along with the relevant code for rotating the sections (if you are looking for actual code). It uses a cell and faces array.

提交回复
热议问题