Class Solver
- Namespace
- NonoSharp
- Assembly
- NonoSharp.dll
A static class to solve Nonogram puzzles, or determine if they can be solved.
public static class Solver
- Inheritance
-
Solver
- Inherited Members
Remarks
The Solver will not make any guesses, meaning that puzzles with a valid and unique
solution that might require more advanced logical deduction,
or guesses in any other form, might be rejected.
Puzzles without one unique answer, are rejected.
Note that the runtime of solving a puzzle grows exponentially with its size.
For a quick runtime, keep puzzles small (~25x25). There are, however, no restrictions on the methods
regarding puzzle size.
Methods
IsSolvable(Nonogram)
Determines whether the puzzle in nonogram can be solved.
public static bool IsSolvable(Nonogram nonogram)
Parameters
nonogramNonogramThe
Nonograminstance to check solvability for.
Returns
- bool
trueif the puzzle can be solved,falseotherwise.
IsSolvable(Nonogram, out HashSet<CellPosition>?)
Determines whether the puzzle in nonogram can be solved.
public static bool IsSolvable(Nonogram nonogram, out HashSet<CellPosition>? solution)
Parameters
nonogramNonogramThe
Nonograminstance to check solvability for.solutionHashSet<CellPosition>The solution HashSet if
nonogramis solvable.nullif the puzzle is not solvable.
Returns
- bool
trueif the puzzle can be solved,falseotherwise.
IsSolvable(int, int, Clues[], Clues[])
Determines whether the puzzle constructed from the given dimensions and clues can be solved.
public static bool IsSolvable(int width, int height, Clues[] columnClues, Clues[] rowClues)
Parameters
widthintWidth of the puzzle to solve.
heightintHeight of the puzzle to solve.
columnCluesClues[]Column clues (usually shown on the top of the puzzle) for this puzzle.
rowCluesClues[]Row clues (usually shown on the right of the puzzle) for this puzzle.
Returns
- bool
trueif the puzzle can be solved,falseotherwise.
Exceptions
- ArgumentException
Thrown when the lengths of
columnCluesandrowCluesdo not matchwidthorheightrespectively.- ArgumentOutOfRangeException
Thrown when
widthorheightare non-positive.
IsSolvable(int, int, Clues[], Clues[], out HashSet<CellPosition>?)
Determines whether the puzzle constructed from the given dimensions and clues can be solved.
public static bool IsSolvable(int width, int height, Clues[] columnClues, Clues[] rowClues, out HashSet<CellPosition>? solution)
Parameters
widthintWidth of the puzzle to solve.
heightintHeight of the puzzle to solve.
columnCluesClues[]Column clues (usually shown on the top of the puzzle) for this puzzle.
rowCluesClues[]Row clues (usually shown on the right of the puzzle) for this puzzle.
solutionHashSet<CellPosition>The solution HashSet if the puzzle is solvable.
nullif the puzzle is not solvable.
Returns
- bool
trueif the puzzle can be solved,falseotherwise.
Exceptions
- ArgumentException
Thrown when the lengths of
columnCluesandrowCluesdo not matchwidthorheightrespectively.- ArgumentOutOfRangeException
Thrown when
widthorheightare non-positive.
Solve(Nonogram)
Solves the puzzle of Nonogram instance nonogram in-place.
public static HashSet<CellPosition> Solve(Nonogram nonogram)
Parameters
nonogramNonogramPuzzle to solve.
Returns
- HashSet<CellPosition>
The solution in a HashSet of CellPositions.
Remarks
If the given puzzle is not solvable, the returned solution will be incomplete. To ensure a complete solution, use IsSolvable(Nonogram, out HashSet<CellPosition>?).