Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. The firstthree digits represent the first row, the next three digits represent the second row,and the last three digits represent the last row.

image text in transcribedHi I just need to get any form of code because I really do not understand it. I would rather get anything than nothing so if there is any code that you can give that will help a lot and I will upvote as well. Thank you.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

02 Legislative and regulatory processes.

Answered: 1 week ago