Easiest to code algorithm for Rubik's cube?

前端 未结 7 2171
爱一瞬间的悲伤
爱一瞬间的悲伤 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:57

    One solution is to I guess simultaneously run all possible routes. That does sound stupid but here's the logic - over 99% of possible scrambles will be solvable in under 20 moves. This means that although you cycle through huge numbers of possibilities you are still going to do it eventually. Essentially this would work by having your first step as the scrambled cube. Then you would have new cubes stored in variables for each possible move on that first cube. For each of these new cubes you do the same thing. After each possible move check if it is complete and if so then that is the solution. Here to make sure you have the solution you would need an extra bit of data on each Rubiks cube saying the moves done to get to that stage.

    0 讨论(0)
提交回复
热议问题