#NEWLINE# def solveSudoku( self , board ) : #NEWLINE# #INDENT# def isValid( board , x , y ) : #NEWLINE# #INDENT# for i in xrange ( 9 ) : #NEWLINE# #INDENT# if ( ( i != x ) and ( board [ i ] [ y ] == board [ x ] [ y ] ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# for j in xrange ( 9 ) : #NEWLINE# #INDENT# if ( ( j != y ) and ( board [ x ] [ j ] == board [ x ] [ y ] ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# i = ( 3 * ( x / 3 ) ) #NEWLINE# while ( i < ( 3 * ( ( x / 3 ) + 1 ) ) ) : #NEWLINE# #INDENT# j = ( 3 * ( y / 3 ) ) #NEWLINE# while ( j < ( 3 * ( ( y / 3 ) + 1 ) ) ) : #NEWLINE# #INDENT# if ( ( ( i != x ) or ( j != y ) ) and ( board [ i ] [ j ] == board [ x ] [ y ] ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# j += 1 #NEWLINE# #UNINDENT# i += 1 #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# def solver( board ) : #NEWLINE# #INDENT# for i in xrange ( len ( board ) ) : #NEWLINE# #INDENT# for j in xrange ( len ( board [ 0 ] ) ) : #NEWLINE# #INDENT# if ( board [ i ] [ j ] == '.' ) : #NEWLINE# #INDENT# for k in xrange ( 9 ) : #NEWLINE# #INDENT# board [ i ] [ j ] = chr ( ( ord ( '1' ) + k ) ) #NEWLINE# if ( isValid ( board , i , j ) and solver ( board ) ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# board [ i ] [ j ] = '.' #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return True #NEWLINE# #UNINDENT# solver ( board )