| evert2
| Joined: 30 Aug 2005 | Posts: 6 | : | Location: Amsterdam | Items |
|
Posted: Thu Oct 09, 2008 9:29 pm Post subject: Very short code for naked and hidden subsets of any size |
|
|
Code: | procedure TSudokuGrid.NakedHiddenSubsets(g: integer);
var subi, csubi, subcolors: TPossibilities;
var e, i: integer;
begin
for subi := 1 to 510 do
begin
{subi represents a subset of the cells in group g}
subcolors := 0;
for e := 1 to CountNum[subi] do
begin
i := Elts[subi,e];
subcolors := subcolors or Cells[Groups[g,i]];
end;{-for}
{now subcolors contains all colors possible in the subset}
if CountNum[subi] = CountNum[subcolors] then
begin
csubi := EmptyCell and not subi;
for e := 1 to CountNum[csubi] do
begin
i := Elts[csubi,e];
DoExclude(Groups[g,i],subcolors);
end;{-for}
end;{-if}
end;{-for}
end; |
Of course elsewhere I need novels of code to do the preparations like:
- filling array CountNum (number of elements in a set being represented by a bitmap)
- filling array Elts (the actual elements)
- filling array Groups (contains information about which groups (rows columns boxes and more ...?) contain which cells |
|