Cyclic Single-Track Gray Codes

Debug: document.doctype.publicId = , typeof Worker = . Options: autoversion

Caution: This demonstration is for the enlightenment of the wise rather than the obedience of the un-enlightened. Things may be easier if you have have read my CREGJ articles on Gray codes and studied the Javascript that is running here. Essentially, this demo was written primarily for my own use.

There are no (essential) server-side scripts, only this HTML file, plus CSS and JS files, so the files can be downloaded and run locally, and you can edit the JavaScript file to suit. (Clearly you will need some knowledge of how to download and edit the files that comprise a web page). WARNING: As this is development code, it might not be fully functional (I might have left it in a non-working state), so you are advised to enable your browser's JS console so that you are warned of all errors.

Note: for N > 7 this program needs to run for many hours, and perform > 1E9 iterations. For $N = 19 the necklace search alone takes 10s, doubling (or worse) for each value of N above that.Show More...
To avoid the "browser has become unresponsive" message, the code runs in a separate thread, in a web worker. Some notes on this are contained within the JavaScript code and possibly also in the results table.

Form

Set the parameters below. Further options are available by editing the JS file.

First, the program searches for and lists all the necklace codes. Next, it tries to assemble the necklace codes into a valid Gray code. Currently, although it reports each result, it only lists the Gray codes for the longest predicted sequence. You can ask the program to halt after it has found a certain number of sequences.

For a necklace code of length N, Gray codes are multiples of 2N not exceeding 2^N (and there are other restrictions). To generate only the necklace codes, set the iterations to zero, as the iteration count applies only to the Gray code search.

  Desired length of necklace codes, N (i.e. number of Gray-code sensors).

For the value of N given above, there are [binaryValues] binary codes. According to my prediction, [badCodes] of those are not valid necklace codes and [validNecklaceCodes] are valid codes, giving rise to [necklaces] necklaces. Gray sequences must use an even number of necklaces, implying a period of [period]. But those necklaces might not all be useable. Check that statement by reading the results below.

  Max. iterations for Gray code search. (Set to zero to calculate only the necklaces).

Ignore the punctuation. It is stripped out and re-inserted when you enter a new number. You can also use scientific notation. Syntax errors are silently corrected.

  Maximum tree depth (i.e. number of necklaces in the Gray sequence) to search for. (Populated automatically with max value when N is altered. Not in use yet.

  Number of maximum-period sequences to search for.

  Submit the values entered above.

  Reset to the default values built in to the HTML page (a FORM reset).

  Set the default values built in to the JavaScript file. These might be different to the HTML defaults applied when this page is first loaded.

This action is achieved by setting location.search='?default', causing the browser to reload the page, with the query string set to ?default. That then causes the code to apply the default settings to the form elements.

  Load a virgin page with no query string – i.e. run location.replace(location.pathname). Having done that, you might want to ...

  Flush the js/css cache – i.e. force a re-load of the page from the server – by running location.reload(true). See note below.

Note on auto-versionning: show
Some browsers aggressively cache JS and CSS files, which can be a nuisance during development when their contents are changing. This page has probably been written to use auto-versionning which will avoid the problem. (Search the source code for auto-versionning or look at the Debug bar (if present) at the top of the page). If autoversioning is not in use you should use the "Reload" button, above, at the start of your session. Alternatively you can do a hard refresh of the browser page.

Program Status

Clicking on ❌ will force a terminate() on any Web Worker process that is running in a separate thread (as well as closing this box). To terminate the worker but leave this message up, do terminate Worker, because post a stop message doesnt work (see JS code for explanation).

Progess updates reported here

Downloads

  Save the results listed below. Debug: Do not remove this anchor tag. Aclick here is simulated by a click on the button.

[ close ]

Javascript Error

myErrorReport goes here

Results


/pub/cregj/more/j118/gray_code_demo.html, last modified Tue, 27 Sep 2022 16:12:23 +0100. Server: britiac4.british-caving.org.uk (31.25.186.126)