Automatic sliding puzzle

I’d like to create what I’m not sure how to call it so I’ll just call it a ‘sliding puzzle’:

it’s one of those things where each piece of the puzzle contains part of an image. They’re scrambled and one piece is missing so you can then slide other pieces thereby re0arranging the pieces to recreate the image…

clear? ok, now what I’d like to do is create one of these things that re-arranges automatically…

so the puzzle initially looks like this:

384
152
76x

where ‘x’ is the missing part. by sliding the pieces it will at the end look like this:

123
456
78x

I’m not sure where to start on this. I’m thinking I will have to dive into path-finding tutorials…
Any ideas?