Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

Very short code for naked and hidden subsets of any size

 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Setting sudoku
View previous topic :: View next topic  
Author Message
evert2

Joined: 30 Aug 2005
Posts: 6
:
Location: Amsterdam

Items
PostPosted: Thu Oct 09, 2008 9:29 pm    Post subject: Very short code for naked and hidden subsets of any size Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Setting sudoku All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron