- Code: Select all
+----------------+-------------+----------------+
| . -1 . | . -1 . | . -1 . |
| . (1) . | . (1) . | . . . |
| . -1 . | . -1 . | . -1 . |
+----------------+-------------+----------------+
| . -1 . | . -1 . | . -1 . |
| . . . | . (1) . | . (1) . |
| . -1 . | . -1 . | . -1 . |
+----------------+-------------+----------------+
| . (1) . | . -1 . | . (1) . |
| (1) (-1) (1) | -1 -1 -1 | (1) (-1) (1) |
| . (1) . | . -1 . | . (1) . |
+----------------+-------------+----------------+
example codes from my solver on how i accomplish this:
{note i just wrote this code today and am still testing it out so far so good not bad for <2 hours writing. mind you 8 years of failed very slow attempts lol }
first i studied the list of strong links
then i figured out the best way for me to build a table of those type of classed links { data storage code below very well tested}
originally i had a 2ndary table of weak-links which i realized is wasted space
since a weak link only occurs on a shared sector that sees all the digits my strong link setup already included that information!
all you have to do is reference the start and end cells of the inital link
saved sectors all those cells are found in for start/end
then run your program to line up the end cells sector to the next starting sector and off to the races we go.
my solver is in free pascal using setwise mathematical functions.
data type: Show
- Code: Select all
{link type data base}
Linkset : stronglk; // array [ 0..9][0..5][0..9] of numberset[0..80]//setwise
{digit selected[1..9]}
{0: bivavel,
1: 2 cells in a sector
2: cell in sector , grouped link to another = all digits in that sector
3: cells in sector, as a grouped link to a single cell = all digits in that sector
4: cells in sector, as a grouped link to a grouped node = all digits in that sector
5: ERI}
{ internal data as:
0 starting digit,
1 active cell,
2 linked cells,
3 next link digit,
4 sector its in,
5 peers sector the link cells are is in.
6 previous - digit swap is applicable 0 = off
7 digit swap is applicable 0 = off
8 potential elimination cells for basic ...end cell
9 potential elimination for ring codes ...start cell
}
strong link builder: Show
- Code: Select all
Procedure links;{rebuild}
var
N,xn,q,j,a,b,c,d,e,m,n2:integer;
output: text;
used:numberset;
begin
setlength(Linkset,10,6,0);
for n:= 1 to 9 do
begin
q:=-1;
A:=-1;
b:=-1;
c:=-1;
D:=-1;
e:=-1;
used:=[];
for xn:= 0 to 26 do
begin
{bivavle cell}
if DigitRCB[xn,n] <> []
then
begin
for J in (DigitRCB[xn,n]-used) do
if nm[j] = 2
then
begin
include(used,j);
inc(q);
setlength(linkset[n][0],q+1);
include(linkset[n][0][q,0],n);
include(linkset[n][0][q,1],j);
linkset[n][0][q,2]:=[j];
for m in (pm[j]-[n]) do
begin
include(linkset[n][0][q,3],m);
linkset[n][0][q,9]:= peer[j] * digitcell[m];
end;
linkset[n][0][q,4]:=cellsec[j];
linkset[n][0][q,5]:=CellSec[j];
linkset[n][0][q,6]:=[n];
linkset[n][0][q,7]:=[m];
linkset[n][0][q,8]:= peer[j] * digitcell[n] ;
end;
end;{bivavle}
{bi local}
if (sec[xn,n] = 2 )
then
for J in DigitRCB[xn,n] do
begin
inc(a);
setlength(linkset[n][1],a+1);
include(linkset[n][1][a,0],n);
include(linkset[n][1][a,1],j);
linkset[n][1][a,2]:= Digitrcb[xn,n] - [j];
include(linkset[n][1][a,3],n);
//include(linkset[n,1,a,4],xn);
linkset[n][1][a,4]:=cellsec[j] - [xn];
for m in digitRCB[xn,n] -[j] do
linkset[n][1][a,5]:=cellsec[m]-[xn];
linkset[n][1][a,6]:=pm[j]-[n];
linkset[n][1][a,7]:=pm[m]-[n];
linkset[n][1][a,8]:=peer[j]*digitcell[n] -[m];
linkset[n][1][a,9]:=peer[m]*digitcell[n] -[j];
end; {bilocal}
{ single + grouped & Grouped + single}
if (sec[xn,n] <5) and (Sec[xn,n] >2)
then
for J in DigitRCB[xn,n] do
for m in peerRCB[xn] do
if ((DigitRCB[m,n] * DigitRCB[xn,n]) + [j] = DigitRCB[xn,n] )
and not ( J in DigitRCB[m,n])
then
begin
{ single + grouped}
inc(b);
setlength(linkset[n][2],b+1);
include(linkset[n][2,b,0],n);
include(linkset[n][2,b,1],j);
linkset[n][2,b,2]:= Digitrcb[xn,n] - [j];
include(linkset[n][2,b,3],n);
linkset[n][2,b,4]:=cellsec[j] - [xn];
include(linkset[n][2,b,5],m);
linkset[n][2,b,6]:=pm[j]-[n];
linkset[n][2,b,7]:=[0];
linkset[n][2,b,9]:= Digitrcb[m,n]- (DigitRCB[m,n] * DigitRCB[xn,n]) ;
linkset[n][2,b,8]:= peer[j]* digitcell[n]-(DigitRCB[m,n] * DigitRCB[xn,n]);
{ grouped + single}
inc(c);
setlength(linkset[n][3],c+1);
include(linkset[n][3,c,0],n);
linkset[n][3,c,1]:= Digitrcb[xn,n] - [j];
include(linkset[n][3,c,2],j);
include(linkset[n][3,c,3],n);
include(linkset[n][3,c,4],m);
linkset[n][3,c,5]:= cellsec[j] - [xn] ;
linkset[n][3,c,6]:=[0];
linkset[n][3,c,7]:=pm[j]-[n];
linkset[n][3,c,9]:= peer[j] * digitcell[n]-(DigitRCB[m,n] * DigitRCB[xn,n]);
linkset[n][3,c,8]:= DigitRCB[m,n] -(DigitRCB[m,n] * DigitRCB[xn,n]) ;
end;
{Grouped + grouped}
if (sec[xn,n] <7) and (Sec[xn,n] >4)
then
for J in peerrcb[xn] do
for m in (peerrcb[xn]-[0..j]) do
if ((DigitRCB[j,n] * DigitRCB[xn,n]) + (DigitRCB[m,n] * DigitRCB[xn,n]) = (DigitRCB[xn,n]))
and (DigitRCB[j,n] * DigitRCB[m,n] = [] )
then
begin
inc(d);
setlength(linkset[n][4],d+1);
include(linkset[n][4,d,0],n);
linkset[n][4,d,1]:=(DigitRCB[xn,n] * Digitrcb[j,n]);
linkset[n][4,d,2]:=(DigitRCB[xn,n] * DigitRCB[m,n]);
include(linkset[n][4,d,3],n);
include(linkset[n][4,d,4],J);
include(linkset[n][4,d,5],m);
linkset[n][4,d,6]:=[0];
linkset[n][4,d,7]:=[0];
linkset[n][4,d,9]:= DigitRCB[m,n] - (DigitRCB[xn,n] * DigitRCB[m,n]);
linkset[n][4,d,8]:= DigitRCB[j,n] - (DigitRCB[xn,n] * DigitRCB[j,n]);
inc(d);
setlength(linkset[n][4],d+1);
include(linkset[n][4,d,0],n);
linkset[n][4,d,2]:=(DigitRCB[xn,n] * Digitrcb[j,n]);
linkset[n][4,d,1]:=(DigitRCB[xn,n] * DigitRCB[m,n]);
include(linkset[n][4,d,3],n);
include(linkset[n][4,d,4],m);
include(linkset[n][4,d,5],j);
linkset[n][4,d,6]:=[0];
linkset[n][4,d,7]:=[0];
linkset[n][4,d,9]:= DigitRCB[j,n] - (DigitRCB[xn,n] * DigitRCB[j,n]);
linkset[n][4,d,8]:= DigitRCB[m,n] - (DigitRCB[xn,n] * DigitRCB[m,n]);
end;
if (sec[xn,n] <6) and (Sec[xn,n] >1) and (xn in [18..26])
then
for J in eri[xn-18,n] do
begin
inc(e);
setlength(linkset[n][5],e+1);
include(linkset[n][5,e,0],n);
linkset[n][5,e,1]:=(DigitRCB[xn,n] * Digitrcb[Rx[secset[xn,j]],n]);
linkset[n][5,e,2]:=(DigitRCB[xn,n] * DigitRCB[Cy[secset[xn,j]]+9,n]);
include(linkset[n][5,e,3],n);
include(linkset[n][5,e,4], rx[secset[xn,j]]);
include(linkset[n][5,e,5], Cy[secset[xn,j]]+9);
linkset[n][5,e,6]:=[0];
linkset[n][5,e,7]:=[0];
linkset[n][5,e,8]:= DigitRCB[Rx[secset[xn,j]],n] - (Digitrcb[xn,n] * Digitrcb[Rx[secset[xn,j]],n]);
linkset[n][5,e,9]:= DigitRCB[Cy[secset[xn,j]]+9,n] - (Digitrcb[xn,n] * Digitrcb[Cy[secset[xn,j]]+9,n]);
inc(e);
setlength(linkset[n][5],e+1);
include(linkset[n][5,e,0],n);
linkset[n][5,e,2]:=(DigitRCB[xn,n] * Digitrcb[Rx[secset[xn,j]],n]);
linkset[n][5,e,1]:=(DigitRCB[xn,n] * DigitRCB[Cy[secset[xn,j]]+9,n]);
include(linkset[n][5,e,3],n);
include(linkset[n][5,e,5], rx[secset[xn,j]]);
include(linkset[n][5,e,4], Cy[secset[xn,j]]+9);
linkset[n][5,e,6]:=[0];
linkset[n][5,e,7]:=[0];
linkset[n][5,e,9]:= DigitRCB[Rx[secset[xn,j]],n] - (Digitrcb[xn,n] * Digitrcb[Rx[secset[xn,j]],n]);
linkset[n][5,e,8]:= DigitRCB[Cy[secset[xn,j]]+9,n] - (Digitrcb[xn,n] * Digitrcb[Cy[secset[xn,j]]+9,n]);
end;
end;
end;
{
assign(output,'C:\sudoku\combotest.txt');
erase(output);
rewrite(output);
close(output);
for n2 in [1..9] do
for xn in [0..5] do
for J:= low(linkset[n2][xn]) to high(linkset[n2][xn]) do
begin
append(output);
writeln(output);
write(output,'#',n2,' | ');
write(output,'type:',xn,' | ');
for n:= low(linkset[n2][xn,j]) to high(linkset[n2][xn,j]) do
begin
for M in linkset[n2][xn,j,n] do
write(output,m,',');
write(output,' | ');
end;
close(output);
end}
end;{strong link builder}
x-chain {depth first}: Show
- Code: Select all
{x-chain }
procedure xchain(K:integer);
type
xsets = array of array of array of numberset;
steps = array of array of numberset;
used = array of numberset;
hold = array of integer;
var
h:hold;
xset: xsets;
step:steps;
use: used;
n,a,b,c,d,e,max:integer;
begin
setlength(xset,10,0,0);
for n in[1..9] do
begin
b:=-1;
for a in [1..5] do
for c:= low(linkset[n][a]) to high(linkset[n][a]) do
begin
b:=b+1;
setlength(xset[n],b+1,10);
{ note the next section & similar subsections can be compressed into xset[n][b]:=linkset[n,a,c] instead of the 10 parts they are listed to show what im coping for this example}
xset[n][b,0]:=linkset[n,a,c,0];
xset[n][b,1]:=linkset[n,a,c,1];
xset[n][b,2]:=linkset[n,a,c,2];
xset[n][b,3]:=linkset[n,a,c,3];
xset[n][b,4]:=linkset[n,a,c,4];
xset[n][b,5]:=linkset[n,a,c,5];
xset[n][b,6]:=linkset[n,a,c,6];
xset[n][b,7]:=linkset[n,a,c,7];
xset[n][b,8]:=linkset[n,a,c,8];
xset[n][b,9]:=linkset[n,a,c,9];
end;
end;
for n in[1..9] do
for a:= high(xset[n]) downto 0 do
begin
b:=0;
max:= high(xset[n]);
setlength(use,b+1);
use[b]:= xset[n][a][1] + xset[n][a][2] ;
setlength(h,b+1);
h[b]:=max;
setlength(step,b+1,10);
step[b,0]:=xset[n,a,0];
step[b,1]:=xset[n,a,1];
step[b,2]:=xset[n,a,2];
step[b,3]:=xset[n,a,3];
step[b,4]:=xset[n,a,4];
step[b,5]:=xset[n,a,5];
step[b,6]:=xset[n,a,6];
step[b,7]:=xset[n,a,7];
step[b,8]:=xset[n,a,8];
step[b,9]:=xset[n,a,9];
repeat
for c:= h[b] downto 0 do
if (xset[n][C][1] * use[b] = [])
and (xset[n][C][2] * use[b] = [])
and (step[b][5] * xset[n][c][4] <> [])
then
begin
h[b]:=h[b] - 1;
b:=b+1;
setlength(use,b+1);
use[b]:=use[b-1]+ xset[n][c][1] +xset[n][c][2] ;
setlength(h,b+1);
h[b]:=max;
setlength(step,b+1,10);
step[b,0]:=xset[n,c,0];
step[b,1]:=xset[n,c,1];
step[b,2]:=xset[n,c,2];
step[b,3]:=xset[n,c,3];
step[b,4]:=xset[n,c,4];
step[b,5]:=xset[n,c,5];
step[b,6]:=xset[n,c,6];
step[b,7]:=xset[n,c,7];
step[b,8]:=xset[n,c,8];
step[b,9]:=xset[n,c,9];
if (b > 0) and (xset[n][c][5] * xset[n][a][4] <> []) {ring}
then
begin
active:=true;
{start and finsih peers are eliminated for each set in the chain}
for e:= 0 to (b-1) do
for d:= e+1 to (b) do
begin
active:=true;
covered2[n]:=covered2[n] + ((step[d][8]*step[e][8]) -use[b]); { start a to start b peers}
covered2[n]:=covered2[n] + ((step[d][9]*step[e][9]) -use[b]); {end a to end b peers}
covered2[n]:=covered2[n] + ((step[d][8]*step[e][9]) -use[b]); {end a to start b}
covered2[n]:=covered2[n] + ((step[d][9]*step[e][8]) -use[b]); {start a to end b}
end;
end;
if (b > 0) and (xset[n][c][5] * xset[n][a][4] = []) and (((xset[n][a][8]*xset[n][c][9]) -use[b]) <> []){normal}
then
begin
active:=true;
covered2[n]:=covered2[n] + ((xset[n][a][8]*xset[n][c][9]) -use[b]);
end;
break;
end
else
h[b]:= h[b] - 1;
if (h[b] < 0) and (b > 0) or (b >= max)
then
begin
b:=b-1;
setlength(use,b+1);
setlength(h,b+1);
setlength(step,b+1,10);
h[b]:=h[b]-1;
end;
until (h[b] = -1) or (b = 0)
end;
end; {x-chain}
to help that data looks like this for me for the above pattern
double bridged er: Show
- Code: Select all
#1 | type:1 | 1, | 10, | 13, | 1, | 10,18, | 13,19, | 2,3,4,5,6,7,8,9, | 2,3,4,5,6,7,8,9, | 0,1,2,18,19,20,28,46,55,64,73, | 3,4,5,21,22,23,31,40,49,58,67,76, |
#1 | type:1 | 1, | 13, | 10, | 1, | 13,19, | 10,18, | 2,3,4,5,6,7,8,9, | 2,3,4,5,6,7,8,9, | 3,4,5,21,22,23,31,40,49,58,67,76, | 0,1,2,18,19,20,28,46,55,64,73, |
#1 | type:1 | 1, | 40, | 43, | 1, | 13,22, | 16,23, | 2,3,4,5,6,7,8,9, | 2,3,4,5,6,7,8,9, | 4,13,22,30,31,32,48,49,50,58,67,76, | 7,25,33,34,35,51,52,53,61,70,79, |
#1 | type:1 | 1, | 43, | 40, | 1, | 16,23, | 13,22, | 2,3,4,5,6,7,8,9, | 2,3,4,5,6,7,8,9, | 7,25,33,34,35,51,52,53,61,70,79, | 4,13,22,30,31,32,48,49,50,58,67,76, |
#1 | type:4 | 1, | 6,7,8, | 24,25,26, | 1, | 0, | 2, | 0, | 0, | 0,1,2,3,4,5, | 18,19,20,21,22,23, |
#1 | type:4 | 1, | 24,25,26, | 6,7,8, | 1, | 2, | 0, | 0, | 0, | 18,19,20,21,22,23, | 0,1,2,3,4,5, |
#1 | type:4 | 1, | 27,28,29, | 45,46,47, | 1, | 3, | 5, | 0, | 0, | 30,31,32,33,34,35, | 48,49,50,51,52,53, |
#1 | type:4 | 1, | 45,46,47, | 27,28,29, | 1, | 5, | 3, | 0, | 0, | 48,49,50,51,52,53, | 30,31,32,33,34,35, |
#1 | type:5 | 1, | 63,64,65, | 55,64,73, | 1, | 7, | 10, | 0, | 0, | 66,67,68,69,70,71, | 1,10,19,28,46, |
#1 | type:5 | 1, | 55,64,73, | 63,64,65, | 1, | 10, | 7, | 0, | 0, | 1,10,19,28,46, | 66,67,68,69,70,71, |
#1 | type:5 | 1, | 69,70,71, | 61,70,79, | 1, | 7, | 16, | 0, | 0, | 63,64,65,66,67,68, | 7,25,34,43,52, |
#1 | type:5 | 1, | 61,70,79, | 69,70,71, | 1, | 16, | 7, | 0, | 0, | 7,25,34,43,52, | 63,64,65,66,67,68, |
pss you could build the tables to be a parent/child list and walk the links as well as some people perfer but its a breadth first approach.
{i still dont know how to do that as im self taught}