Question: In Java, Write a program to solve this problem with the fewest number of moves. Theinput consists of a 9-digit string containing one each of

In Java, Write a program to solve this problem with the fewest number of moves. Theinput consists of a 9-digit string containing one each of the digits 19.

In Java, Write a program to solve this problem with the fewestPlease give me anything, I don't understand how to do this so even anything helps

Relevant topics: array lists, stacks, queues. You are given a frame that fits 9 square blocks. The frame contains 8 blocks, numbered 1 through 8, leaving one location empty. You can shift a neighboring block into the empty space, and your goal is to find a sequence of moves that results in the blocks numbered 1 through 8 going left to right, top row to bottom, with the lower right position empty. For example, the following sequence of configurations solves the puzzle: 1 1 2 3 1 2 3 4 8 7 6 5 4 7 2 3 8 5 6 1 4 7 2 3 5 6 2 3 5 8 6 4 7 6 1 2 3 4 5 7 8 6 4 7 8 Write a program to solve this problem with the fewest number of moves. The input consists of a 9-digit string containing one each of the digits 1 -9. The first three digits represent the first row, the next three digits represent the second row, and the last three digits represent the last row. The digit '9' represents the space. For example, the initial state of the puzzle given above would be represented by 123489765. The output is either a sequence of strings giving the configurations of a solution, or -1 if no solution exists. For example, if the input is 123489765 then a correct output is 123489765 123485769 123485796 123495786 123459786 123456789 If the input is 812943765 then the correct output is -1 since the problem cannot be solved. If the input is 123456789 then the correct output is 123456789 since the problem is already solved. Notice that if there is a solution with n moves, then your program should print out n + 1 lines, starting with the input line. 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!