Skip to content

commandline options

David Clamage edited this page May 16, 2021 · 1 revision

Command-line Options

Overview

When using the command-line solver, the following categories of options can be specified:

Alternatively, the solver can act as a server for website integrations.

  • [Required] Listen for websocket connections: --listen
  • [Optional] Specify a port to listen on (defualt 4545): --port=12345

Examples

These examples are designed to give you a general idea of how the solver command-line works. Explanations of each option follow in later sections. These examples do not have full coverage of all command-line options, including ways to import boards and options for solver behavior.

Example 1: Miracle Solution Count

-b=9 -c=knight -c=king -c=difference:neg1 -nt -o=miracle.txt

Summary: Calculate a solution count for a blank 9x9 board with the anti-knight, anit-king, and nonconsecutive constraints. Output solutions to a file named miracle.txt

Breakdown:

Parameter Explanation
-b=9 The input board is a blank 9x9 board.
-c=knight Use the anti-knight constraint.
-c=king Use the anti-king constraint.
-c=difference:neg1 Nonconsecutive. Specifically, use the difference constraint, passing a sub-parameter to it specifying to use a negative constraint on a difference of 1.
-nt This is actually two parameters, equivalent to -n and -t specified separately. This can be done with any parameter options which do not require a variable input.
-n This tells the solver that you want to calculate the solution count.
-t Enables multithreading, which uses all the cores of your CPU to achieve the solution more quickly.
-o=miracle.txt Output all solutions found to a file named miracle.txt. If this parameter isn't specified, then the solutions are discarded and only the count is found.

Example 2: Find a solution to a classic sudoku with a given string

-g=........1....23.4.....452....1.3.....3...4...6..7....8..6.....9.5....62.7.9...1.. -ps

Summary: Take an input board with givens and find a solution.

Parameter Explanation
-g=...etc The input board is a 9x9 grid, which is known because 81 values are given. . means that a cell is blank, and a number from 1-9 is a given. The values are given in order from left to right, then top to bottom.
-p Print the input board before finding the solution.
-s Find a solution using the brute-force solver.

Example 3: Logically solve a puzzle imported from f-puzzles

-f=N4IgzglgXgpiBcBOANCALhNAbO8QGYAGQgAgGUBXAIzAEIRUBDCtACwHsAnBEAJUYB2AczABrBiE4UcYGGh4A5LgFtGWchQAm7URRJSZJRgAdjWAJ4A6ADoDbZNIM2NOmkmxidl7ZXM9h4EgARCCFMMBIwNE4IAGNscxIIAVjOGEZZEgAzTh93VhgSKmkqEhgBTRs7AQcnFzcAaVzjUQgSAAoBdhIBGCFGDAA3Qtj2ASjORmS0AEpAkLC0CNljFwGYNypExhIAd1ZMQu00IzSSUfGYWJYIYctg0PDImFXJtA2i7aKsRljREmOJFYjGGRhIAEZ4AAmfQDCDsSwSIQxTQIADaaOAAF9kNjcTi8YSCcT8QBdZCYklE/E06nY8mU2lU5lMhl0lnsskUzk85lsjkC1ncwW8rmM0W8/lM6WS8noApeHx+bjwTEgLDJGBgdFovj4ADCABYJLxDUaTQBWc2oXhWi2W/UANhNZudNoNbr1+vtpNJBPVmu1qt1tv1AHYTY7wyaw9GbbGABwx/WISMph2pm1WpO+/0a3pBjF8cH68EmqH6qEmg34F2Vh21m1Rqvx0sgXNyzQQLJZTzlWK4NUDrBYQt8RDWvgJ81+3EgYej9FT70mic+/0Lse8acRm0TiOz0Cbpe8Cu7vgV52H+cwEdbqP2pszrFyt7w9FH2+L1UXye8EvGtex4/tu+pJja06pkBX5btOLbLrW0F3ieJbnqe0ZId+IbTsaEErn6fpAA= -pl

Summary: Import a board from f-puzzles and logically solve it, printing out the solve path.

Parameter Explanation
-f=N4I... Import a puzzle from an f-puzzles URL. This string is the base64 encoded puzzle, which can be found in the address bar when opening the puzzle.
-p Print the input board before finding the solution.
-l Attempt to find a solution using the logical solver.

Example 4: Generate real candidates with f-puzzles import/export

-f N4IgzglgXgpiBcBOANCA5gJwgEwQbT1AGMYA7AFxgwAUyiIAbAWQEMMBrMfAFmQDZkAdmQAOZIgC6AX2TEylGnUasOXeHl4DhYyTNAA3FgwCuceACZUaCPrIJyGU3pCGTZgMxWbd+A6eyXI1MEAEYvW1J7RxhnEgoqWlJ6ZjZOHn4hUXFpANdg+ABWcJ8/GIC4hUTklTT1TUydHLl4xSTlVLUNDO1pCWRCEAqEpRTVfDDPXiKtUSbB+WG20dq8CeQp7tnYhdbqjvxphuztlqr2sbrNxpPKkZrOje1j8p2z5c7LDZmROaHd85Wlk8T10L1Od326jCQPWV1+rwhF1WyBh9R6Uj6Az+b3u42Qk2Qh3RYNuS1xUPxsKJWxJiz2SOp11p/3e6W+z2apPpK0eWVBnLpAI+VLhN0FrPUMJB8PBZMhyNRouZOPl0MpaK2mIFLPJeEZHPmsu5nX1/MCblCxUivmizjyZks6G81tKdqCHitUX82pVSOlbot8F4ToiXrKPsRK1NMq5QoOoq1htjErwUr5MfFurTTIM7oQwesoZt3vN+SKIZKttyefgAgrLqrEblfvTAfyYXrYbFOvl2YN2MjwuBmv6TeN+BhjIzPaRk6VY7j6mj3d9PKOZoHzbX/urgZCK8HE8pO4XKbn32nq6HhITo6TmflvJz95na6KJ9LHs7xfDn8t39dXd8kdQtKxLTdx0ud9WyAsw61AhtwIRLcHhvYlT11J9ejvCDFwVEULwPFC8U+G9COVQ8lyuftkMgrp2Q3Wi8KfGijTwgkpyIujs0vSj8I4hpeOIilFWgn4MRwpiUzVL5BK4vCZLIuSKOEvV5xfK82WUjDHzQmkdKRATyIMwFj30jS+LVAT0L/JBPR/DFpCAA -rtuv

Summary: Generate real candidates for an imported f-puzzles and export the result as a new f-puzzles URL, opening it in your default browser.

Parameter Explanation
-f=N4I... Import a puzzle from an f-puzzles URL. This string is the base64 encoded puzzle, which can be found in the address bar when opening the puzzle.
-r Calculate the "true candidates" for the puzzle. These are candidates which can lead to a solution if given.
-t Multithreading.
-u Output the solution as an f-puzzles URL.
-v Attempt to automatically open the f-puzzles URL in the default browser.

Input Board Options

Board Size and Givens

These options are mutually exclusive, meaning you may only specify one of these options. They define the input board.

Short Parameter Long Parameter Sub Parameter Behavior
-b --blank n, a number between 1 and 31 The input is a blank board with no givens, of size n by n
-g --givens A string of length n^2 for n <= 9 or 2 * (n^2) for n between 10 and 31 The input string determines the board size, and each character (or set of two characters for boards 10 by 10 and larger) is a blank cell or given digit. A value of 0 or any non-numerical character (such as .) is treated as a blank cell. Cells are specified from left to right, then top to bottom.
-a --candidates A string of length n^3 for n <= 9 or 2 * (n^3) for n between 10 and 31 The input string determines the board size, and each character (or set of two characters for boards 10 by 10 and larger) is a possible candidate for a cell. A value of 0 or any non-numerical character (such as .) means that the candidate is unavailable. All candidates must be specified as either their value or a non-value character, and cannot be omitted. Candidates are specified from left to right, top to bottom, and within a cell are specified in numerical order.
-f --fpuzzles A string which is the base64 data for an f-puzzles board. Imports the board size, givens, and all constraints from the f-puzzles data. The base64 string can be found in the address bar for a newly-opened f-puzzles link, after the ?load=.

