was: A little programming chalenge: My solution, the principle


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?


Possibly Related Threads...
Thread Author Replies Views Last Post
  [HP-PIRME] BUG Pretty Print, Solution: abs => |...|, ABS => ||...|| CompSystems 2 1,472 12-13-2013, 09:36 AM
Last Post: CompSystems
  [OT] engineering student chalenge cyrille de Brébisson 1 957 11-25-2013, 10:06 PM
Last Post: FORTIN Pascal
  [HP-Prime xCAS] Arrays: Programming Commands (solution to the ambiguity) CompSystems 6 1,808 08-30-2013, 06:32 PM
Last Post: CompSystems
  HP-Prime: Solution to ambiguity with [ ... ] & another BUGs CompSystems 12 2,527 08-28-2013, 08:48 AM
Last Post: CompSystems
  Advanced User's Manual and solution to the ambiguity of data types [HP-Prime xCAS] CompSystems 15 4,111 08-20-2013, 03:37 PM
Last Post: Thomas Klemm
  HHC 2012 RPN Programming Contest - 10-Step Way-After-Nashville Solution Jeff O. 32 4,953 10-12-2012, 01:41 AM
Last Post: Paul Dale
  41CL: Linux/Mac connection solution (soon) Geir Isene 28 4,453 06-10-2012, 01:21 PM
Last Post: Ángel Martin
  71B vs 41CL The HP "Certainty Principle" John W Kercheval 12 2,312 05-06-2012, 09:47 AM
Last Post: John W Kercheval
  [WP34S] Cheap Overlay Solution Courtesy of Kinkos Les Wright 5 1,252 11-28-2011, 02:38 PM
Last Post: Walter B
  The solution to the quartic equation on the HP50g, revisited Crawl 0 559 10-12-2011, 07:33 PM
Last Post: Crawl

Forum Jump: