Good morning, You can't see the following line: If (sudoku(i, j) = 0) Or (sudoku(i, j) = "") Or (Len(sudoku(i, j)) > 1) Or (total_digits(sudoku) total.... Can you tell me the rest of the line? Thanks
Hi, could you help me with this? Programming step 1: Grid, Possible, and Stuck should be defined at the top of your module. Grid should be a variant type, Possible a 9 × 9 × 9 array of integers with each coordinate indexed from 1 to 9, and Stuck should be Boolean. The main macro will be called Solver. This will start by setting up the initial values of grid and possible, and then repeatedly call various subroutines which will carry out certain tests and update the two arrays. Programming step 2: Start the macro called Solver. First input the grid from cells A1:I9 using the Range.Value method and save in Grid. Testing: At each stage you should test your routine. For example, you could test you have read the starting grid by either using MsgBox, or you could save the current value of Grid to the location of the final solution (see Programming step 8). Next set up the array called Possible. Initially we will say that any value is possible in a cell if the cell is empty, and that if a cell is not empty then the only possible value is the value in that cell. Obviously this will need to be improved using the rules of Sudoku - which is what the rest of the programme will do. Programming step 3: To set up the array Possible use a pair of nested loops from 1 to 9 (labelled by i and j say). For each pair (i,j), if the entry in Grid(i,j) is 0 then use another loop to set Possible(i,j,k)=1 for all values of k. If the entry in Grid(i,j) is non-zero, then again use another loop to set the values of Possible(i,j,k), but this time set it equal to 1 if Grid(i,j)=k (i.e., k is the value in the cell (i,j)) and set it equal to 0 otherwise. At the end of this process we will have set up the initial values of grid and possible, and be ready to start working out new entries. As this stage you should set Stuck = False. We now want to repeatedly test our grid for possible new entries, and keep updating it. We will only stop when we can make no further changes. To do this we will use a Do While loop. Inside the loop we will set Stuck = True. We then carry out lots of tests described below. If any of them change either of our main arrays then they will also change the value of Stuck to False (as we can still do something). Only if every test fails will Stuck still be True by the end of the loop, at which point we will stop repeating. 3 Programming step 4: Next we will begin a Do While Stuck = False loop. The first line inside the loop should set Stuck = True. At the start of this loop we will check each cell in the grid, and if it is non-empty we will know that the value in that cell (n say) cannot occur anywhere else in that row, column or large square. For example, in the grid in Figure 1 we can see that Grid(2,2) = 4, and so 4 cannot occur anywhere else in row 2, column 2, or the rest of the top left large square. Thus we can set Possible(i,j,n) = 0 for all other pairs (i,j) in the same row, column or large square as the cell we are considering. Programming step 5: To do this we will use a pair of nested loops as before to run through all possible pairs (i,j). If Grid(i,j) is not equal to 0 then we call CleanRow(i,j) where CleanRow is a new subroutine which will remove the value of Grid(i,j) as a possibility elsewhere in row i. Then we will call CleanCol(i,j) which will do the same for the column j, and finally we will call CleanSquare(i,j) which will work out which large square we are in and then remove the value of Grid(i,j) as a possibility elsewhere in that square. The design of these subroutines is described later. Once we have finished looping through all the cells in the grid, we will have updated Possible so that no entry can occur in the same row, column, or large square twice. Now we need to work out whether we can deduce any new entries in our grid. We will do this in two ways, which will be sufficient to solve basic examples, but will not be powerful enough to solve all grids. The first way will be to look at each cell in the grid which is empty, and check how many possibilities are left for that cell. Obviously, if we have eliminated all but one possibility, then the cell must have that remaining value in it, and so we can put the value in the cell. For example, consider the cell in row 9 and column 8 in Figure 1. The only values still missing from the large square it is in are 3, 7, and 9. However 3 and 7 occur in the same row, and so the only possible value is 9. Thus we can deduce that Grid(9,8) = 9. If CleanRow (and CleanCol and CleanSquare) has worked correctly then Possible(9,8,9) = 1 but all other entries Possible(9,8,n) will be zero - something obvious to check to make sure you are on the right track. Programming step 6: Use a pair of nested loops to run through the grid. If Grid(i,j) is zero then call CheckUnique(i,j), a new subroutine which will check whether there is only one possible entry, and enter it if there is. The design of this subroutine will be described in more detail later. The second type of test we will do is a little different. Suppose that we have only three empty cells left in the same row of our grid, and that the first has only possible values being 1, 3, 7, the second only has possible values being 1, 7, and the third has only possible values being 1, 7. Then we know that 3 must occur in the first cell, as it has to occur somewhere in that row and there is nowhere else available. Programming step 7: Use a pair of nested loops to run through the grid. If Grid(i,j) is zero then call CheckRow(i,j), CheckCol(i,j) and CheckSquare(i,j), three new subroutines which will check whether one of the possible values for Grid(i,j) can only occur in that position in the row (or column, or large square). These are also described below. 4 Now that we have carried out all of our tests, we can finish our Do While loop. If nothing has changed, the programme will exit the loop, and should print out the final grid. Programming step 8: Close the Do While loop. Set the value of the cells A15:I23 to be equal to Grid. This completes the main programme. All that remains is to describe the various subroutines which are used inside Solver. Each of these will be a subroutine with two arguments: i as integer and j as integer. So, for example, the first line for the routine CleanRow must read Sub CleanRow(i as Integer, j as Integer) It is essential that you follow this instruction as failure to do so will result in your routines failing the tests when you are being marked. So stick to the names given and do not add or take away arguments. CleanRow: CleanRow will have two integer inputs, i and j say. It should consist of a loop from 1 to 9 (based on a variable k, say) which checks the value of Possible(i,k,Grid(i,j)) (if Grid(i,j) is non-zero). If this is 1 and k is not equal to j then this means that it is still thought to be possible for the value of Grid(i,j) to occur in position Grid(i,k). Clearly this cannot be the case, so set Possible(i,k,Grid(i,j)) = 0 and (as something has changed) set Stuck = False. CleanCol: CleanCol will have two integer inputs, i and j say. It does the same as CleanRow, but checks the column instead of the row. Thus k will have to be in the first coordinate not the second, and j will be used instead of i in the other coordinate. CleanSquare: CleanSquare will have two integer inputs, i and j say. It will do the same as CleanRow, but checks the large square instead of the row. This is a little more complicated, and this (and the similar CheckSquare routine) are probably the hardest parts of the project. We would like to repeat the method of CleanRow, but first we need to know which large square we are in. Define new variables HorOffset and VertOffset. Use an If or Select Case structure to set VertOffset = 0 if i ≤ 3, or 3 if i ≤ 6, or 6 otherwise, and similarly for HorOffset with j. Next use two nested loops (based on k and m say) each running from 1 to 3. The cells in the same large square as (i, j) are then indexed by values k + VertOffset and m + HorOffset. In your nested loops check if it is still thought to be possible for the entry in position (k + VertOffset, m + HorOffset) to be the same as the value in Grid(i,j), with k + VertOffset different from i or m + HorOffset different from j. If so then set Possible(k + VertOffset, m + HorOffset, Grid(i,j)) = 0 and change the value of Stuck to False. CheckUnique: CheckUnique will have two integer inputs, i and j say. Define a new variable called CheckSum which will be the sum of all of the entries in possible with first coordinate i and second coordinate j. (Use a loop to calculate this.) If the value of CheckSum is 1 then there is only one possible value for Grid(i,j). In this case use a loop to run through the entries in Possible of the form Possible(i,j,k). If the entry equals 1 for some value k, then set Grid(i,j) = k and Stuck = False. 5 CheckRow: CheckRow will have two integer inputs, i and j say. Use a loop to check whether Possible(i,j,k) = 1 for some k. If it does then use a loop to calculate the sum of all the values of Possible(i,m,k) as m varies. This sum equals the number of places in the given row where it is possible for k to occur. If this sum equals 1 then there is only one possible place, and we know that it is in position (i,j), so set Grid(i,j) = k, change the values of Possible for that cell to reflect this fact, and change Stuck to False. CheckCol: CheckCol will have two integer inputs, i and j say. This does the same as CheckRow but now m varies over the rows instead of the columns. CheckSquare: CheckSquare will have two integer inputs, i and j say. To write this modify CheckRow in the same way that we modified CleanRow to get CleanSquare. Thanks!
Link not working
Good morning,
You can't see the following line:
If (sudoku(i, j) = 0) Or (sudoku(i, j) = "") Or (Len(sudoku(i, j)) > 1) Or (total_digits(sudoku) total....
Can you tell me the rest of the line?
Thanks
why can't I download the file?
Thank you for making the file available, will definitely check out your other contents as well!
Has anyone downloaded successfully and achieved the solution presented in the video?
Does the program try every possible value for each cell?
Link not working
It has been removed
The site is closed
send the download file plss
How do I access the code??? The file wont download.
Hi, I can't download the files, and I really wanted to use it. I tried in my phone and computer, and both couldn't. How can you help me?
I can't download this file ???
can you send vb cood pleas???
I make subscribe to the channel, but it's doesn't download excel's file
You should be redirected to the file afterwards, or you can subscribe and then retry to download
Hi, could you help me with this?
Programming step 1: Grid, Possible, and Stuck should be defined at the top of your module. Grid should be a variant type, Possible a 9 × 9 × 9 array of integers with each coordinate indexed from 1 to 9, and Stuck should be Boolean. The main macro will be called Solver. This will start by setting up the initial values of grid and possible, and then repeatedly call various subroutines which will carry out certain tests and update the two arrays.
Programming step 2: Start the macro called Solver. First input the grid from cells A1:I9 using the Range.Value method and save in Grid. Testing: At each stage you should test your routine. For example, you could test you have read the starting grid by either using MsgBox, or you could save the current value of Grid to the location of the final solution (see Programming step 8). Next set up the array called Possible. Initially we will say that any value is possible in a cell if the cell is empty, and that if a cell is not empty then the only possible value is the value in that cell. Obviously this will need to be improved using the rules of Sudoku - which is what the rest of the programme will do.
Programming step 3: To set up the array Possible use a pair of nested loops from 1 to 9 (labelled by i and j say). For each pair (i,j), if the entry in Grid(i,j) is 0 then use another loop to set Possible(i,j,k)=1 for all values of k. If the entry in Grid(i,j) is non-zero, then again use another loop to set the values of Possible(i,j,k), but this time set it equal to 1 if Grid(i,j)=k (i.e., k is the value in the cell (i,j)) and set it equal to 0 otherwise. At the end of this process we will have set up the initial values of grid and possible, and be ready to start working out new entries. As this stage you should set Stuck = False. We now want to repeatedly test our grid for possible new entries, and keep updating it. We will only stop when we can make no further changes. To do this we will use a Do While loop. Inside the loop we will set Stuck = True. We then carry out lots of tests described below. If any of them change either of our main arrays then they will also change the value of Stuck to False (as we can still do something). Only if every test fails will Stuck still be True by the end of the loop, at which point we will stop repeating. 3
Programming step 4: Next we will begin a Do While Stuck = False loop. The first line inside the loop should set Stuck = True. At the start of this loop we will check each cell in the grid, and if it is non-empty we will know that the value in that cell (n say) cannot occur anywhere else in that row, column or large square. For example, in the grid in Figure 1 we can see that Grid(2,2) = 4, and so 4 cannot occur anywhere else in row 2, column 2, or the rest of the top left large square. Thus we can set Possible(i,j,n) = 0 for all other pairs (i,j) in the same row, column or large square as the cell we are considering.
Programming step 5: To do this we will use a pair of nested loops as before to run through all possible pairs (i,j). If Grid(i,j) is not equal to 0 then we call CleanRow(i,j) where CleanRow is a new subroutine which will remove the value of Grid(i,j) as a possibility elsewhere in row i. Then we will call CleanCol(i,j) which will do the same for the column j, and finally we will call CleanSquare(i,j) which will work out which large square we are in and then remove the value of Grid(i,j) as a possibility elsewhere in that square. The design of these subroutines is described later. Once we have finished looping through all the cells in the grid, we will have updated Possible so that no entry can occur in the same row, column, or large square twice. Now we need to work out whether we can deduce any new entries in our grid. We will do this in two ways, which will be sufficient to solve basic examples, but will not be powerful enough to solve all grids. The first way will be to look at each cell in the grid which is empty, and check how many possibilities are left for that cell. Obviously, if we have eliminated all but one possibility, then the cell must have that remaining value in it, and so we can put the value in the cell. For example, consider the cell in row 9 and column 8 in Figure 1. The only values still missing from the large square it is in are 3, 7, and 9. However 3 and 7 occur in the same row, and so the only possible value is 9. Thus we can deduce that Grid(9,8) = 9. If CleanRow (and CleanCol and CleanSquare) has worked correctly then Possible(9,8,9) = 1 but all other entries Possible(9,8,n) will be zero - something obvious to check to make sure you are on the right track.
Programming step 6: Use a pair of nested loops to run through the grid. If Grid(i,j) is zero then call CheckUnique(i,j), a new subroutine which will check whether there is only one possible entry, and enter it if there is. The design of this subroutine will be described in more detail later. The second type of test we will do is a little different. Suppose that we have only three empty cells left in the same row of our grid, and that the first has only possible values being 1, 3, 7, the second only has possible values being 1, 7, and the third has only possible values being 1, 7. Then we know that 3 must occur in the first cell, as it has to occur somewhere in that row and there is nowhere else available.
Programming step 7: Use a pair of nested loops to run through the grid. If Grid(i,j) is zero then call CheckRow(i,j), CheckCol(i,j) and CheckSquare(i,j), three new subroutines which will check whether one of the possible values for Grid(i,j) can only occur in that position in the row (or column, or large square). These are also described below. 4 Now that we have carried out all of our tests, we can finish our Do While loop. If nothing has changed, the programme will exit the loop, and should print out the final grid.
Programming step 8: Close the Do While loop. Set the value of the cells A15:I23 to be equal to Grid. This completes the main programme. All that remains is to describe the various subroutines which are used inside Solver. Each of these will be a subroutine with two arguments: i as integer and j as integer. So, for example, the first line for the routine CleanRow must read Sub CleanRow(i as Integer, j as Integer) It is essential that you follow this instruction as failure to do so will result in your routines failing the tests when you are being marked. So stick to the names given and do not add or take away arguments.
CleanRow: CleanRow will have two integer inputs, i and j say. It should consist of a loop from 1 to 9 (based on a variable k, say) which checks the value of Possible(i,k,Grid(i,j)) (if Grid(i,j) is non-zero). If this is 1 and k is not equal to j then this means that it is still thought to be possible for the value of Grid(i,j) to occur in position Grid(i,k). Clearly this cannot be the case, so set Possible(i,k,Grid(i,j)) = 0 and (as something has changed) set Stuck = False.
CleanCol: CleanCol will have two integer inputs, i and j say. It does the same as CleanRow, but checks the column instead of the row. Thus k will have to be in the first coordinate not the second, and j will be used instead of i in the other coordinate.
CleanSquare: CleanSquare will have two integer inputs, i and j say. It will do the same as CleanRow, but checks the large square instead of the row. This is a little more complicated, and this (and the similar CheckSquare routine) are probably the hardest parts of the project. We would like to repeat the method of CleanRow, but first we need to know which large square we are in. Define new variables HorOffset and VertOffset. Use an If or Select Case structure to set VertOffset = 0 if i ≤ 3, or 3 if i ≤ 6, or 6 otherwise, and similarly for HorOffset with j. Next use two nested loops (based on k and m say) each running from 1 to 3. The cells in the same large square as (i, j) are then indexed by values k + VertOffset and m + HorOffset. In your nested loops check if it is still thought to be possible for the entry in position (k + VertOffset, m + HorOffset) to be the same as the value in Grid(i,j), with k + VertOffset different from i or m + HorOffset different from j. If so then set Possible(k + VertOffset, m + HorOffset, Grid(i,j)) = 0 and change the value of Stuck to False.
CheckUnique: CheckUnique will have two integer inputs, i and j say. Define a new variable called CheckSum which will be the sum of all of the entries in possible with first coordinate i and second coordinate j. (Use a loop to calculate this.) If the value of CheckSum is 1 then there is only one possible value for Grid(i,j). In this case use a loop to run through the entries in Possible of the form Possible(i,j,k). If the entry equals 1 for some value k, then set Grid(i,j) = k and Stuck = False. 5
CheckRow: CheckRow will have two integer inputs, i and j say. Use a loop to check whether Possible(i,j,k) = 1 for some k. If it does then use a loop to calculate the sum of all the values of Possible(i,m,k) as m varies. This sum equals the number of places in the given row where it is possible for k to occur. If this sum equals 1 then there is only one possible place, and we know that it is in position (i,j), so set Grid(i,j) = k, change the values of Possible for that cell to reflect this fact, and change Stuck to False.
CheckCol: CheckCol will have two integer inputs, i and j say. This does the same as CheckRow but now m varies over the rows instead of the columns. CheckSquare: CheckSquare will have two integer inputs, i and j say. To write this modify CheckRow in the same way that we modified CleanRow to get CleanSquare.
Thanks!
Go away
why I can't download this file ???
I can't download this file ???
i cannot download the file