by StrmCkr » Sat Jan 28, 2017 7:27 am
[url=http://forum.enjoysudoku.com/almost-locked-rules-for-now-t2510.html]Almost locked set rules[/url]
[hidden=ALS-XZ][code]procedure alsxz(k:integer); {so far this is 100,000% faster}
type
almostlockedset2= array of array of integer;
var
q,xn,xn2,yn,yn2,yn3,yn4,n,z,x,r,u,alsa,alsB,a,b:integer;
A3:numberset;
A4:numberset;
z1:nums;
lx1: rcbpeer;
lx2: rcbpeer;
als2:almostlockedset2;
begin
alsfinder;
//ahsfinder;
b:=0;
setlength(als2,b,5);
for a:= high(als) downto 0 do {startin array}
if (als[a,1]+1 = als[a,2])
then
begin
b:=b+1;
setlength(als2,b+1,5);
als2[b,0]:=als[a,0];
als2[b,1]:=als[a,1];
als2[b,2]:=als[a,2];
als2[b,3]:=als[a,3];
als2[b,4]:=als[a,4];
end;
if k=0 then begin u:=0; setlength(techwrite,u+1,18); end;
for alsA:= low(als2) to (high(als2)-1) do {als A}
if (als2[alsA,1]+1 = als2[alsA,2]) {cell = digit +1}
then
for ALSB:= alsa+1 to high(als2) do {Als B}
if (als2[alsb,1]+1 = als2[alsb,2] ) {cell = digit +1}
and (popcnt(dword((comboset2[als2[alsa,4]]*Comboset2[als2[alsb,4]]) ) ) >1 ) {set a & B must share 2 digits}
and (combosets[als2[alsa,0],als2[alsa,3]] - combosets[als2[alsb,0],als2[alsb,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
and (combosets[als2[alsb,0],als2[alsb,3]] - combosets[als2[alsa,0],als2[alsa,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
then
begin
xn:=als2[alsa,0];
xn2:=als2[alsb,0];
yn:=als2[alsA,3];
yn3:=als2[alsB,3];
yn2:=als2[alsa,4];
yn4:= als2[alsb,4];
z1:=[];
{restricted common chcek}
for z in (comboset[yn4] * comboset[yn2]) do
if ((Digitcell[z] * combosets[xn,yn]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn2,yn3]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn,yn] * combosets[xn2,yn3]) = []) {resticted commons cannot be found in an overlap cell}
then
begin
lx2:=[0..26];
for q in (combosets[xn,yn]+combosets[xn2,yn3]) *digitcell[z] do {combine common cells in both a&b for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z1:=z1 + [z]; {saves the resticted commons}
end;
if popcnt(dword(z1)) =1 {single restricted common eliminations}
then
begin
for R in ((comboset[yn4] * comboset[yn2] ) -z1) do {search for common digit to both, and active in both}
if ((Digitcell[R]* combosets[xn,yn] )<> [] )
and(( Digitcell[R] * combosets[xn2,yn3])<> [])
then
begin
active:=true;
a3:=(([0..80] * digitcell[R])); {valid eliminations must contain R and cannot be in the sets a&b}
for q in ((combosets[xn,yn] + combosets[xn2,yn3]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&B}
a3:=peer[q] * a3 - (combosets[xn,yn] + combosets[xn2,yn3]);
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+7]:= techwrite[u,r+7] + a3;
techwrite[u,7]:=techwrite[u,7]+[R];
end;
end;
if (k= 0)
and (techwrite[u,7] <> [])
then
begin
techwrite[u,0]:=[3];
techwrite[u,1]:=[4];
techwrite[u,2]:=techwrite[u,2]+comboset[yn2];
techwrite[u,3]:=techwrite[u,3]+Combosets[xn,yn];
techwrite[u,4]:=techwrite[u,4]+comboset[yn4];
techwrite[u,5]:=techwrite[u,5]+combosets[xn2,yn3];
techwrite[u,6]:=techwrite[u,6]+ z1;
end;
if u = 32767 {max array size error code safty exit}
then
begin
if k = 0 then
techdisplay(#97,u);
setlength(techwrite,0,0);
u:=0; setlength(techwrite,u+1,17)
//exit;
end;
if (k=0) and (techwrite[u,0] <> []) then begin u:=U+1; setlength(techwrite,u+1,18); end;
end; {normal eliminations}
if popcnt(dword(z1)) >1 {doubly linked rules }
then
begin
active:=true;
active:=true;
{set A&b is now a locked set removal peers cells visable to all copies of each digit in both sets}
for R in comboset[yn2] + comboset[yn4] do
for q in ([0..80] * digitcell[R]) do
begin {R/Q elimiantion search}
if (R in (comboset[yn2] * Comboset[yn4]) ){search for common digit to both, and active in both}
and ((digitcell[R] * combosets[xn,yn]) <> [] )
and ( (Digitcell[R] * combosets[xn2,yn3]) <> [])
and (Peer[q] * ((Combosets[xn,yn]+Combosets[xn2,yn3])*digitcell[R]) = ((Combosets[xn,yn] + Combosets[xn2,yn3])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * (Combosets[xn,yn] + combosets[xn2,yn3]) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+7]:= techwrite[u,r+7] + [q];
techwrite[u,7]:=techwrite[u,7]+[R];
end;
end;
{cells in set b for digits exclusivly to b their peers cannot contain r}
if (R in (Comboset[yn2] - z1))
and (peer[q] * Digitcell[R] * Combosets[xn,yn] = combosets[xn,yn] * Digitcell[R])
and ([q] * combosets[xn,yn] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+7]:= techwrite[u,r+7] + [q];
techwrite[u,7]:=techwrite[u,7]+[R];
end;
end;
{cells in set A for digits exclusivly to A their peers cannot contain r}
if (R in (Comboset[yn4] - z1))
and (peer[q] * Digitcell[R] * Combosets[xn2,yn3] = combosets[xn2,yn3]* Digitcell[R])
and ([q] * combosets[xn2,yn3] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+7]:= techwrite[u,r+7] + [q];
techwrite[u,7]:=techwrite[u,7]+[R];
end;
end;
end; {R/Q elimiantion search}
if (k= 0)
and (techwrite[u,7] <> [])
then
begin
techwrite[u,0]:=[3];
techwrite[u,1]:=[4];
techwrite[u,2]:=techwrite[u,2]+comboset[yn2];
techwrite[u,3]:=techwrite[u,3]+Combosets[xn,yn];
techwrite[u,4]:=techwrite[u,4]+comboset[yn4];
techwrite[u,5]:=techwrite[u,5]+combosets[xn2,yn3];
techwrite[u,6]:=techwrite[u,6]+ z1;
end;
if u = 32767 {max array size error code safty exit}
then
begin
if k = 0 then
techdisplay(#97,u);
setlength(techwrite,0,0);
u:=0; setlength(techwrite,u+1,18)
//exit;
end;
if (k=0) and (techwrite[u,0] <> []) then begin u:=U+1; setlength(techwrite,u+1,18); end;
end; {doubly linked}
end; {yn4}
if k = 0 then
chaindisplay(#97,u);
end;{als -xz rule}[/code][/hidden]
[hidden=AHS-xz][code]{almost hidden set xz } // needs a massive overhall for the eliminations process should be cell based not cell+digit
procedure ahsxz(k:integer); {so far this is 100,000% faster}
var
q,xn,xn2,n,z,x,r,u,alsa,alsB,act3,u2:integer;
a2,a3,b2,b3,z1,x1,lxl,yn,yn2,yn3,yn4:numberset;
begin
//alsfinder;
ahsfinder;
if k=0 then begin u:=0; setlength(techwrite,u+1,16); end;
for alsA:= low(ahs) to (high(ahs)-1) do {als A}
if (ahs[alsA,1]+1 = ahs[alsA,2]) {digit = cell +1}
and (ahs[alsa,1] <4)
// and (sectorrcb[ahs[alsa,0],ahs[alsa,4]] = [24,69,78])
then
for ALSB:= alsa+1 to high(ahs) do {Als B}
if (ahs[alsb,1]+1 = ahs[alsb,2] ) {cell = digit +1}
and (ahs[alsb,1] <4)
// and (sectorrcb[ahs[alsb,0],ahs[alsb,4]] = [62,69,71])
then
begin
xn:=ahs[alsa,0]; {sector a}
xn2:=ahs[alsb,0];
yn:=comboset[ahs[alsA,3]]; {digits a }
yn3:=comboset[ahs[alsB,3]]; {digits b}
yn2:=sectorrcb[xn,ahs[alsa,4]]; {cells a }
yn4:=sectorrcb[xn2,ahs[alsb,4]]; {cells b}
a2:=yn*yn3;// identifies shared Digits
z1:=yn2*yn4; // overlapping cells
b2:=[]; //checks for RCC
b3:=[]; // stores RCC if the
lxl:=[]; // shared cells with shared digits
a3:=[]; // digits of a shared cell with no shared digits
if (z1 <> []) and (a2 <> [] )
then
for n in a2 do
lxl:=lxl + (Digitcell[n]* z1);
if (lxl=[]) and (z1 <> [])
then
for n in z1 do
a3:=a3 + (pm[n] *(yn+yn3));
//identifies shared digits in 1 sector that have 1 option
for q in a2 do
begin
x1:=[0..26];
for N in (DigitCell[q] * (yn2+yn4)) do
if (pm[n] -(yn+yn3) * [q]) = [q]
then
begin
b2:= b2 + [n];
x1:=cellsec[n] * x1;
end;
{z1:= z1 - b2;}
for n in x1 do
if (sectorRCB[n,q] * (yn2 * b2) <> [])
and (sectorrcb[n,q] * (yn4 * b2) <> [])
then
b3:=(yn2 * b2)+(yn4 * b2);
end;
gotoxy(2,60);
for n in b3 do
write(n,' ');
gotoxy(2,61);
for n in z1 do
write(n,' ');
gotoxy(2,62);
for n in lxl do
write(n,' ');
gotoxy(2,63);
for n in a3 do
write(n,' ');
{basic elimination}
if (B3 + (z1-lxl) <> [])
then
begin
active:=true;
for n in yn - (a2+a3) do
begin
covered2[n]:=covered2[n] + digitcell[n]* (yn4-(b3+(z1-lxl)));
if k = 0
then
techwrite[u,n]:=techwrite[u,n]+ digitcell[n]*(yn4-(b3+(z1-lxl)));
end;
for n in yn3 - (a2+a3) do
begin
covered2[n]:=covered2[n] + digitcell[n]*(yn2-(b3+(z1-lxl)));
if k = 0
then
techwrite[u,n]:=techwrite[u,n]+ digitcell[n]*(yn2-(b3+(z1-lxl)));
end;
end;
if (k= 0)
and ((techwrite[u,1]+ techwrite[u,2] + techwrite[u,3] + techwrite[u,3]+techwrite[u,4]+techwrite[u,5]+techwrite[u,6]+techwrite[u,7]+techwrite[u,8]+techwrite[u,9]) <> [])
then
begin
techwrite[u,0]:=yn;
techwrite[u,10]:=yn3;
techwrite[u,11]:=yn2;
techwrite[u,12]:=yn4;
//techwrite[u,13]:=[q];
//techwrite[u,14]:=[R];
//For u2 in pm[r] - (comboset[yn3] + Comboset[yn] ) do
//techwrite[u,u2]:= techwrite[u,u2] + [R];
inc(u);
setlength(techwrite,u+1,16);
end;
end;
if k=0 then techdisplay(#104,u);
end;{ahs-xz rule } [/code][/hidden]
[hidden=ALS-XY][code]{all most locked sets XY Rule : including double and trippled linked rules}
procedure alsxy(k:integer); {so far this is 100,000% faster}
type
almostlockedset2= array of array of integer;
var
q,xn,xn2,xn3,yn,yn2,yn3,yn4,YN5,YN6,n,z,x,act3,r,u,alsA,alsB,alsC,a,b:integer;
A3:numberset;
z1:nums;
Z2:nums;
z3:nums;
lx1: rcbpeer;
lx2: rcbpeer;
lx3: rcbpeer;
als2: almostlockedset2;
begin
alsfinder;
//ahsfinder;
b:=-1;
setlength(als2,b+1,5);
{reduces the als array to the +1 size}
for a:= high(als) downto 0 do {startin array}
if (als[a,1]+1 = als[a,2])
then
begin
b:=b+1;
setlength(als2,b+1,5);
als2[b,0]:=als[a,0];
als2[b,1]:=als[a,1];
als2[b,2]:=als[a,2];
als2[b,3]:=als[a,3];
als2[b,4]:=als[a,4];
end;
if k=0 then begin u:=0; setlength(techwrite,u+1,20); end;
for alsA:= low(als2) to (high(als2)-2) do {als C}
if (als2[alsA,1]+1 = als2[alsA,2]) {cell = digit +1}
then
for ALSB:= alsa+1 to high(als2)-1 do {Als A}
if (als2[alsb,1]+1 = als2[alsb,2] ) {cell = digit +1}
and (popcnt(dword((comboset2[als2[alsa,4]]*Comboset2[als2[alsb,4]]) ) ) >=1 ) {set a & B must share 2 digits}
and (combosets[als2[alsa,0],als2[alsa,3]] - combosets[als2[alsb,0],als2[alsb,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
and (combosets[als2[alsb,0],als2[alsb,3]] - combosets[als2[alsa,0],als2[alsa,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
then
begin
xn:=als2[alsa,0];
xn2:=als2[alsb,0];
yn:=als2[alsA,3];
yn3:=als2[alsB,3];
yn2:=als2[alsa,4];
yn4:= als2[alsb,4];
z1:=[];
{restricted common chcek A & C}
for z in (comboset[yn4] * comboset[yn2]) do
if ((Digitcell[z] * combosets[xn,yn]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn2,yn3]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn,yn] * combosets[xn2,yn3]) = []) {resticted commons cannot be found in an overlap cell}
then
begin
lx2:=[0..26]; { a RC should only exist in the common intersections of the selected sets}
for q in (combosets[xn,yn]+combosets[xn2,yn3]) *digitcell[z] do {combine common cells in both a&b for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z1:=z1 + [z]; {saves the resticted commons}
end;
if popcnt(dword(z1)) >=1 {* single restricted common advance to adding 3rd sector}
then
for alsC:= low(als2) to (high(als2)) do {als b}
if (als2[alsC,1]+1 = als2[alsC,2]) {cell = digit +1}
and (popcnt(dword(( comboset2[yn2]*Comboset2[als2[alsC,4]] ) ) ) >=1 ) {checks that set B and set C share at least 1 digits}
and (combosets[xn,yn] - combosets[als2[alsC,0],ALS2[ALSC,3]] <> [] ) { sectors B & C can over lap, however cells cannot overlap in full}
and ( combosets[als2[alsC,0],ALS2[ALSC,3]] - combosets[xn,yn] <> [] )
then
begin
z2:=[];
z3:=[];
xn3:=als2[alsc,0];
yn5:=als2[alsc,3];
yn6:= als2[alsc,4];
{restricted common chcek B & C}
for z in (comboset[yn6] * comboset[yn2] ) do
if ((Digitcell[z] * combosets[xn3,yn5]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn,yn] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn,yn]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn,yn] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn3,yn5] * combosets[xn,yn]) = []) {resticted commons cannot be found in an overlap cell}
//and (digitcell[z] * Combosets[xn2,yn3] - (combosets[xn3,yn5]+combosets[xn,yn]) = []){resticted commons cannot be found in an overlap cell shared by the 2nd set}
then
begin
lx2:=[0..26]; { a RC should only exist in the common intersections of the selected sets}
for q in (combosets[xn3,yn5]+combosets[xn,yn]) *digitcell[z] do {combine common cells in both C&B for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z2:=z2 + [z]; {saves the resticted commons}
end;
{restricted common chcek B & A}
for z in (comboset[yn6] * comboset[yn4] ) do
if ((Digitcell[z] * combosets[xn3,yn5]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn2,yn3] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn2,yn3]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn2,yn3] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn3,yn5] * combosets[xn2,yn3]) = []) {resticted commons cannot be found in an overlap cell}
//and (digitcell[z] * Combosets[xn2,yn3] - (combosets[xn3,yn5]+combosets[xn,yn]) = []){resticted commons cannot be found in an overlap cell shared by the 2nd set}
then
begin
lx2:=[0..26]; { a RC should only exist in the common intersections of the selected sets}
for q in (combosets[xn3,yn5]+combosets[xn2,yn3]) *digitcell[z] do {combine common cells in both C&B for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z3:=z3 + [z]; {saves the resticted commons}
end;
if (( popcnt(dword(z2)) >1 ) and ( popcnt(dword(z1)) >1 )){if the resticted common on a set is more then 1 its an double linked als-xz rule}
or (( popcnt(dword(z2)) =1 ) and ( popcnt(dword(z1)) =1 ) and (z1 - z2 <> [] ) and (Z2 - z1 <> [])) {checks that both sectors have at least 1 RC and those numbers are diffrent }
or (( popcnt(dword(z2)) =1 ) and ( popcnt(dword(z1)) >1 ))
or (( popcnt(dword(z2)) >1 ) and ( popcnt(dword(z1)) =1 ))
// and ((comboset[yn4] * Comboset[yn6] - (z2+z1) ) <> [])
then
begin {Eliminations A & B peer of z}
if (popcnt(dword( (comboset2[yn4]*Comboset2[yn6]) ) ) >=1 )
then
for R in ((comboset[yn6] * comboset[yn4] )-(z2+z1{+z3}) ) do {search for common digit to both A & B, thats not the RC of z1,z2,z3}
if ((Digitcell[R]* combosets[xn2,yn3] )<> [] )
and(( Digitcell[R] * combosets[xn3,yn5])<> [])
// and (Digitcell[R] * combosets[xn2,yn3] = [])
then
begin
active:=true;
a3:=(([0..80] * digitcell[R])); {valid eliminations must contain R and cannot be in the sets a&b}
for q in ((combosets[xn3,yn5] + combosets[xn2,yn3] {+ combosets[xn,yn]}) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b}
a3:=peer[q] * a3 - ({combosets[xn,yn] +} combosets[xn2,yn3] + combosets[xn3,yn5]);
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{if AC share more then 1 digit perform basic als-xz eliminations}
if (popcnt(dword( (comboset2[yn4]*Comboset2[yn2]) ) ) >1 )
then
for R in ((comboset[yn2] * comboset[yn4] )-(z1) ) do {search for common digit to both A & C, thats not the RC of z1,}
if ((Digitcell[R]* combosets[xn2,yn3] )<> [] )
and(( Digitcell[R] * combosets[xn,yn])<> [])
// and (Digitcell[R] * combosets[xn2,yn3] = [])
then
begin
active:=true;
a3:=(([0..80] * digitcell[R])); {valid eliminations must contain R and cannot be in the sets a&C}
for q in (({combosets[xn3,yn5] +} combosets[xn2,yn3] + combosets[xn,yn]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b}
a3:=peer[q] * a3 - (combosets[xn,yn] + combosets[xn2,yn3] {+ combosets[xn3,yn5]});
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{if BC share more then 1 digit perform basic als-xz eliminations}
if (popcnt(dword( (comboset2[yn6]*Comboset2[yn2]) ) ) >1 )
then
for R in ((comboset[yn2] * comboset[yn6] )-(z2) ) do {search for common digit to both B & C, thats not the RC of z2,}
if ((Digitcell[R]* combosets[xn3,yn5] )<> [] )
and(( Digitcell[R] * combosets[xn,yn])<> [])
// and (Digitcell[R] * combosets[xn2,yn3] = [])
then
begin
active:=true;
a3:=(([0..80] * digitcell[R])); {valid eliminations must contain R and cannot be in the sets a&C}
for q in ((combosets[xn3,yn5] {+ combosets[xn2,yn3] }+ combosets[xn,yn]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b}
a3:=peer[q] * a3 - (combosets[xn,yn] {+ combosets[xn2,yn3]} + combosets[xn3,yn5]);
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
if ( popcnt(dword(z1)) >1 ) {doubly linked rules } {A & C}
then
begin
active:=true;
{set A&C is now a locked set removal peers cells visable to all copies of each digit in both sets}
for R in comboset[yn2] + comboset[yn4] do
for q in ([0..80] * digitcell[R]) do
begin {R/Q elimiantion search}
if (R in (comboset[yn2] * Comboset[yn4]) ){search for common digit to both, and active in both}
and ((digitcell[R] * combosets[xn,yn]) <> [] )
and ( (Digitcell[R] * combosets[xn2,yn3]) <> [])
and (Peer[q] * ((Combosets[xn,yn]+Combosets[xn2,yn3])*digitcell[R]) = ((Combosets[xn,yn] + Combosets[xn2,yn3])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * (Combosets[xn,yn] + combosets[xn2,yn3]) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{cells in set C for digits exclusivly to C their peers cannot contain r}
if (R in (Comboset[yn2] - z1))//Comboset[yn4]) )
and (peer[q] * Digitcell[R] * Combosets[xn,yn] = combosets[xn,yn] * Digitcell[R])
and ([q] * combosets[xn,yn] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{cells in set A for digits exclusivly to A their peers cannot contain r}
if (R in (Comboset[yn4] - z1))//Comboset[yn2]) )
and (peer[q] * Digitcell[R] * Combosets[xn2,yn3] = combosets[xn2,yn3]* Digitcell[R])
and ([q] * combosets[xn2,yn3] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
end; {R/Q elimiantion search}
end; {doubly linked}
if ( popcnt(dword(z2)) >1 ) {doubly linked rules } {B & C}
then
begin
active:=true;
{set B&C is now a locked set removal peers cells visable to all copies of each digit in both sets}
for R in comboset[yn2] + comboset[yn6] do
for q in ([0..80] * digitcell[R]) do
begin {R/Q elimiantion search}
if (R in (comboset[yn2] * Comboset[yn6]) ){search for common digit to both, and active in both}
and ((digitcell[R] * combosets[xn,yn]) <> [] )
and ( (Digitcell[R] * combosets[xn3,yn5]) <> [])
and (Peer[q] * ((Combosets[xn,yn]+Combosets[xn3,yn5])*digitcell[R]) = ((Combosets[xn,yn] + Combosets[xn3,yn5])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * (Combosets[xn,yn] + combosets[xn3,yn5]) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{cells in set C for digits exclusivly to C their peers cannot contain r}
if (R in (Comboset[yn2] - z2))//Comboset[yn6]) )
and (peer[q] * Digitcell[R] * Combosets[xn,yn] = combosets[xn,yn] * Digitcell[R])
and ([q] * combosets[xn,yn] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{cells in set B for digits exclusivly to B their peers cannot contain r}
if (R in (Comboset[yn6] - z2))// Comboset[yn2]) )
and (peer[q] * Digitcell[R] * Combosets[xn3,yn5] = combosets[xn3,yn5]* Digitcell[R])
and ([q] * combosets[xn3,yn5] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
end; {R/Q elimiantion search}
end; {doubly linked}
{tripply linked rules } {B & A & C are all locked sets}
if (( popcnt(dword(z3)) >=1) and(( popcnt(dword(z3+z2+z1)) >=3))) // and(z3 - (z2+z1) <> [] )) {check that the resticted commons between the three sets are all diffrent}
then
begin
active:=true;
{set B&C is now a locked set removal peers cells visable to all copies of each digit in all sets}
for R in comboset[yn4] + comboset[yn6] +comboset[yn2] do
for q in ([0..80] * digitcell[R]) do
begin {R/Q elimiantion search}
if (R in (comboset[yn4] * Comboset[yn6] * Comboset[yn2]) ){search for common digit to all, and active in all}
and ((digitcell[R] * combosets[xn2,yn3]) <> [] )
and ( (Digitcell[R] * combosets[xn3,yn5]) <> [])
and ( (Digitcell[R] * combosets[xn,yn]) <> [])
and (Peer[q] * ((Combosets[xn2,yn3]+Combosets[xn3,yn5]+combosets[xn,yn])*digitcell[R]) = ((Combosets[xn2,yn3] + Combosets[xn3,yn5]+combosets[xn,yn])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * (Combosets[xn2,yn3] + combosets[xn3,yn5]+combosets[xn,yn]) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
if (R in (comboset[yn4] * Comboset[yn6] ) ){search for common digit to ab, and active in ab}
and ((digitcell[R] * combosets[xn2,yn3]) <> [] )
and ( (Digitcell[R] * combosets[xn3,yn5]) <> [])
and ( (Digitcell[R] * combosets[xn,yn]) = []) {and not in c}
and (Peer[q] * ((Combosets[xn2,yn3]+Combosets[xn3,yn5]{+combosets[xn,yn]})*digitcell[R]) = ((Combosets[xn2,yn3] + Combosets[xn3,yn5]+combosets[xn,yn])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * (Combosets[xn2,yn3] + combosets[xn3,yn5]{+combosets[xn,yn]}) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
if (R in (comboset[yn2] * Comboset[yn6] ) ){search for common digit to cb, and active in c}
and ((digitcell[R] * combosets[xn,yn]) <> [] )
and ( (Digitcell[R] * combosets[xn3,yn5]) <> [])
and ( (Digitcell[R] * combosets[xn2,yn3]) = []) {and not in b}
and (Peer[q] * (({Combosets[xn2,yn3]+}Combosets[xn3,yn5]+combosets[xn,yn])*digitcell[R]) = ((Combosets[xn2,yn3] + Combosets[xn3,yn5]+combosets[xn,yn])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * ({Combosets[xn2,yn3] +} combosets[xn3,yn5]+combosets[xn,yn]) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
if (R in (comboset[yn2] * Comboset[yn4] ) ){search for common digit to ca, and active in ca}
and ((digitcell[R] * combosets[xn,yn]) <> [] )
and ( (Digitcell[R] * combosets[xn2,yn3]) <> [])
and ( (Digitcell[R] * combosets[xn3,yn5]) = []) {and not in b}
and (Peer[q] * ((Combosets[xn2,yn3]+{Combosets[xn3,yn5]+}combosets[xn,yn])*digitcell[R]) = ((Combosets[xn2,yn3] + Combosets[xn3,yn5]+combosets[xn,yn])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * (Combosets[xn2,yn3] {+ combosets[xn3,yn5]}+combosets[xn,yn]) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{belive comboset yn6,yn2 can be replaced with z1,z2,z3} //same as i did for the xz-function.
{cells in set A for digits exclusivly to A their peers cannot contain r}
if (R in (Comboset[yn4] - (Comboset[yn6]+comboset[yn2])) )
and (peer[q] * Digitcell[R] * Combosets[xn2,yn3] = combosets[xn2,yn3] * Digitcell[R])
and ([q] * combosets[xn2,yn3] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{cells in set B for digits exclusivly to B their peers cannot contain r}
if (R in (Comboset[yn6] - ( Comboset[yn4]+comboset[yn2]) ))
and (peer[q] * Digitcell[R] * Combosets[xn3,yn5] = combosets[xn3,yn5]* Digitcell[R])
and ([q] * combosets[xn3,yn5] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
{cells in set C for digits exclusivly to C their peers cannot contain r}
if (R in (Comboset[yn2] - ( Comboset[yn4]+comboset[yn6]) ))
and (peer[q] * Digitcell[R] * Combosets[xn,yn] = combosets[xn,yn]* Digitcell[R])
and ([q] * combosets[xn,yn] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k =0 then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + [q];
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
end; {R/Q elimiantion search}
end; {tripply linked}
if (k= 0)
and (techwrite[u,9] <> [])
then
begin
techwrite[u,0]:=techwrite[u,0]+[3];
techwrite[u,1]:=techwrite[u,1]+[6];
techwrite[u,2]:=techwrite[u,2]+comboset[yn2];
techwrite[u,3]:=techwrite[u,3]+Combosets[xn,yn];
techwrite[u,4]:=techwrite[u,4]+comboset[yn4];
techwrite[u,5]:=techwrite[u,5]+combosets[xn2,yn3];
techwrite[u,6]:=techwrite[u,6]+comboset[yn6];
techwrite[u,7]:=techwrite[u,7]+combosets[xn3,yn5];
techwrite[u,8]:=techwrite[u,8]+ z1 + z2;
end;
if u = 32767 {max array size error code safty exit}
then
begin
if k = 0 then
techdisplay(#121,u);
setlength(techwrite,0,0);
u:=0; setlength(techwrite,u+1,20)
end;
if (k=0) and (techwrite[u,9] <> []) then begin u:=U+1; setlength(techwrite,u+1,20); end;
end; {normal eliminations}
end;
end;
if k = 0 then
chaindisplay(#121,u);
end;{als -xy rule}[/code][/hidden]
[url=http://forum.enjoysudoku.com/als-w-wings-rings-t36860.html]ALS-w-wing[/url]
[hidden=Als-W-wing][code]
{w -wing technique expanded from bivavle cells into als sets}
procedure alswwing(k:integer);
var
q,xn,xn2,yn,yn2,yn3,yn4,yn5,yn6,n,n2,z,x,r,r2,u,alsa,alsb:integer;
A3:numberset;
z1:nums;
lx1: numberset;
lx2: numberset;
lx3: numberset;
lx4: numberset;
lx5: numberset;
begin
alsfinder;
//ahsfinder;
if k=0 then begin u:=0; setlength(techwrite,u+1,21); end;
for alsA:= low(als) to (high(als)-1) do {als A}
if (als[alsA,1]+1 = als[alsA,2]) {cell = digit +1}
then
for ALSB:= alsa+1 to high(als) do {Als B}
if (als[alsb,1]+1 = als[alsb,2] ) {cell = digit +1}
and (popcnt(dword((comboset2[als[alsa,4]]*Comboset2[als[alsb,4]]) ) ) >1 ) {set a & B must share 2 digits}
and (combosets[als[alsa,0],als[alsa,3]] - combosets[als[alsb,0],als[alsb,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
and (combosets[als[alsb,0],als[alsb,3]] - combosets[als[alsa,0],als[alsa,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
then
begin
xn:=als[alsa,0];
xn2:=als[alsb,0];
yn:=als[alsA,3];
yn3:=als[alsB,3];
yn2:=als[alsa,4];
yn4:= als[alsb,4];
for N in (comboset[yn4] * comboset[yn2]) do
if (digitcell[n] *( combosets[xn,yn] * combosets[xn2,yn3]) = []){sectors cannot have overlapping shared linked digit}
then
begin
lx1:=[0..80];
lx2:=[0..80];
for x in (digitcell[n] * combosets[xn,yn]) do
lx1:=lx1 * peer[x];
for x in (digitcell[n] * combosets[xn2,yn3]) do
lx2:=lx2 * peer[x];
for yn5 in [0..26] do
if (Digitrcb[yn5,n] <> [] ) and (Sec[yn5,n] < 7)
and ( (digitrcb[yn5,n] * lx1) + (digitrcb[yn5,n] * lx2 ) = digitrcb[yn5,n] )
// and (lx1 * lx2 <> []) { not as simple as a 1 direction elimination}
and (digitrcb[yn5,n] * (digitcell[n] * (combosets[xn,yn] + combosets[xn2,yn3])) = [] ) { active N sets cannot overlap the strong link}
and (lx2 * digitrcb[yn5,n] <> []) {peers cant be blank}
and ( lx1 * digitrcb[yn5,n] <> []) {peers cant be blank}
then
begin
if k=0 then
begin
techwrite[u,0]:= comboset[yn2];
techwrite[u,10]:= comboset[yn4];
techwrite[u,11]:= (combosets[xn,yn] ) ;
techwrite[u,12]:=(combosets[xn2,yn3] );
techwrite[u,13]:=digitrcb[yn5,n] * lx1;
techwrite[u,14]:= digitrcb[yn5,n] * lx2;
techwrite[u,15]:= [n];
techwrite[u,16]:=[];
techwrite[u,17]:=[0];
end;
for R in ((comboset[yn4] * comboset[yn2]) - [n]) do
begin
lx3:=[0..80];
for x in digitcell[r] * (combosets[xn2,yn3] + combosets[xn,yn]) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R] *lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;
end;
{self contained Ring - mimics als-doubly linked}
// - restricted common to A & B that is not N and not in the overlap of sets a & B
for R2 in ((comboset[yn4] * comboset[yn2]) - [n]) do
if (digitcell[r2] * combosets[xn,yn] * combosets[xn2,yn3] = [] ) {overlaping cells must not contain r}
then
begin
lx3:=[0..80];
for x in digitcell[r2] * (combosets[xn,yn]) do
lx3:=lx3 * peer[x];
if (lx3 * digitcell[r2]*combosets[xn2,yn3] = digitcell[r2]*combosets[xn2,yn3] )
and (lx3 <> [])
then
begin
if k=0 then
begin
techwrite[u,16]:=techwrite[u,16] +[x];
end;
for R in comboset[yn2] + comboset[yn4] do
for q in ([0..80] * digitcell[R]) do
begin {R/Q elimiantion search}
if (R in (comboset[yn2] * Comboset[yn4]) ){search for common digit to both, and active in both}
and ((digitcell[R] * combosets[xn,yn]) <> [] )
and ( (Digitcell[R] * combosets[xn2,yn3]) <> [])
and (Peer[q] * ((Combosets[xn,yn]+Combosets[xn2,yn3])*digitcell[R]) = ((Combosets[xn,yn] + Combosets[xn2,yn3])*digitcell[R])) {makes sure the peer of q can see all the digits}
and ([q] * (Combosets[xn,yn] + combosets[xn2,yn3]) = []) {q cannot elimiante from a set cell}
then
begin
covered2[R]:=Covered2[R] + [q];
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *[q]);
end;
end;
{cells in set A for digits exclusivly to A their peers cannot contain r}
if (R in (Comboset[yn2] - Comboset[yn4]) )
and (peer[q] * Digitcell[R] * Combosets[xn,yn] = combosets[xn,yn] * Digitcell[R])
and ([q] * combosets[xn,yn] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *[q]);
end;
end;
{cells in set B for digits exclusivly to B their peers cannot contain r}
if (R in (Comboset[yn4] - Comboset[yn2]) )
and (peer[q] * Digitcell[R] * Combosets[xn2,yn3] = combosets[xn2,yn3]* Digitcell[R])
and ([q] * combosets[xn2,yn3] = [])
then
begin
covered2[R]:=Covered2[R] + [q];
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *[q]);
end;
end;
end; {R/Q elimiantion search}
end;
end; {self contained doubly linked als-xz thanks to y5 link}
For n2 in (comboset[yn4]*comboset[yn2])- [n] do
begin
lx4:=[0..80];
lx5:=[0..80];
for x in (digitcell[n2] * combosets[xn,yn]) do
lx4:=lx4 * peer[x];
for x in (digitcell[n2] * combosets[xn2,yn3]) do
lx5:=lx5 * peer[x];
{rings}
for yn6 in [0..26] do
if (Digitrcb[yn6,n2] <> [] ) and (Sec[yn6,n2] < 7)
and ( (digitrcb[yn6,n2] * lx4) + (digitrcb[yn6,n2] * lx5 ) = digitrcb[yn6,n2] )
// and (lx1 * lx2 <> []) { not as simple as a 1 direction elimination}
and (digitrcb[yn6,n2] * (digitcell[n2] * (combosets[xn,yn] + combosets[xn2,yn3])) = [] ) { active N sets cannot overlap the strong link}
and (lx4 * digitrcb[yn6,n2] <> []) {peers cant be blank}
and ( lx5 * digitrcb[yn6,n2] <> []) {peers cant be blank}
then
begin
{regular eliminations}
for R in ((comboset[yn4] * comboset[yn2]) - [n2]) do
begin
lx3:=[0..80];
for x in digitcell[r] * (combosets[xn2,yn3] + combosets[xn,yn]) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;{regular eliminations}
end;
{regular eliminations}
for R in ((comboset[yn4] * comboset[yn2]) - [n]) do
begin
lx3:=[0..80];
for x in digitcell[r] * (combosets[xn2,yn3] + combosets[xn,yn]) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;{regular eliminations}
end;
{all digits common to a & b are locked to a & b remove peers }
for R in ((comboset[yn4] * comboset[yn2]) ) do
begin
lx3:=[0..80] - ((digitrcb[yn6,n2]+ digitrcb[yn5,n]) + (combosets[xn2,yn3] + combosets[xn,yn]) );
for x in digitcell[r] * (combosets[xn2,yn3] + combosets[xn,yn]) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;{peers of set a & B common digits eliminations}
end;
{B non n,n2 digits are locked to set b }
for R in (comboset[yn4] -[n,n2] ) do
begin
lx3:=[0..80] - (combosets[xn,yn] + combosets[xn2,yn3]);
for x in digitcell[r] * (combosets[xn2,yn3]) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;
end;
{A non n,n2 digits are locked to set A }
for R in (comboset[yn2] -[n,n2] ) do
begin
lx3:=[0..80] - (combosets[xn,yn] + combosets[xn2,yn3]);
for x in digitcell[r] * (combosets[xn,yn]) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;
end;
{eliminates n2 from b + part y6 sector in cells that are peers }
For R in [n2] do
begin
lx3:= [0..80] - (combosets[xn,yn] + combosets[xn2,yn3] + (digitrcb[yn6,n2]));
for x in digitcell[r] * (combosets[xn2,yn3] + (lx5 * digitrcb[yn6,n2])) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] +(digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;
end;
{eliminates n2 from A + part of y6 sector cells that are peers }
For R in [n2] do
begin
lx3:= [0..80] - (combosets[xn,yn] + combosets[xn2,yn3] + (digitrcb[yn6,n2]));
for x in digitcell[r] * (combosets[xn,yn] + (lx4 * digitrcb[yn6,n2])) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;
end;
{eliminates n from b + part y5 sector in cells that are peers }
For R in [n] do
begin
lx3:= [0..80] - (combosets[xn,yn] + combosets[xn2,yn3] + (digitrcb[yn5,n]));
for x in digitcell[r] * (combosets[xn2,yn3] + (lx2 * digitrcb[yn5,n])) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] + (digitcell[R]*lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;
end;
{eliminates n from A + part of y5 sector cells that are peers }
For R in [n] do
begin
lx3:= [0..80] - (combosets[xn,yn] + combosets[xn2,yn3] + (digitrcb[yn5,n]));
for x in digitcell[r] * (combosets[xn,yn] + (lx1 * digitrcb[yn5,n])) do
lx3:=lx3 * peer[x];
if (digitcell[R] * lx3 <> []) and (lx3 <> [0..80])
then
begin
active:=true;
covered2[r]:=covered2[r] +(digitcell[R]* lx3);
if k=0 then
begin
techwrite[u,r]:=techwrite[u,r] +(digitcell[R] *lx3);
end;
end;
end;
if k=0 then
begin
techwrite[u,0]:= comboset[yn2];
techwrite[u,10]:= comboset[yn4];
techwrite[u,11]:= (combosets[xn,yn] ) ;
techwrite[u,12]:=(combosets[xn2,yn3] );
techwrite[u,13]:=digitrcb[yn5,n] * lx1;
techwrite[u,14]:= digitrcb[yn5,n] * lx2;
techwrite[u,15]:= [n];
techwrite[u,19]:= [n2];
techwrite[u,17]:=[0,1];
techwrite[u,18]:=digitrcb[yn6,n2] * lx4;
techwrite[u,20]:=digitrcb[yn6,n2] * lx5;
end;
if (k = 0) and ((techwrite[u,1] <> []) or (techwrite[u,2] <> []) or (techwrite[u,3] <> [])or (techwrite[u,4] <> [])or (techwrite[u,5] <> [])or (techwrite[u,6] <> [])or (techwrite[u,7] <> [])or (techwrite[u,8] <> [])or (techwrite[u,9] <> []))
then
begin
u:=u+1;
setlength(techwrite,u+1,21);
end;
end; {yn6}
end; {n2 restictions check}
if (k = 0) and ((techwrite[u,1] <> []) or (techwrite[u,2] <> []) or (techwrite[u,3] <> [])or (techwrite[u,4] <> [])or (techwrite[u,5] <> [])or (techwrite[u,6] <> [])or (techwrite[u,7] <> [])or (techwrite[u,8] <> [])or (techwrite[u,9] <> []))
then
begin
u:=u+1;
setlength(techwrite,u+1,21);
end;
end;
end; {y5 N directional search};
end; { completed a & b set search}
if k = 0 then techdisplay(#23,u);
end; {als-w-wing}[/code][/hidden]
[url=http://forum.enjoysudoku.com/als-s-wing-t36880.html]AlS-Swing[/url]
[hidden=ALS- S-Wing][code]{Swing expaned so the bivavle is an almost locked set}
Procedure alsSwing(K:integer);
var
q,xn,xn5,j,j2,xn2,yn,yn2,yn3,yn4,yn5,yn6,n,n2,z,z2,x,r,r2,g,count,count2,alsa:integer;
A3:numberset;
z1:nums;
lx1: numberset;
lx2: numberset;
lx3: numberset;
lx4: numberset;
lx5: numberset;
begin
alsfinder;
//ahsfinder;
if k=0 then begin g:=0; setlength(techwrite,g+1,16); end;
for alsA:= low(als) to (high(als)) do {als A}
if (als[alsA,1]+1 = als[alsA,2]) {cell = digit +1}
then
begin
xn5:=als[alsa,0];
yn5:=als[alsA,3];
yn4:= als[alsa,4];
for n in (comboset[yn4] ) do
for n2 in (comboset[yn4] - [n]) do
begin
lx1:=[0..80];
for x in (digitcell[n] * combosets[xn5,yn5]) do
lx1:=lx1 * peer[x];
lx2:=[0..80];
for x in (digitcell[n2] * combosets[xn5,yn5]) do
lx2:=lx2 * peer[x];
for J in [0..26] do
if (digitrcb[j,n] <> [])
and ((digitcell[n]*combosets[xn5,yn5]) * digitrcb[j,n]=(digitcell[n]*combosets[xn5,yn5]))
then
for yn in peerrcb[j] do
if (digitrcb[yn,n] <> [])
and not ((digitcell[n]*combosets[xn5,yn5])* digitrcb[yn,n]= (digitcell[n]*combosets[xn5,yn5]))
and (digitrcb[yn,n] * digitrcb[j,n] <> [])
and ( (Digitrcb[yn,n] * digitrcb[j,n]) = ( lx1 * digitrcb[yn,n] ) )
then
for z in peerrcb[yn] do
if (digitrcb[z,n] <> [] )
and not ((digitcell[n]* combosets[xn5,yn5]) * digitrcb[z,n]= (digitcell[n]*combosets[xn5,yn5]))
and (digitrcb[z,n] * digitrcb[yn,n] <> [])
and ((digitrcb[z,n] * digitrcb[yn,n]) + (digitrcb[yn,n] * digitrcb[j,n] ) = digitrcb[yn,n])
then
for J2 in ([0..26]) do
if (digitrcb[j2,n2] <> [])
and ((digitcell[n2]*combosets[xn5,yn5]) * digitrcb[j2,n2]=(digitcell[n2]*combosets[xn5,yn5]))
then
for yn2 in peerrcb[j2] - [yn] do
if (digitrcb[yn2,n2] <> [])
and not ( (digitcell[n2] * combosets[xn5,yn5]) * digitrcb[yn2,n2]=(digitcell[n2] * combosets[xn5,yn5]))
and (digitrcb[yn2,n2] * digitrcb[j2,n2] <> [])
and ( (Digitrcb[yn2,n2] * digitrcb[j2,n2]) = ( lx2 * digitrcb[yn2,n2] ) )
then
for z2 in (peerrcb[z] * peerrcb[yn2]) do
if (digitrcb[z2,n2] <> [] )
and not ((digitcell[n2]*combosets[xn5,yn5]) * digitrcb[z2,n2]=(digitcell[n2]*combosets[xn5,yn5]))
and (digitrcb[z2,n2] * digitrcb[yn2,n2] <> [])
and ((digitrcb[z2,n2] * digitrcb[yn2,n2]) + (digitrcb[yn2,n2] * digitrcb[j2,n2] ) = digitrcb[yn2,n2])
then
if ( (digitrcb[yn,n2] * digitrcb[z2,n2] ) = (digitrcb[yn,n2] * digitrcb[z2,n2]) )
and ( (digitrcb[yn2,n] * digitrcb[z,n] ) = (digitrcb[yn2,n] * digitrcb[z,n]) )
and (( digitrcb[yn,n] * digitrcb[z,n] ) * (digitrcb[yn2,n2] * digitrcb[z2,n2] ) = [])
then
begin
Count:=0;
count2:=0;
for q in (digitrcb[yn,n] * digitrcb[z,n]) do
inc(count);
for q in (digitrcb[yn2,n2] * digitrcb[z2,n2]) do
inc(count2);
if ((count in [1]) and ((digitrcb[yn,n2] * Digitrcb[z,n2]) * (digitrcb[yn,n] * Digitrcb[z,n]) <> []) )
or ((count2 in [1]) and ((digitrcb[yn2,n] * Digitrcb[z2,n]) * (digitrcb[yn2,n2] * Digitrcb[z2,n2]) <> []))
then
begin
active:=true;
if k = 0 then begin
techwrite[g,0]:=combosets[xn5,yn5];
techwrite[g,10]:= [n];
techwrite[g,11]:=[n2];
techwrite[g,12]:= digitrcb[yn,n] * digitrcb[z,n];
techwrite[g,13]:= digitrcb[yn,n] - (digitrcb[yn,n] * digitrcb[z,n]);
techwrite[g,14]:= (digitrcb[yn2,n2] * digitrcb[z2,n2]);
techwrite[g,15]:= digitrcb[yn2,n2] - (digitrcb[yn2,n2] * digitrcb[z2,n2]);
end;
if (count in [1])
and ((digitrcb[yn,n2] * Digitrcb[z,n2]) * (digitrcb[yn,n] * Digitrcb[z,n]) <> [] )
then
for q in ( digitrcb[yn,n] * digitrcb[z,n]) do
if (peer[q] * (digitrcb[yn2,n2] * digitrcb[z2,n2]) = (digitrcb[yn2,n2] * digitrcb[z2,n2]))
then
begin
covered2[n2]:= covered2[n2] +(digitrcb[yn,n] * Digitrcb[z,n]);
if k = 0
then techwrite[g,n2]:=(digitrcb[yn,n] * Digitrcb[z,n]);
end;
if (count2 in [1])
and ((digitrcb[yn2,n] * Digitrcb[z2,n]) * (digitrcb[yn2,n2] * Digitrcb[z2,n2]) <> [])
then
for q in ( digitrcb[yn2,n2] * digitrcb[z2,n2]) do
if (peer[q] * (digitrcb[yn,n] * digitrcb[z,n]) = (digitrcb[yn,n] * digitrcb[z,n]))
then
begin
covered2[n]:= covered2[n] +(digitrcb[yn2,n2] * Digitrcb[z2,n2]);
if k = 0
then techwrite[g,n]:=(digitrcb[yn2,n2] * Digitrcb[z2,n2]);
end;
if (k = 0) and (techwrite[g,n] + techwrite[g,n2] <> [])
then
begin
g:=g+1;
setlength(techwrite,g+1,16);
end;
end;
end;
end;
end;
if k= 0 then techdisplay(#4,g);
end;{alsswing}[/code][/hidden]
[url=http://forum.enjoysudoku.com/als-m-wings-rings-t36866.html]als-m-wing[/url]
[hidden=ALS-M-Wing][code]{All most locket set version of for the M - wing changing the bivavles to als sets}
procedure alsMwing(k:integer);
var
q,xn,xn5,xn2,yn,yn2,yn3,yn4,yn5,yn6,n,n2,z,x,r,r2,g,alsa:integer;
A3:numberset;
z1:nums;
lx1: numberset;
lx2: numberset;
lx3: numberset;
lx4: numberset;
lx5: numberset;
begin
alsfinder;
//ahsfinder;
if k=0 then begin g:=0; setlength(techwrite,g+1,16); end;
for alsA:= low(als) to (high(als)) do {als A}
if (als[alsA,1]+1 = als[alsA,2]) {cell = digit +1}
then
begin
xn5:=als[alsa,0];
yn5:=als[alsA,3];
yn4:= als[alsa,4];
for xn2 in ComboSubset[yn4] do
if (popcnt(dword(((comboset[yn4]*pm[xn2])))) >1) and (peer[xn2] * combosets[xn5,yn5] = [])
then
for n in (comboset[yn4]*pm[xn2]) do
begin
lx1:=[0..80];
for x in (digitcell[n] * combosets[xn5,yn5]) do
lx1:=lx1 * peer[x];
for yn in [0..26] do
if (lx1 * digitrcb[yn,n] <> [] )
and (lx1 * digitrcb[yn,n] <> Digitrcb[yn,n] )
then
{row,box,col}
if (digitrcb[yn,n] <> [] ) and (sec[yn,n] <5)
and(digitrcb[yn,n] * ( (lx1*digitrcb[yn,n]) + [xn2] ) = digitrcb[yn,n] )
then
begin
for n2 in ((comboset[yn4]*pm[xn2]) - [n]) do
begin
lx2:=[0..80];
for x in (digitcell[n2] * combosets[xn5,yn5]) do
lx2:=lx2 * peer[x];
{row}
for yn2 in ((peerRCB[Rsec[rx[xn2]]] + peerrcb[Csec[Cy[xn2]]] + peerrcb[bsec[bxy[xn2]]]) ) do
begin
if (digitrcb[yn2,n2] <> [] ) and (sec[yn2,n2] <6)
and ((digitrcb[yn2,n2] * peer[xn2]) + [xn2] = digitrcb[yn2,n2] )
then
begin
active:=true;
for z:= 0 to 80 do
if (peer[z] * ((digitcell[n2]*combosets[xn5,yn5]) + ( digitrcb[yn2,n2] - [xn2]) )
= ((digitcell[n2]*combosets[xn5,yn5]) +( digitrcb[yn2,n2] - [xn2]) ) ) and (z in digitcell[n2])
then
begin
covered2[n2]:=covered2[n2] + [z];
if k = 0 then
techwrite[g,n2]:=techwrite[g,n2] + [z];
end;
if ((digitrcb[yn2,n2] * lx2) = (digitrcb[yn2,n2] -[xn2]) ) {ring code}
then
begin
for z:= 0 to 80 do
begin
if (peer[z] * ([xn2] + (digitrcb[yn,n] -(digitcell[n]*combosets[xn5,yn5])) )= ([xn2] + (digitrcb[yn,n] - (digitcell[n]*combosets[xn5,yn5])) )) and (z in digitcell[n])
then
begin
covered2[n]:=covered2[n] + [z];
if k = 0 then
techwrite[g,n]:=techwrite[g,n] + [z];
end;
For R in (comboset[yn4] -[n,n2]) do
if (peer[z] * (Digitcell[R]*Combosets[xn5,yn5]) = digitcell[r]*Combosets[xn5,yn5])
and (R in pm[z])
then
begin
covered2[r]:=covered2[r] + [z];
if k = 0 then
techwrite[g,r]:=techwrite[g,r] + [z];
end;
end;
covered[xn2]:= covered[xn2] + (pm[xn2] - [n,n2] ); {xn2 becomes a locked pair}
if k= 0
then
for z in (pm[xn2] - [n,n2]) do
techwrite[g,z]:=techwrite[g,z]+[xn2];
end; {rings}
end;
if k =0
then
begin
techwrite[g,0]:= [n];
techwrite[g,10]:= [n2];
techwrite[g,11]:=combosets[xn5,yn5];
techwrite[g,12]:=[xn2];
techwrite[g,13]:= (digitrcb[yn,n] * lx1);
techwrite[g,14]:= (digitrcb[yn2,n2] * peer[xn2]);
end;
if (k =0) and ( (techwrite[g,n2] <> []) or (techwrite[g,n] <> []) )
then begin
g:=g+1;
setlength(techwrite,g+1,15);
end;
end;{end row,box,col}
end; {end #'s for rows,cols,boxs}
end; {end row,col,box}
end;
end; {set A}
if k = 0 then techdisplay(#1,g);
end;{alsMwing}
[/code][/hidden]
[hidden=AALS-2RC-rule][code]{Almost Almost locked set 2 RC rule}
procedure Aals2RC(k:integer); {so far this is 100,000% faster}
var
q,xn,xn2,xn3,yn,yn2,yn3,yn4,YN5,YN6,n,z,x,act3,r,u,alsa,alsb,alsc:integer;
A3:numberset;
z1:nums;
Z2:nums;
z3:nums;
lx1: rcbpeer;
lx2: rcbpeer;
lx3: rcbpeer;
begin
alsfinder;
//ahsfinder;
if k=0 then begin u:=0; setlength(techwrite,u+1,20); end;
for alsA:= low(als) to (high(als)) do {als C}
if (als[alsA,1]+2 = als[alsA,2]) {cell = digit +2}
then
for ALSB:= low(als) to high(als)-1 do {Als A}
if (als[alsb,1]+1 = als[alsb,2] ) {cell = digit +1}
and (popcnt(dword((comboset2[als[alsa,4]]*Comboset2[als[alsb,4]]) ) ) >=1 ) {set a & C must share 1 digits}
and (combosets[als[alsa,0],als[alsa,3]] - combosets[als[alsb,0],als[alsb,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
and (combosets[als[alsb,0],als[alsb,3]] - combosets[als[alsa,0],als[alsa,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
then
begin
z1:=[];
xn:=als[alsa,0];
xn2:=als[alsb,0];
yn:=als[alsA,3];
yn3:=als[alsB,3];
yn2:=als[alsa,4];
yn4:= als[alsb,4];
{restricted common chcek A & C}
for z in (comboset[yn4] * comboset[yn2]) do
if ((Digitcell[z] * combosets[xn,yn]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn2,yn3]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn,yn] * combosets[xn2,yn3]) = []) {resticted commons cannot be found in an overlap cell}
then
begin
lx2:=[0..26]; { a RC should only exist in the common intersections of the selected sets}
for q in (combosets[xn,yn]+combosets[xn2,yn3]) *digitcell[z] do {combine common cells in both a&b for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z1:=z1 + [z]; {saves the resticted commons}
end;
if popcnt(dword(z1)) >=1 {* single restricted common advance to adding 3rd sector}
then
for alsC:= alsb+1 to (high(als)) do {als b}
if (als[alsC,1]+1 = als[alsC,2]) {cell = digit +1}
and (popcnt(dword(( comboset2[yn2]*Comboset2[als[alsC,4]] ) ) ) >=1 ) {checks that set B and set C share at least 1 digits}
and (combosets[xn,yn] - combosets[als[alsC,0],ALS[ALSC,3]] <> [] ) { sectors B & C can over lap, however cells cannot overlap in full}
and ( combosets[als[alsC,0],ALS[ALSC,3]] - combosets[xn,yn] <> [] )
then
begin
z2:=[];
z3:=[];
xn3:=als[alsc,0];
yn5:=als[alsc,3];
yn6:= als[alsc,4];
{restricted common chcek B & C}
for z in (comboset[yn6] * comboset[yn2] ) do
if ((Digitcell[z] * combosets[xn3,yn5]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn,yn] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn,yn]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn,yn] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn3,yn5] * combosets[xn,yn]) = []) {resticted commons cannot be found in an overlap cell}
//and (digitcell[z] * Combosets[xn2,yn3] - (combosets[xn3,yn5]+combosets[xn,yn]) = []){resticted commons cannot be found in an overlap cell shared by the 2nd set}
then
begin
lx2:=[0..26]; { a RC should only exist in the common intersections of the selected sets}
for q in (combosets[xn3,yn5]+combosets[xn,yn]) *digitcell[z] do {combine common cells in both C&B for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z2:=z2 + [z]; {saves the resticted commons}
end;
{restricted common chcek B & A}
for z in (comboset[yn6] * comboset[yn4] ) do
if ((Digitcell[z] * combosets[xn3,yn5]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn2,yn3] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn2,yn3]) - ({(digitcell[z]*COmbosets[xn2,yn3]) + }(combosets[xn2,yn3] * combosets[xn3,yn5])) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn3,yn5] * combosets[xn2,yn3]) = []) {resticted commons cannot be found in an overlap cell}
//and (digitcell[z] * Combosets[xn2,yn3] - (combosets[xn3,yn5]+combosets[xn,yn]) = []){resticted commons cannot be found in an overlap cell shared by the 2nd set}
then
begin
lx2:=[0..26]; { a RC should only exist in the common intersections of the selected sets}
for q in (combosets[xn3,yn5]+combosets[xn2,yn3]) *digitcell[z] do {combine common cells in both C&B for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z3:=z3 + [z]; {saves the resticted commons}
end;
if (( popcnt(dword(z2)) >1 ) and ( popcnt(dword(z1)) >1 )){if the resticted common on a set is more then 1 its an double linked als-xz rule}
or (( popcnt(dword(z2)) =1 ) and ( popcnt(dword(z1)) =1 ) and (z1 - z2 <> [] ) and (Z2 - z1 <> [])) {checks that both sectors have at least 1 RC and those numbers are diffrent }
or (( popcnt(dword(z2)) =1 ) and ( popcnt(dword(z1)) >1 ))
or (( popcnt(dword(z2)) >1 ) and ( popcnt(dword(z1)) =1 ))
// and ((comboset[yn4] * Comboset[yn6] - (z2+z1) ) <> [])
then
begin {Eliminations A & B peer of z}
if (popcnt(dword( (comboset2[yn4]*Comboset2[yn6]*comboset2[yn2]) ) ) >=1 )
then
for R in ((comboset[yn6] * comboset[yn4] * comboset[yn2] ) ) do {search for common digit to both A & B &C, thats not the RC of z1,z2,z3}
if ((Digitcell[R]* combosets[xn2,yn3] )<> [] )
and(( Digitcell[R] * combosets[xn3,yn5])<> [])
and ((Digitcell[R] * combosets[xn,yn] <> []))
and ((z1-z2) - [r] <> [])
and ((z2-z1) - [r] <> [])
then
begin
active:=true;
a3:=(([0..80] * digitcell[R]) ); {valid eliminations must contain R and cannot be in the sets a&b}
for q in ((combosets[xn3,yn5] + combosets[xn2,yn3] + combosets[xn,yn]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b&C}
a3:=peer[q] * a3 - (combosets[xn,yn] + combosets[xn2,yn3] + combosets[xn3,yn5]);
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
if (popcnt(dword( (z1+z2) ) ) >=4 ) {double linked restriction of links}
then
begin
for R in ((comboset[yn6] * comboset[yn2] *z2 ) ) do {search for common digit to both C & B thats in Z2}
if ((Digitcell[R]* combosets[xn,yn] )<> [] )
and(( Digitcell[R] * combosets[xn3,yn5])<> [])
then
begin
active:=true;
a3:=(([0..80] * digitcell[R]) ); {valid eliminations must contain R and cannot be in the sets a&b}
for q in ((combosets[xn3,yn5] {+ combosets[xn2,yn3]} + combosets[xn,yn]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b&C}
a3:=peer[q] * a3- (combosets[xn,yn] {+ combosets[xn2,yn3] }+ combosets[xn3,yn5]);
if (a3 <> (([0..80] * digitcell[R]))) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
for R in ((comboset[yn2] * comboset[yn4] *z1 ) ) do {search for common digit to both C & A thats in Z1}
if ((Digitcell[R]* combosets[xn,yn] )<> [] )
and(( Digitcell[R] * combosets[xn2,yn3])<> [])
then
begin
active:=true;
a3:=(([0..80] * digitcell[R]) ); {valid eliminations must contain R and cannot be in the sets a&b}
for q in (({combosets[xn3,yn5] +} combosets[xn2,yn3] + combosets[xn,yn]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b&C}
a3:=peer[q] * a3 - (combosets[xn,yn] + combosets[xn2,yn3] {+ combosets[xn3,yn5]});
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
for R in ((comboset[yn2] ) -(z1+z2) ) do {search for digit in A thats left from Z1+z2}
if ((Digitcell[R]* combosets[xn,yn] )<> [] )
then
begin
active:=true;
a3:=(([0..80] * digitcell[R]) ); {valid eliminations must contain R and cannot be in the sets a&b}
for q in (({combosets[xn3,yn5] + combosets[xn2,yn3] +} combosets[xn,yn]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b&C}
a3:=peer[q] * a3- (combosets[xn,yn] {+ combosets[xn2,yn3] + combosets[xn3,yn5]});
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
for R in ((comboset[yn4] ) -(z1+z2) ) do {search for digit in A thats left from Z1+z2}
if ((Digitcell[R]* combosets[xn2,yn3] )<> [] )
then
begin
active:=true;
a3:=(([0..80] * digitcell[R]) ); {valid eliminations must contain R and cannot be in the sets a&b}
for q in (({combosets[xn3,yn5] + combosets[xn,yn] +} combosets[xn2,yn3]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b&C}
a3:=peer[q] * a3- (combosets[xn2,yn3] {+ combosets[xn2,yn3] + combosets[xn3,yn5]});
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
for R in ((comboset[yn6] ) -(z1+z2) ) do {search for digit in A thats left from Z1+z2}
if ((Digitcell[R]* combosets[xn3,yn5] )<> [] )
then
begin
active:=true;
a3:=(([0..80] * digitcell[R]) ); {valid eliminations must contain R and cannot be in the sets a&b}
for q in (({combosets[xn2,yn3] + combosets[xn,yn] +} combosets[xn3,yn5]) * digitcell[R] ) do { a combined peer search for R with in the sets, A&b&C}
a3:=peer[q] * a3- (combosets[xn3,yn5] {+ combosets[xn2,yn3] + combosets[xn,yn]});
if (a3 <> (([0..80] * digitcell[R]) )) and (a3 <> []) {safty checks}
then
covered2[R]:=covered2[r] + a3; {elimination trigger}
if (k= 0 ) and (a3<> [0..80]) and (a3 <> [])
then
begin
techwrite[u,r+9]:= techwrite[u,r+9] + a3;
techwrite[u,9]:=techwrite[u,9]+[R];
end;
end;
end;
if (k= 0)
and (techwrite[u,9] <> [])
then
begin
techwrite[u,0]:=[3];
techwrite[u,1]:=[6];
techwrite[u,2]:=techwrite[u,2]+comboset[yn2];
techwrite[u,3]:=techwrite[u,3]+Combosets[xn,yn];
techwrite[u,4]:=techwrite[u,4]+comboset[yn4];
techwrite[u,5]:=techwrite[u,5]+combosets[xn2,yn3];
techwrite[u,6]:=techwrite[u,6]+comboset[yn6];
techwrite[u,7]:=techwrite[u,7]+combosets[xn3,yn5];
techwrite[u,8]:=techwrite[u,8]+ z1+z2;
end;
if u = 32767 {max array size error code safty exit}
then
begin
if k = 0 then
techdisplay(#25,u);
setlength(techwrite,0,0);
u:=0; setlength(techwrite,u+1,20)
//exit;
end;
if (k=0) and (techwrite[u,9] <> []) then begin u:=U+1; setlength(techwrite,u+1,20); end;
end;
end;
end;
if k = 0 then
chaindisplay(#25,u);
end;{Aals 2RC rule}
[/code][/hidden]
[hidden=N^a ls N^rc rule][code]
{N*almost locked set N* RC rule } // work in progress
procedure NalsNRC(K:integer); {mutual exclusion}
type
hold = array of integer;
Nuse = array of integer;
base = array of integer;
rcc = array of array of nums;
RCDs = array of nums;
TRCC = array of nums;
usednum= array of nums;
used = array of numberset;
used2 = array of numberset;
cellused=array of numberset;
almostlockedset3= array of array of integer;
RCSTORE= array of array of nums;
var
xn,w,p,p2,n,n2,a,m,z,xn2,yn,yn3,yn2,yn4,xn3,yn5,yn6,xn4,q,r,u,b,b2,B3,max,size,f:integer;
h:hold;
nouse: nuse;
step: base;
rc:rcc;
RCD:RCDs;
TRC:TRCC;
als3: almostlockedset3;
store: RCSTORE;
A3:numberset;
z1:nums;
z2:nums;
lx1: rcbpeer;
lx2: rcbpeer;
use:used;
use2:used;
usenum : usednum;
celluse : cellused;
begin
alsfinder;
//ahsfinder;
setlength(als3,high(als)+1);
setlength(store,high(als)+1);
for a:= high(als) downto 0 do {startin array}
begin
w:=-1;
for p:= high(als) downto 0 do {iteration of peers}
if (als[p,1]+1 = als[p,2] ) then
if (popcnt(dword((comboset2[als[a,4]]*Comboset2[als[p,4]]) ) ) >=1 ) {set a & B must share >1 digits}
and (combosets[als[a,0],als[a,3]] - combosets[als[p,0],als[p,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
and (combosets[als[p,0],als[p,3]] - combosets[als[a,0],als[a,3]] <> [] ) { sectors can over lap, however cells cannot overlap in full}
then
begin
xn:=als[a,0];
xn2:=als[p,0];
yn:=als[a,3];
yn3:=als[p,3];
yn2:=als[a,4];
yn4:= als[p,4];
z1:=[];
{restricted common chcek}
for z in (comboset[yn4] * comboset[yn2]) do
if ((Digitcell[z] * combosets[xn,yn]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z digit has cells out side the overlap}
and ((Digitcell[z] * combosets[xn2,yn3]) - (combosets[xn2,yn3] * combosets[xn,yn]) <> [] ) {checks that the sector for z dgit has cells out side the overlap}
and (digitcell[z] *( combosets[xn,yn] * combosets[xn2,yn3]) = []) {resticted commons cannot be found in an overlap cell}
then
begin
lx2:=[0..26]; { a RC should only exist in the common intersections of the selected sets}
for q in (combosets[xn,yn]+combosets[xn2,yn3]) *digitcell[z] do {combine common cells in both a&b for common sectors amongts those cells}
lx2:= lx2 * cellsec[q];
if (popcnt(dword(lx2)) >0) and (popcnt(dword(lx2)) < 3) {check that those cells only existing in 1 or 2 sectors to be restircted}
then
z1:=z1 + [z]; {saves the resticted commons}
end;
if ( ( popcnt(dword(z1)) >=1 ) )
then
begin
w:=w+1;
setlength(als3[a],w+1);
setlength(store[a],w+1);
als3[a,w]:=p;
store[a,w]:=z1;
end;
end;
end;
if k=1 then begin u:=0; setlength(techwrite,u+1,0); end;
for a:= high(als) downto 0 do {startin array}
if (high(als3[a]) +1 >= (als[a,2] - als[a,1]))
and (als[a,2] - als[a,1] >=1)
//and (comboset[als[a,4]] = [1,2,4])
then
begin
w:=0;
setlength(h,w+1);
h[w]:=high(als3[a]);
setlength(TRC,(w+1)); {set the array size to w}
TRC[w]:= [];
setlength(usenum,w+1);
usenum[w]:=comboset[als[a,4]];
setlength(celluse,w+1);
celluse[w]:=combosets[als[a,0],als[a,3]];
setlength(rcd,W+1);
rcd[W]:=Comboset[als[a,4]];
setlength(use,(w+1)); {set the array size to w}
setlength(use2,(w+1)); {set the array size to w}
use[w]:=[0..80] - combosets[als[a,0],als[a,3]];
use2[w]:=[0..80];
size:= (als[a,2] - als[a,1]);
h[w]:= high(als3[a]); {keeps track of what array is the next stop used for step W }
repeat
for p:= h[w] downto 0 do
if ((use[w] * combosets[als[als3[a,p],0],als[als3[a,p],3]]) <> [])
and (( store[a,p] - TRC[w] <>[])
or (w=1) )
// or (( w< size ) and (popcnt(dword(trc[w]))> size) and (store[a,p]-trc[w] = [])) )
{ and ((comboset[als[als3[a,p],4]] = [2,4])
or (comboset[als[als3[a,p],4]] = [1,4])) }
then
begin
h[w]:=h[w]-1;
inc(w);
setlength(h,w+1);
h[w]:=p-1;
setlength(step,w+1);
step[w]:=p;
setlength(usenum,w+1);
usenum[w]:=Comboset[als[als3[a,p],4]];
setlength(celluse,w+1);
celluse[w]:=combosets[als[als3[a,p],0],als[als3[a,p],3]];
setlength(rcd,W+1);
rcd[W]:=RCD[w-1] * Comboset[als[als3[a,p],4]];
setlength(TRC,(w+1)); {set the array size to w}
TRC[w]:= store[a,p]+TRC[w-1];
setlength(use,(w+1)); {set the array size to w}
setlength(use2,(w+1)); {set the array size to w}
use[w]:= use[w-1] - combosets[als[als3[a,p],0],als[als3[a,p],3]];
use2[w]:= use2[w-1] - combosets[als[als3[a,p],0],als[als3[a,p],3]];
{if (k=1)
then
begin
f:=((w+1)*2);
setlength(techwrite[u],0);
setlength(techwrite[u],((f+13)+1));
techwrite[u,0]:=[3];
techwrite[u,1]:=[f];
techwrite[u,(f+3-1)]:=trc[w];
techwrite[u,(f+3)]:=z1;
techwrite[u,2]:=comboset[als[a,4]];
techwrite[u,3]:=combosets[als[a,0],als[a,3]];
for b:= 1 to w do
begin
techwrite[u,(b*2)+2]:=techwrite[u,(b*2)+2] + comboset[als[als3[a,step[b]],4]];
techwrite[u,(b*2)+3]:=techwrite[u,(b*2)+3]+ combosets[als[als3[a,step[b]],0],als[als3[a,step[b]],3]];
end;
u:=u+1;
setlength(techwrite,u+1);
writexy(2,60,'size :');
write(w,' ',size);
end; }
//type 1: links = correct number
if ((w) = size) and (popcnt(dword(TRC[w] )) >= size ) //and (RCD[w] <> [])
then
begin
if k = 1
then
begin
if u = 32765 {max array size error code safty exit}
then
begin
chaindisplay(#22,u);
setlength(techwrite,0,0);
u:=0;
setlength(techwrite,u+1,0)
//exit;
end;
f:=((w+1)*2);
setlength(techwrite[u],0);
setlength(techwrite[u],((f+13)+1));
end;
a3:=[];
a3:= [0..80] - use[w];
z1:=[];
for q:= w downto 1 do
for b:= w downto 1 do
begin
if (popcnt(dword(store[a,step[b]]-z1)) =1)
then
Z1:=z1 + (store[a,step[b]]);
if (popcnt(dword(store[a,step[b]]-rcd[w])) = 1 )
then
z1:= z1 + (store[a,step[b]] - (rcd[w]));
end;
if popcnt(dword(trc[w] -z1 )) = (size - popcnt(dword(z1)))
then
z1:=z1 + trc[w] ;
// eliminates a common digit thats no listed as a RC when RC = number of links}
if popcnt(dword(TRC[w])) = size
then
for b in RCD[w] -( trc[w]) do
for q in digitcell[b] do
if (peer[q] * (a3 * digitcell[b]) = (a3 * digitcell[b]) ) and (a3 * digitcell[b] <> [])
then
begin
Active:=true;
covered2[B]:=covered2[B] + [Q];
if k = 1
then
begin
techwrite[u,(b+F+3)]:=techwrite[u,(b+f+3)] + [q];
techwrite[u,(f+3)]:=techwrite[u,(f+3)] + [b];
end;
end;
// eliminates a common "non" RC when there is more digits then links required
if popcnt(dword(TRC[w])) >= size
then
for b in RCD[w] - z1 do
for q in digitcell[b] do
if( peer[q] * (a3 * digitcell[b]) = (a3 * digitcell[b]) ) and (a3 * digitcell[b] <> [])
then
begin
Active:=true;
covered2[B]:=covered2[B] + [Q];
if k = 1
then
begin
techwrite[u,(b+f+3)]:=techwrite[u,(b+f+3)] + [q];
techwrite[u,(f+3)]:=techwrite[u,(f+3)] + [b];
end;
end;
// elimination code for locked sets
if (popcnt(dword(TRC[w])) >= size*2 )
then
begin
for r:= w downto 1 do
for b in usenum[r] - store[a,step[r]] do
for q in (( digitcell[b]) - celluse[r] ) do
if ((peer[q] * digitcell[b] * celluse[r]) = digitcell[b] * celluse[r])
and (digitcell[b] * celluse[r] <> [] )
then
begin
Active:=true;
covered2[B]:=covered2[B] + [Q];
if k = 1
then
begin
techwrite[u,(b+f+3)]:=techwrite[u,(b+f+3)] + [q];
techwrite[u,(f+3)]:=techwrite[u,(f+3)] + [b];
end;
end;
for b in usenum[0] - trc[w] do
for q in ((digitcell[b] ) - celluse[0] ) do
if ((peer[q] * digitcell[b] * celluse[0]) = digitcell[b] * celluse[0])
and (digitcell[b] * celluse[0] <> [] )
then
begin
Active:=true;
covered2[B]:=covered2[B] + [Q];
if k = 1
then
begin
techwrite[u,(b+f+3)]:=techwrite[u,(b+f+3)] + [q];
techwrite[u,(f+3)]:=techwrite[u,(f+3)] + [b];
end;
end;
for r:= w downto 1 do
for b in usenum[r] * store[a,step[r]] do
for q in (([0..80] * digitcell[b] ) - (celluse[r]+celluse[0]) ) do
if ((peer[q] * digitcell[b] * (celluse[r]+celluse[0])) = (digitcell[b] * (celluse[r]+celluse[0])))
and (digitcell[b] * (celluse[r]+celluse[0]) <> [] )
then
begin
Active:=true;
covered2[B]:=covered2[B] + [Q];
if k = 1
then
begin
techwrite[u,(b+f+3)]:=techwrite[u,(b+f+3)] + [q];
techwrite[u,(f+3)]:=techwrite[u,(f+3)] + [b];
end;
end;
end;
if (k=1) and (techwrite[u,(f+3)] <> [])
then
begin
techwrite[u,0]:=[3];
techwrite[u,1]:=[w];
techwrite[u,(f+3-1)]:=trc[w];
techwrite[u,(f+3)]:=z1;
techwrite[u,2]:=comboset[als[a,4]];
techwrite[u,3]:=combosets[als[a,0],als[a,3]];
for b:= 1 to w do
begin
techwrite[u,(b*2)+2]:=techwrite[u,(b*2)+2] + comboset[als[als3[a,step[b]],4]];
techwrite[u,(b*2)+3]:=techwrite[u,(b*2)+3]+ combosets[als[als3[a,step[b]],0],als[als3[a,step[b]],3]];
end;
u:=u+1;
setlength(techwrite,u+1);
end;
end;
// temp removed type 2 for the time being to focus on missing eliminations in type 1}
//type 2 eliminates when there is not enough links then required as it locks the first set to empty if they are all false
if (popcnt(dword(TRC[w] )) > 1+ size ) and (w = 1 +size)
then
begin
if k = 1
then
begin
f:=((w+1)*2);
setlength(techwrite[u],0);
setlength(techwrite[u],((f+13)+1));
end;
a3:=[];
a3:= [0..80] - use2[w];
z1:=[];
for q:= w downto 1 do
for b:= w downto 1 do
if popcnt(dword(store[a,step[b]]-z1)) =1
then
Z1:=z1 + (store[a,step[b]]);
if popcnt(dword(TRC[w])) = 1+size
then
for b in RCD[w] - trc[w] do
for q in [0..80] do
if (peer[q] * (a3 * digitcell[b]) = (a3 * digitcell[b]) ) and (a3 * digitcell[b] <> [])
and (q in digitcell[b])
then
begin
Active:=true;
covered2[B]:=covered2[B] + [Q];
if k = 1
then
begin
techwrite[u,(b+F+3)]:=techwrite[u,(b+f+3)] + [q];
techwrite[u,(f+3)]:=techwrite[u,(f+3)] + [b];
end;
end;
if popcnt(dword(TRC[w])) >= 1+ size
then
for b in RCD[w] - z1 do
for q in [0..80] do
if( peer[q] * (a3 * digitcell[b]) = (a3 * digitcell[b]) ) and (a3 * digitcell[b] <> [])
and (q in digitcell[b])
then
begin
Active:=true;
covered2[B]:=covered2[B] + [Q];
if k = 1
then
begin
techwrite[u,(b+f+3)]:=techwrite[u,(b+f+3)] + [q];
techwrite[u,(f+3)]:=techwrite[u,(f+3)] + [b];
end;
end;
if (k=1) and (techwrite[u,(f+3)] <> [])
then
begin
techwrite[u,0]:=[3];
techwrite[u,1]:=[w];
techwrite[u,(f+3-1)]:=trc[w];
//techwrite[u,(f+3)]:=z1;
techwrite[u,2]:=comboset[als[a,4]];
techwrite[u,3]:=combosets[als[a,0],als[a,3]];
for b:= 1 to w do
begin
techwrite[u,(b*2)+2]:=techwrite[u,(b*2)+2] + comboset[als[als3[a,step[b]],4]];
techwrite[u,(b*2)+3]:=techwrite[u,(b*2)+3]+ combosets[als[als3[a,step[b]],0],als[als3[a,step[b]],3]];
end;
u:=u+1;
setlength(techwrite,u+1);
end;
end; //type 2
break;
end
else
h[w]:=h[w] -1;
if ((h[w] < 0) and (w >0)) or (w = size+1)
then
begin
dec(w); //set the array size to w
setlength(h,w+1);
setlength(use,(w+1));
setlength(use2,(w+1));
setlength(TRC,(w+1));
setlength(rcd,W+1);
setlength(usenum,w+1);
setlength(celluse,w+1);
end;
until (w = 0) and (h[w] < 0)
end;
chaindisplay(#22,u);
end; {n*a-ls n-RC }[/code][/hidden]
Some do, some teach, the rest look it up.