| 
  | 
On 11/01/2025 09:23, jr wrote:
> 
> the board (above) doesn't tell me very much, how do you deal with the nine
> sub-squares ?  how do keep track of the values a given cell (still) can take ?
> (and many other such questions :-))
> 
Yes, I admit I didn't give much information.
On 10/01/2025 19:10, Bald Eagle wrote:
 > jr pointed out that if you use dictionaries, you won't get the
 > "too many nested...." error.
I don't see how dictionaries could help me at all.
Here's the macro code where I put a lot of comments.
'a' parameter containt the 9x9 array typically called by : Solve(board)
// ---------------------------------------------------------------------
// The recursive solve() procedure
// ---------------------------------------------------------------------
#macro Solve(a)
  /*
  // Counts the number of times the function calls itself.
  #declare solve_count = solve_count+1;
  #debug concat(" solve_count = ",str(solve_count,0,0),"\n")
  */
  // Set default value do false : sudoku not solved by default
  #local solve_value = false;
  // Find an empty cell (the first one)
  #local (Result,Row,Col) = find_empty(a);
  // find_empty say that there is no empty cell
  #if (!Result)
   // all cells are filled.
   // Sudoku is solved
   // Set solve_value to true.
   #local solve_value = true;
  #else
   // Yes, there is an empty cell at 'Row', 'Col'
   // Let's try to fill it.
   // For all digit from 1 to 9
   #for (num,1,SIZE)
    // If this candidate is good for this cell put it in this cell.
    // is_valid() check that 'num' is not on the line 'Row', not in the
    // column 'Col' an not in 3x3 square which contains (Row,Col).
    #if ( is_valid(a,num,Row,Col) )
     // Put 'num' in cell [Row][Col]
     #declare a[Row][Col] = num;
     // Tests if all cells are filled
     // ! RECURSION HERE !
     #if ( Solve(board) )
      // Yes! Soduku is solved.
      // Set the return value to true
      #local solve_value = true;
      // and exit this macros
      #break
     #end // #if ( solve(board) )
     // Reset candidate 'num' in this cell
     #declare a[Row][Col] = 0;
     // the 'num' candidate is wrong
    #end // #if ( is_valid(a,num,row,col) )
    // next digit candidate
   #end // #for (num,1,SIZE)
  // look if there is an other empty cell
  #end
  // Return state of solver
  solve_value
#end
// ---------------------------------------------------------------------
I've tried to remove the recursion, but so far without success.
Either I have an infinite loop, or the resolution is not complete.
regards
-- 
kurtz le pirate
compagnie de la banquise
 Post a reply to this message 
 | 
  |