Friendship Bracelet Normal Pattern Solver

Introduction to the Bracelet Solver

bracelet_solver is a small command line utility to find a knotting pattern for a friendship bracelet design. It is currently only available for Windows.

Download and Installation

The current version is bracelet_solver 0.01. This first alpha release has not been extensively tested and likely contains a number of bugs. To help improve the program, please report any issues to me at adrian@antiprism.com.

There is no installer. Download the following executables

Then copy them to a directory in your PATH, or the directory where you will be working.

Preparing the Bracelet Design File

The starting point is the bracelet design. This is a repeatable section of a bracelet described by the colours of the knots in each line. You can make an original design by following this bracelet design tutorial, or you could modify an existing pattern from the Friendship-bracelets.net patterns database

The bracelet design must be converted to a simple text format and written to a file. This file can be prepared and edited using a text editor such as Windows notepad.

To convert the design, assign a single character to each colour in the bracelet (letters are case sensitive). Enter each line of knots in the bracelet section in order as line of text, with each knot in the line being represented by its colour character. Spaces can be used to improve the readability.

If you wish to modify a bracelet from the patterns database, you can easily copy the design into a file using the pat2design utility.

Example Bracelet Design Files

A simple example is a 2-colour chevron.

The design has two colours: yellow and red. Assign the character 'y' to yellow, and 'r' to red. The design has four lines of knots, the number of knots in the lines alternate between 4 and 3. The bracelet design file would contain the following text (optional spaces have been added for clarity), and can be download as design2.txt

y r r y
 y r y
r y y r
 r y r
It would work equally well to assign '0' to red and '1' to yellow and leave out the spaces. The file would contain the following text, and give exactly the same results.
1001
101
0110
010

Running the Program

The program is a command line utility, and meant to be run from a DOS box or similar. The DOS box can generally be started from the Windows menu in the Accessories section.

The program accepts a bracelet design file and produces a report with information about the design and a list of the knotting solutions that the program finds. For more help on the program and its options run

bracelet_solver -h

A typical way to run the program is as follows

bracelet_solver design2.txt > report_design2.txt
The program reads the design from the file design2.txt and writes the report into the file report_design2.txt. You can view the report file with a text processor or word processor.

When run this way the program will try to find a single solution (find more by setting the option -k) for each of a wide range of combinations of strings. It finds solutions quickly, but is not thorough.

Another way to run the program is to specify a particular set of strings. This will find the knotting paterns (set option -k to find more than one) that start with the set of strings. For example, the following command finds 8 distinct knotting patterns that start and end with the particular set of stings.

bracelet_solver -s yrryyrry design2.txt -k 0 > report_design2.txt
Note: when using option -s, it may take a long (minutes), or very long, time to find a set of solutions for larger designs with few colours.

The Report and Solutions

The report contains some extra information to show how individual solutions are arrived at. If you are just interested in the solutions themselves then they are easy enough to pick out, and are documented below under Information about knotting variations.

Information about the bracelet design

General information about the design.
Knot pattern to solve
The input bracelet design
Number of colours
Total number of different colours in the design
Number of strings
Number of strings that will be used in the knotting pattern
Required string colour counts
A list of the colours, and how many strings are required to be that colour

Information about strings sets

One or more solutions were found for a set of strings of various colours.
Free string colour counts
The string to the top right of each knot on the first row is assigned the colour of that knot. The other strings are the free strings, and are assigned colours from remaining required colours and a combination of other colours to try.
STRINGS NO.
The order number for the particular set of free strings
Fixed strings
The strings to the top right of the knots on the first row. These will not change for this set of strings.
Permuted strings
The other strings, in their initial order, which will be permuted to find solutions.

Information about permutations

One or more solutions were found for a particular permutation of the set of strings.
PERMUTATION NO.
The order number for the particular permutation of free strings in this string set.
Fixed strings
The strings to the top right of the knots on the first row.
Permutation
The permutation of the other strings, which together with the fixed strings form a specific set of strings to be tested for knotting solutions.

Information about knotting variations (solutions)

A knotting solution that was found for the particular permutation of the strings.
KNOTTING VARIATION
The order number for the particular knotting variation for this permutation of free strings (in this string set.)
Solution no.
The order number for this solution, among all solutions so far found.
Base strings
The actual strings tested. If followed by the word Reordered, then the initial strings in the pattern were reordered to make them match the end strings. This ensures that the bracelet section will repeat.
Text pattern format
The numbered knot lines are sandwiched above and below by strings. The two strings above a knot lead into the knot, and then exit as the two strings below. If the two strings are the same colour use any knot type to tie the knot. Otherwise, if the top left (right) string colour matches the knot colour the first half o the knot is a forward (backward), and if the bottom left (right) string matches the knot colour the second half of the knot is a backward (forward).
Generator pattern format
Use this with the Friendship-bracelets.net Alternative Generator Add more or less rows or strings to match the knot rows and strings in the solution pattern. Set up the string colours to match the input strings. Click the "Show console" box. Select and copy the knot text (don't include the string line) from the solution, then select the text in the console box and paste in the solution, replacing the original knot text. Add a string and then remove a string to refresh the displayed pattern with the new solution knots.

Program Help

The program help can be printed with bracelet_solver -h.


Usage: bracelet_solver [options] bracelet_design_file

Read a text file containing a bracelet design, a formatted text
representation of a repeating section of a bracelet, and find
sets of strings and knotting patterns that will produce this section.
Produce a report of solutions and write it to standard output

bracelet_design_file
A text file holding the knot lines and colours for a repeating section
of a bracelet, in the following simple format. Assign a single character
to each colour in the bracelet (letters are case sensitve). Enter each
line of knots in the bracelet section in order as line of text, with each
knot in the line represented by its colour character. The final text file
will have an even number of lines, and as many lines as there are lines
of knots in the bracelet section. If the first line has N knots, either
all the lines will have N knots, or the lines will alternate between
N and N-1 knots. Not all patterns have solutions!

Options
  -h        print this help text
  -v        print the program version and licence
  -n num    maximum number of solutions to find, 0 for no limit
            (default: 1000)
  -k num    maximum number of knotting variations to find for each
            string permutation, 0 for no limit (default: 1)
  -s strs   find all exact solutions for a specific set of strings (might
            take some time!)

Program Licence

The program licence can be printed with bracelet_solver -v. The terms of the licence mean that the program executable can be freely shared.
bracelet_solver 0.01

Copyright 2013 Adrian Rossiter <adrian@antiprism.com>
               http://www.antiprism.com/other/bracelet_solver.html

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the 'Software'),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

pat2design

pat2design is a very basic utility for converting a published pattern into a bracelet design input file for bracelet_solver. This makes it easier to modify an existing pattern, as it saves having to convert the pattern by hand.

Make an input pattern file, in exactly the same format as the generator pattern text produced in bracelet_solver report. This is a line of characters to represent the string colours, followed by a knotting pattern. The knotting pattern is copy pasted from the Friendship-bracelets.net Alternative Generator console.

Here is an example of how to convert Pattern #2. Start up the Alternative Generator with Pattern #2 (for a different pattern replace the 2 in the URL with the number of the pattern you wish to modify).

Write the top line of strings as a character for each colour, e.g.

yrryyrry
Click on "Show console", and copy the text into the file below the strings line. The final file, which can be downloaded as pat2.txt, contains the following text
yrryyrry
DDdd
DDd
DDdd
DDd
pat2design accepts the input pattern file as an argument and writes the design file to standard output, so run it like this
pat2design pat2.txt > design2.txt
design2.txt contains the following text
y r r y
 y r y
r y y r
 r y r
This can then be modified and used as input for bracelet_solver to find knotting patterns.