Answered step by step
Verified Expert Solution
Question
1 Approved Answer
N and M will be at least 2 and no more than 5. IN JAVA A Sliding Block Puzzle is a type of puzzle in
N and M will be at least 2 and no more than 5.
IN JAVA
A Sliding Block Puzzle is a type of puzzle in which a an N by M rectangular grid contains a single blank space and (N*M)-1 numbered tiles. The goal of the puzzle is to arrange the puzzle such that the numbers are ordered left-to-right, top-to-bottom, with the empty space in the top left. This is achieved by repeatedly sliding adjacent tiles into the empty space and thus rearranging the puzzle. You will implement a function that will take a puzzle (represented as a 2d array of integers, with 0 representing the blank space) and return the minimum number of moves to bring it to a solution. If the puzzle has no solution, you should return -1. An example move: A solved puzzle: 163 163 8 72 -> 8 0 2 4 05 4 75 012 3 4 5 6 7 8 You may make the following assumptions: * All input will be well-formed: Puzzles will be rectangular, and will contain each number from 0 to (M*N) exactly once No inputs will be null, empty, or zero-length * N and M will be at least two and no more than 5 An engineer will review the code that you submit. Please include comments explaining your approach and thought processesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started