Easiest to code algorithm for Rubik's cube?

前端 未结 7 2301
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 03:59

What would be a relatively easy algorithm to code in Java for solving a Rubik\'s cube. Efficiency is also important but a secondary consideration.

7条回答
  •  独厮守ぢ
    2021-01-31 04:51

    The simplest non-trivial algorithm I've found is this one:

    http://www.chessandpoker.com/rubiks-cube-solution.html

    It doesn't look too hard to code up. The link mentioned in Yannick M.'s answer looks good too, but the solution of 'the cross' step looks like it might be a little more complex to me.

    There are a number of open source solver implementations which you might like to take a look at. Here's a Python implementation. This Java applet also includes a solver, and the source code is available. There's also a Javascript solver, also with downloadable source code.

    Anthony Gatlin's answer makes an excellent point about the well-suitedness of Prolog for this task. Here's a detailed article about how to write your own Prolog solver. The heuristics it uses are particularly interesting.

提交回复
热议问题