Jump to content
Sign in to follow this  

Rezolvare Sudoku Folosind O Aplicatie Javascript

Recommended Posts

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

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:

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...