你如何在代码中代表魔方? [英] How would you represent a Rubik's Cube in code?
问题描述
如果您正在开发软件来解决魔方,您将如何代表多维数据集?
If you were developing software to solve a Rubik's Cube, how would you represent the cube?
推荐答案
这个 ACM Paper 介绍了几种替代方法,代表一个红宝石的立方体,并将它们与彼此进行比较。不幸的是,我没有帐号来获取全文,但描述如下:
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:
提供了Rubik Cube的七个替代表示形式,比较:一个3×3×3数组的3位整数;一个6×3×3的文字数组;一个5×12字面矩阵;一个ll-by-ll稀疏文字矩阵;一个54元素的矢量;一个四维数组;和3×3×3的嵌套数组。给定APL功能,用于定向移动和四分之一圈加上几个用于求解多维数据集的有用工具。
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.
此外,这个 RubiksCube.java 文件包含一个非常干净的表示形式以及相关的代码,用于旋转这些部分(如果您正在寻找实际的代码)。它使用一个单元格并面向数组。
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.
这篇关于你如何在代码中代表魔方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!