![]() #The delete key sets the number back to 0. #Whether the current coordinates are in the acceptable range. The coordinates are repositioned on the other edge of the sudoku matrix if a limit is reached. #Whether the x key (multiplication) is pressed. #Whether the left key on the dpad is pressed. #Whether the right key on the dpad is pressed. #Whether the up key on the dpad is pressed. #The next empty (equal to 0) cell is searched proceding in order from left to right, top to bottom. If no empty cells are found the whole sudoku is checked for validity. If the sudoku results to be valid then 1 is returned, therefore ending the solving process. Otherwise 0 is returned. #PyStack usage is a limitation of this program. Its limit cannot be increased by editing the parameters of the plot setup menu of the Python app. The following check halts the solving process if pystack_use() returns a value larger than 4039. It appears that running the python program embedded in a PPL program from the program library allows for a higher limit for PyStack. The value 4039 was determined by trial and error, and only achieves its goal when the python program is executed within a PPL program from the program library. If the program would not use recursion then PyStack usage limit would not be an issue. #The method solve is a recursive method which attempts to solve the sudoku. The arguments x and y are passed during each recursive calling of the method and indicate the current position of the solving process in the matrix. #Set variable d to 0. This is a flag to show the solving process as it happens. The process is slower if shown. #If no equal numbers were found return 1. #A cell of the row, the column and the square is checked as long as the dynamic coordinate(s) in each check are not equal to the ones feeded to the method. #The coordinates of each cell in a 3 by 3 square are not in sequence. The variable x2 is set to the top-left x coordinate plus i modulo 3 (ranging from 0 to 2). The variable y2 is set to the top-left y coordinate plus the integer result of i divided by 3 (ranging from 0 to 2). When a row of the 3 by 3 square ends, x2 is set back to the leftmost x coordinate in the square while y2 is incremented by 1. ![]() #The variable i is incremented by 1 9 times. #The top-left coordinates of the 3 by 3 square are computed and assigned to variables boxx and boxy. #If the cell is empty then 0 is returned. #The variable n is set to the value present in matrix at the given coordinates. #This method checks the validity of the number present at the given coordinates by searching for equal numbers in the same row, column and 3 by 3 square. If an equal number is found, or if the considered cell contains 0, then 0 (false) is returned otherwise 1 (true) is returned. #Set variable matrix to a 9 by 9 matrix filled with zeros representing empty cells. #Set the y coordinate in the sudoku matrix to 0.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |