solveSudoku              package:sudoku              R Documentation

_S_o_l_v_e _a _S_u_d_o_k_u _P_u_z_z_l_e

_D_e_s_c_r_i_p_t_i_o_n:

     Solves a Sudoku Puzzle.

_U_s_a_g_e:

       solveSudoku(z, verbose=FALSE, map=c(1:9,letters), level=0,
                   print.it=TRUE)

_A_r_g_u_m_e_n_t_s:

       z: A filename (passed to 'readSudoku'), or a numeric matrix.

 verbose: If TRUE, report on progress.

     map: Vector of unique puzzle elements (possibly longer than
          necessary).  The default is 'c(1:9, letters)', so an N=16
          puzzle should be encoded using '1'-'9' and 'a'-'g'.

   level: Recursion level (should not be set by user).

print.it: Logical: print the solution?

_D_e_t_a_i_l_s:

     A Sudoku puzzle consists of an NxN grid, where N is a perfect
     square (usually N=9).  The grid is subdivided into N [sqrt(N) x
     sqrt(N)] boxes.  You must fill in the missing values so that each
     row, each column, and each box contains the integers 1:N exactly
     once.

     The algorithm uses an NxNxN array of logicals, representing the
     NxN cells and the N possible elements.  For example, if
     a[1,2,3]=TRUE, then z[1,2] is known to be '3'.  If a[1,2,4]=FALSE,
     then z[1,2] is known not to be '4'.  The basic rules of Sudoku are
     used to fill in FALSE's, then elimination is used to find the
     TRUE's.  If that approach runs out of steam, a guess is made and
     the program recurses to find either a solution or an
     inconsistency.  No attempt is made to prove a solution's
     uniqueness.

_V_a_l_u_e:

     Invisibly returns the solved (numerical) matrix, and prints the
     character version.

_A_u_t_h_o_r(_s):

     David E. Brahm <brahm@alum.mit.edu>

_R_e_f_e_r_e_n_c_e_s:

     Example "puz1" comes from <URL: http://sudoku.com/>.

_E_x_a_m_p_l_e_s:

     ## Not run: 
       solveSudoku(system.file("puz1.txt",package="sudoku"), verbose=TRUE)
     ## End(Not run)

