Deutsch   English   Français   Italiano  
<67869565$0$16845$426a74cc@news.free.fr>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!cleanfeed3-a.proxad.net!nnrp6-1.free.fr!not-for-mail
Date: Tue, 14 Jan 2025 17:48:37 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: =?UTF-8?B?UmU6IFLDqWN1cnNpdml0w6k=?=
Content-Language: en-US
Newsgroups: fr.comp.lang.c
References: <vm0ncs$vus$1@rasp.pasdenom.info>
 <vm16hg$64d$1@cabale.usenet-fr.net> <vm258a$1l9pk$1@dont-email.me>
 <vm35fc$km3$1@rasp.pasdenom.info> <vm4agb$23g4e$2@dont-email.me>
From: kurtz le pirate <kurtzlepirate@free.fr>
Organization: compagnie de la banquise
In-Reply-To: <vm4agb$23g4e$2@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 92
Message-ID: <67869565$0$16845$426a74cc@news.free.fr>
NNTP-Posting-Date: 14 Jan 2025 17:48:37 CET
NNTP-Posting-Host: 88.123.184.107
X-Trace: 1736873317 news-1.free.fr 16845 88.123.184.107:3620
X-Complaints-To: abuse@proxad.net
Bytes: 3498

On 14/01/2025 01:18, beST wrote:
 >
 > Si elle te pose vraiment des problèmes, poste la, il y a bien un génie
 > du C qui va te donner la bonne formule.
 >

Oui, bien sûr, mais j'aurais bien voulu comprendre.

Mes différents essais aboutissent soit à une boucle infinie, soit à la 
"non" resolution.


Je ne sais plus ou j'ai trouvé cette fonction sur le Net.
C'est pour résoudre la résolution de Sudoku.

'a' passé en paramètre est un tableau 9x9, un grille de Sudoku


// ---------------------------------------------------------------------
// 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
// ---------------------------------------------------------------------






-- 
kurtz le pirate
compagnie de la banquise