Follow on X
Welcome to the home of Str8ts
English French Sequ�ncia em Portugu�s Dutch Deutsch Spanish

Str8ts String Definitions

As of 6th July 2024 I'm employing a new Str8ts string definition to transport information about the board and candidates. This is currently employed on the [Email this Board] feature - best place to copy/paste the new link

The old method was to pass the clues as an 81 character string + the black/white cells as an 81 character string, for example:
https://www.str8ts.com/str8ts.aspx?bd=000000009000000060930000000000004000003000000000720000090000200000000010100000020000000011000000000000000000011001100001100011000000000000001000001000000100000000

The new string also transports whether a big number is a clue or solution AND all the candidates of empty cells. And is just one third longer (243 characters instead of 162).

An example is
https://www.str8ts.com/str8ts.aspx?bd=0vo03c0vc0js0vk0us0vg0021030ro03c1rc1js1rk1qs1rg0410q010100h0vc0jc0v40uc0v00q00u00uo0020021i81sk0130020q00s00p00q000j0021v41u80740020020ng0m01n00810091mk07k01g0jk0u01010u00m00u000200901g01k0v00u000206007g06807g00503o0070u01v01m01vg0eg07g00803g


Users of the solver may want to know more about this string so that they can duplicate it for their own uses and understand how it works. So I'm presenting the information here.

The candidates are the largest payload. We need to store all of 1 to 9 and any combination. This can be done in nine bits if we let each bit represent a number in this way: 1=1, 2=2, 3=4, 4=8, 5=16, 6=32, 7=64, 8=128 and 9=256. A solved cell has one 'candidate' number.

Both the clues/solution distinction and the black/white cells need only one bit between them, so 11 in all. I've chosen to store the candidates bits first, then the cell colour, then the clue flag. All nine candidates add up to 511. Since candidates must exist on an empty white cell the two flag bits will be 0 and 0. This gives us a maximum number of 51100 or 1vs in base 32. A 9 on a black cell will be 25611. So unlike the Sudoku and Killer transport strings, these are 3 bytes per cell and not two.

A bit of javascript code shows how this is done
for (y = 0; y < 9; y++)
for (x = 0; x < 9; x++) {
n = get the cell value or set of candidates as bits
n = (n << 2); // shift to make space for 2 more bits
n += ((isclue) ? 2 : 0) + ((isblack) ? 1 : 0);
h = n.toString(32); // convert to base 32
if (h.length < 2) h = '0' + h; // pad the number if not two digits
if (h.length < 3) h = '0' + h; // pad the number if not three digits
s += h; // append to string being made
}

To unpack a string we do the following
// This splits a string into an array of elements each 3 characters long 
var narr = theString.match(/.{1,3}/g);
if (narr.length != 81) return false; // Sanity length check
for (y = 0; y < 9; y++)
for (x = 0; x < 9; x++) {
n = parseInt(narr[y * 9 + x], 32); // convert base 32 to decimal
clue(y, x) = (n & 2) ? 1 : 0; // extract the clue flag
colour(y, x) = (n & 1) ? 1 : 0; // extract the black/white flag
n = n >> 2; Shift the bits to remove the flags
if (bit_count(n) == 1) {
// save the number as a clue or solution
} else {
// save the number as a set of candidates
}
}
Any problems or questions, let me know in the comments below



Comments

CommentsTalk



Article created on 6-July-2024. Views: 342
This page was last modified on 7-July-2024.
All text is copyright and for personal use only but may be reproduced with the permission of the author.
Copyright Jeff Widderich and Andrew Stuart @ Syndicated Puzzles, Privacy, 2007-2024