Regarding approach to solving sliding tiles puzzle

混江龙づ霸主 提交于 2019-12-11 08:59:51

问题


I have started reading "Think Like A Programmer" by V Anton Spraul. Here is the question.

The train technique mentioned in the book works fine for the example sighted in it. I was attempting to write the train approach method to solve the sliding tiles problem.

Assuming that I am working on subset of the complete problem, for the below set of tiles (as given as example in the book), the approach mentioned works fine.

6 8 .

5 4 7

We move anti-clock wise until we get 4,5,6 in order in top row and then slide 8 over empty space to get all in order.

But for the below, I could not find any suitable method

. 8 6

7 4 5

Is it possible that there can be permutations where the puzzle is unsolvable?

Thanks,

/MS


回答1:


Yes, in fact some puzzles are unsolvable. The way to find out is to try to solve two puzzles at a time: one being the original puzzle, and one being the original puzzle with two tiles switched. When you solve one puzzle, you know that the other one cannot be solved.



来源:https://stackoverflow.com/questions/15733394/regarding-approach-to-solving-sliding-tiles-puzzle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!