Additional Constraints

The constraint option can be specified multiple times to append specific constraints to the input board. This can even be used in combination with the -f f-puzzles import option to apply more constraints. Constraints have several parts: Format, Constraint Name, Groups of Cells

Format

-c=constraintname:group1;group2

Section Explanation
-c= Append a new constraint.
constraintname The name of the constraint to append.
: (Optional) Specify groups to pass into the constraint.
group1 (Optional) The first group to pass into the constraint.
; (Optional) Separates groups.
group2 (Optional) The second group to pass into the constraint.
;... (Any number of groups may be specified)

Constraint Name

See List of Constraints for a comprehensive list of constraints and what groups can be specified for those constraints.

Groups of Cells

Each constraint can have specific behavior for groups which aren't specifically cells, but there is a consistent mechanism for specifying a group as a list of cells. For example, when specifying a Thermometer constraint, the thermometer will want a group of cells which, in order, specify the bulb of the thermo and then the rest of the line.

Method Syntax Explanation Examples
RxCy* Specify one cell R2C3
R5C8
R[x1]C[y1]R[x2]C[y2].. Specify multiple cells by listing them one after another. R1C1R1C2R2C3
R1C1R5C5
R[x1-x2|x]C[y1-y2|y] Specify a range of cells, either a line or a rectangle. R1-4C5
R2C3-8
R2-4C3-6
R[x1,x2|x]C[y1,y2|y] Specify a disjoint range of cells. R1,3,5C5
R2-5C4,6,8
R2,4,6C1,3,5,7
D[123456789] Move in a numpad direction. 1 is down and left, 9 is up and right. Reference your keyboard numpad for all directions. R1C1D2229

* For all cell syntax, case doesn't matter, so you can use R1C1 or r1c1. Uppercase is used in all examples for clarity of reading.

Pre-Solve Options

These options apply in-between creating the input board with its constraints and it being passed into the solver.

Short Parameter Long Parameter Sub Parameter Behavior
-p --print n/a Prints the puzzle as imported.

Solve Options

Solve Action

These solve actions are mutually exclusive, meaning only one may be specified:

Short Parameter Long Parameter Behavior
-s --solve Finds a solution to the puzzle. If multithreading is not used, the solution output is consistent, though not necessarily the lexographically smallest solution. Solution may be inconsistent if multithreading is used.
-d --random Finds a random solution to the puzzle.
-l --logical Attempts to solve the puzzle logically, outputting all logical steps taken. Does not support multithreading.
-r --truecandidates Finds the "true candidates." These are the candidates per cell which can lead to a solution. Can also be considered the union of all solutions to the puzzle. Computed via brute force, and supports multithreading.
-k --check Checks if a puzzle has 0, 1, or 2+ solutions. Uses the brute force solver and supports multithreading. Only faster than solution count if there are more than 2 solutions.
-n --solutioncount Gets the exact number of solutions to the puzzle. Uses the brute force solver and supports multithreading.

Solve Options

These options affect the solve, and can be combined with any of the solve modes:

Short Parameter Long Parameter Behavior
-t --multithread Have the brute-force solver use multithreading. This makes the solver use all of your CPU cores to achieve the answer more quickly, but could affect your system performance and laptop battery consumption.

Post-Solve Options

These options affect the behavior after the solve action has completed.

Short Parameter Long Parameter Sub Parameter Behavior
-o --out filename The solution(s) found are output to the specified file. Solutions are output as they are found, so if the solve is canceled early, all solutions found up to that point will be in the file.
-z --sort n/a Only valid with solution count option -n. Sort the solution count output. If there are a very large number of solutions, this could use a large amount of memory.
u --url n/a Output the result of the solve as an f-puzzles URL.
v --visit n/a Must be combined with -u. Opens the generated f-puzzles URL in the system's default browser.