Difficult Challenge - Hint (Spoiler)

Add a reply

Posted by Mark Byers 728 days ago:
If you try to implement the algorithms explained on Wikipedia you will soon realise that the code becomes quickly becomes quite complicated. But do not despair... there is at least one simple way to approach the problem which leads to a much more concise solution. I want to let people have a go at finding this solution themselves first, but I will offer some help those that are stuck.



If you want to try to solve this challenge on your own first, stop reading now.




Here is an outline of an algorithm you can use:

Rules 3.1 to 3.7 on Wikipedia can all be considered as a special case of the 'contradiction' rule, but limited to considering just a single row. For example, if you have a clue 4 3 in a row of length ten and you try to guess that the fourth cell is unfilled, you get the following situation:

_ _ _ O _ _ _ _ _ _ 4 3

(_ = unknown, O = unfilled, X= filled)

It is now impossible to place all the Xs in the row to satisfy the clue (writing the code to check that there is no way to place the Xs is most interesting part of implementing this algorithm, and there is a simple way to do this too). This contradiction means that the fourth cell cannot be unfilled, so it must be filled instead (X).

_ _ _ X _ _ _ _ _ _ 4 3

Repeating this logic for each cell in the row you can discover that 3rd, 4th and 8th squares must be filled. The other squares in the row are still unknown (no contradiction can be found). This is gives the same result as the Simple Boxes rule. Implementing this simplified version of the contradiction method covers all the rules from 3.1 to 3.7 and is enough to solve all the puzzles your code will be given.

If you are still having problems getting the algorithm working, I can post another hint and/or some pseudo-code you can use to get a working version that you can then golf.
Posted by pfft 723 days ago:
Thanks for the tip, I have managed to get "run 0" (the glider) and run 1 (the plus) to work using this. I've added some of my own ideas to get run 2 (the smiley) to work but so far run 3 (code golf) doesn't work yet. I'll take a closer look later and if I can't figure it out I'll post again.

Add a reply