Help for Nige's Hanjie puzzle solver

These are puzzles which when solved by logical deduction produce a picture in a grid. There's a simple description at Puzzlemix.com.

There are many solvers on the internet, but I have deliberately avoided consulting and re-creating those. Instead, with reference to a book of such puzzles, of which I bought copies for both myself and my sister for Christmas 2020, I programmed the rules that I used to solve the puzzles, adding more rules as needed to solve more complex puzzles. The result is this site.

Preparing a puzzle file

This solver reads puzzles that are stored in plain text files (*.txt). These can be prepared using a text editor such as Notepad on a Windows PC, or TextEdit on a Mac, and saved on your computer.

For example, here is the sample puzzle from the Puzzlemix site:

Hanjie example

And here are the contents of a text file that describes this puzzle for this solver:


columns
2,2
2,1
1,1
2,1
2,2

rows
2,2
2,2
1
1,1
5

Notes:

Glossary

DotA known blank cell. When solving a puzzle on paper, a dot or a cross is used to distinguish a blank cell from an unknown cell.
RunA contiguous set of non-dot cells in a row or column, flanked by dots or the ends of the row or column.
SequenceIn the puzzle definition, this is a target number of contiguous filled cells within that row or column.
ClumpA contiguous set of filled cells in the current state of a row or column.
Fixed RunsAt the start and/or the end of a column or row, there may be fixed runs which are associated with a clump and a single sequence.
Free RunsAll runs within a row or column that are between the fixed runs.

For example: a row of the grid

The target sequences for this row of the puzzle are 1 and 6. Two dots separate the three runs, the third of which contains a clump of four cells. The third run is a fixed run as it must contain only the sequence of 6 and its clump; the first and second runs are free runs.

Solver Buttons

Complete Solve

Makes as much progress as it can, hopefully completing the solve. A message is displayed indicating its success or otherwise.

Step-by-Step Solve

Finds the next row or column where the solver can make any changes, illustrates the changes in the grid and describes them in the grey text area. Repeated use of this button steps through the solve.

Restart This Puzzle

Clears the grid and resets this puzzle, ready for you to start again.

Check Your Manual Solve

If you have attempted to solve a puzzle by hand (see below), this button checks your work and lets you know how you have done.

Manual solving

This allows you to solve a puzzle yourself by clicking on the cells in the grid, perhaps to assist the solver when it cannot complete a puzzle itself.

If you get stuck with your manual solve, try the "Step-by-Step Solve" button to see whether the solver can find the next step. You may eventually see a cryptic error message if you have gone wrong though.

Supported Browsers

This solver has been tested using these web browsers on these operating systems:

N.B. It is known NOT to work with Microsoft Internet Explorer (Windows 10), as the coding techniques used by this solver are not all supported by this browser.

Version History

VersionDateChanges
1122/05/2021Messages in step-by-step solves are now colour-coded for easier identification.
Re-selection of the same file improved after errors in it have been corrected.
Restart this Puzzle button prompts for confirmation if the puzzle is incomplete.
1013/03/2021Button added to allow you to check your manual solve.
Sequence allocation to runs improved to ensure that each run with a clump has a sufficiently-long sequence.
Significant re-write of clump analysis to allow identification of full sequences in more circumstances.
Bug fix: switching from a step-by-step solve to a manual solve now clears cell highlighting.
Puzzle validation message improved to help you find the problem if sequence totals do not match.
903/03/2021Manual solving added with left and right mouse clicks.
Improvements to what text is printed, e.g. the puzzle file name.
Grid lines are not quite black, and so are now visible among filled cells.
Bug fix: cell highlighting is no longer printed.
801/03/2021Improve sequence partitioning to ensure that all runs having clumps are associated with a sequence.
Improve the message displayed when a row or column with no sequences is filled with dots.
Help page and feedback email links added.
722/02/2021Removed the horizontal lines from the cosmetic top left corner.
Surround with dots all free clumps of the same length as the longest free sequence.
Separate with a dot all free run clumps that are one cell apart but cannot be merged.
Complete Solve button now indicates success or otherwise.
612/02/2021Degrees of Freedom and Start or End Known rules are more widely applicable.
Apologetic message added for Internet Explorer users.
Fixed a bug in the clump merge algorithm to only consider sufficiently long sequences.
510/02/2021Partitioning sequences to runs now fixes all initial and final sequences to runs containing suitable clumps.
Special first and last clump rules now apply to the first and last FREE clumps.
Improvements to special first and last free clump cell filling (for clumps at or near the run start/end).
Better messages to explain which sub-rules of the special first/last free clump rule were used.
Improvements to messages re: singular and plural words.
402/02/2021Restart this puzzle button added.
Printing improvements: irrelevant controls not printed, tip about printing backgrounds added.
Puzzle definitions that include empty rows or columns are now handled correctly.
329/01/2021Step by step solving implemented.
Rule improvements around first and last clumps.
224/01/2021Bug fix: allow text files on Windows systems with CRLF line endings to be read.
121/01/2021Initial release.