HP Forums

Full Version: was: A little programming chalenge: My solution, the principle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Hi all,

Contrary to what I expected, I did not present my solution at HHC 2010 because the schedule was too tight. Instead, I presented it after the conference in short comity.

As said previously, one sub-problem is to know how many cells can be filled for the current shape.

Said otherwise, the whole thing is about having a tool that tells you that you can’t reach the maximum as soon as possible, in order to abort useless search as soon as possible.

My solution is to build a table which answers the 2 problems. When the table is filled, it tells the maximum number of cells that can be filled for the current shape.

I build the table cell by cell, starting by the last cell and going backward, so the part of the table already built is useful to build itself for the previous cell. And the process is repeated until the table is full.

I build the table by asking a question: while adding 1 more cell, can I find a filling order which allow 1 more cell filled?

Do you need more details?

Is it efficient? Yes it is! A square of 9*9 is filled in less than a second (actually it is closer to 0.1 second)


Hi Patrice,

Yes, more details please. I have tried to fill in the details based on what you've said and it seems to me to be more complicated than you imply. I'm probably missing something. Perhaps if you give an example.


Hi all,

The following is to be saved as a csv file and then opened in excel. This sample data is from the filling of a square of 9*9.


It contains 4 pairs of columns, each pair is the data for a serie in a graphic, the type of graphic is cloud of points, choose the sub type with line between points.

The principle of the graphic is to move up every time you fill a cell, and move left every time a cell is empty.

The max curve: shows the ending point of a filling depending on how many cells are filled.

The top curve: each point shows how many filled cells can be fitted in the beginning of the shape. It is not possible to preform better than the max curve without breaking the rules. Each point says for the x fist cells, you can fill y cells without breaking the rules.

The bot curve: is the top curve rotated a half turn.

The real curve: is the only path leading to the only filling with the maximum score.

All the trick is the bot curve, for every point, it says: in the last x cells, you can fill y cells to the maximum. if ever your current path goes right to this curve, you will never be able to reach the maximum, you can abort the search and backtrack.

How does it work ? simple! when you begin the fill the shape or a part, you perform better than the bot curve, just count the difference between your path and the curve, if negative, you are on the right of the bot curve.

Every time you check a cell in the shape, you look at the corresponding cell in your table.
if you can fill the cell and the table says true, the path and curve are parallel.
if you can not fill the cell and the table says false, the path and curve are parallel.
if you can fill the cell and the table says false, you gain 1 spare filled cell.
if you can not fill the cell and the table says true, you loose 1 spare filled cell.
as long as the number of spare cells in not negative, you can continue the search.

The main search program is a binary tree explorer deep first, the alternatives are a cell filled or empty. what is not standard is the code to keep track of the spare cells.

Whishing this helps

For more details, just tell which part is not clear.


Hi Dave,

How is your progress?