Suppose we have a square with side lengths S and N of copies of a rectangular tile with length X and width Y. The program should show all the ways in which these copies can be arranged in a grid, so that no two copies can touch each other .
By showing, I mean that it should show the set of coordinates of the upper left corners of each copy in the grid.
I tried to do it as follows:
Find the base case when I try to place each copy with 1 square division. For example, for 6 copies of a 1x2 tile in a 6x6 grid, the base case
xx_xx_ ______ xx_xx_ ______ xx_xx_ ______
Move the last fragment to possible positions.
Return the last tile to the base case, move the tile to the last to a possible position. Repeat step 2.
Do this for each tile.
Basically the problem is that I cannot find cases where the difference in the number of rows or columns is 1, but they do not touch each other. For example, I cannot find this case:
xx____ This tile ___xx_ and this one has a difference in row numbers 1. xx____ ___xx_ xx____ ___xx_
Can you offer something? Or maybe a more efficient algorithm?
NOTE. I am trying to implement it in Prolog.
source share