Summary
The goal of this challenge is to create an undone image-version of a 15-puzzle / sliding puzzle also called taquin in french.
Details:
Given an input composed of:
- an image,
- an integer
n
, - an other integer
r
,
your program, or function, or anything else that fits, must output the same image (i.e. same size and format) as the input, but that underwent the following process:
- divide the image into
n²
rectangles, - remove one of those rectangles, randomly,
- move a random number of contiguous rectangles from the line/column affected by point (2.) so the hole created is filled and another one is generated in this line/column. This number can be
0
if the blank is in a corner or an edge.
Repeat (3.) r
times.
Clarifications:
- If you moved rectangles from the line in step (3.), you must move rectangles from the column the in the next repetition,
- if you moved rectangles left-to-right in a line-step, they must be moved right-to-left in the next line-step, same for top-to-bottom and bottom-to-top concerning columns,
- you may assume that
n
will be chosen so it divides the lengths of the sides of the picture.
A last point:
An animated .gif
showing the whole process are very welcomed.
I propose to use the following picture (which is 1024x768
), with n=16
and r=100
as a model, you can use any other picture (as long as it's relevant and complies with SE's rules, of course).
Note that standards loopholes policies apply.
This is code-golf, so the shorter submission wins !
Since an example was requested, here is one, made "by hand", with n=4
and r=1
Steps 1 and 2
Step 3 : line-wise, 2 rectangles to the left
move a random number of contiguous rectangles
can it be 0 rectangles? (it would be a pain to make the program change behavior when the blank is on an edge/corner) \$\endgroup\$