Jump to content

Recommended Posts

Posted

Mai mult ca sigur ati jucat sau ati incercat sa jucati pana acum cel putin o data Sudoku. Cu toate acestea, daca va numarati printre cei care nu au facut-o, o simpla si rapida cautare pe Google va pune la dispozitie diverse aplicatii care de care mai complexe prin care puteti juca atat SinglePlayer cat si MultiPlayer acest joc.

Ei bine, pentru rezolvarea/castigarea cat mai rapida a jocului, un tip a creat o aplicatie foarte interesnta care va poate ajuta in acest sens:

function R
(
a, // the array representing the sudoko grid

// placeholder arguments
i, // index of the last empty cell
j, // index to check the candidates for the cell 'i'
m, // candidate number for the the cell 'i'
g // flag whether 'm' is a already used in the same row|col|node as 'i'
){
// phase 1: look for an empty cell
for
(
i=80;
a[i]; // keep going if the cell isn't empty
i--||+a // decrease the index and call 'a.toString()' if we went through the whole grid
);
// phase 2: check all candidate numbers for the cell 'i'
for
(
m=10;
g=a[i]=--m; // put the candidate in the cell 'i' already and set 'g' to something truthy
// at the end of phase 2, the cell 'i' is reset to 0 for "higher" branches of the recursion
g&&R(a) // recurse if 'm' isn't already used in the same row|col|node as 'i'
)
// phase 3: check if the candidate number is used already
for(j in a) // loop through the whole grid again
g*= // turn 'g' falsy if
a[j^i==j] // we are not on the cell 'i'
^m // and the cell 'j' is set to 'm'
|| // and we are in the same row|col|node as 'i'
i/9^j/9&&i%9^j%9&&i/27^j/27|i%9/3^j%9/3
}
[/code]

Dupa cum observati, codul sursa este scris in [b]JavaScript[/b], si este suficient de bine comentat pentru a fi inteles cu usurinta.

Mai multe detalii gasiti aici: :link:

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.