Sudoku strategy - Cross Hatching

Cross-hatching is similar to squeezing but here, we will be using two or more solved numbers that are connected in different directions from our target box.

The graphic above shows an example of cross-hatching. The solved 7s from box G eliminate the possibility of 7 from column 2 while the solved 7 from block C eliminate the possibility of 7 from row 1. The only cell left in block A is R3C1 and hence must be 7.

Could you determine where the 7s are in blocks E and I using cross-hatching?

The single spotted using squeezing or cross hatching is also known as hidden single.

Sudoku strategy - Squeezing

Squeezing utilizes one or two solved numbers in connected boxes to locate the same number in the third connected box. Consider the band (3 horizontally connected boxes) shown above. The number 4 is already solved in the last two boxes. The green color highlights all the squares on which a 4 is not permissible. In the third connected block, only one unsolved square is not highlighted by green, and since that's the only square left, it must be a 4.

The graphic above shows an example of when one solved number is enough to obtain a squeezing solution.

Sudoku

Note: Sudoku terminologies are bolded.

The rule of Sudoku is simple: Fill in the empty cells in the grid so that each row, column and box contains the number 1 to 9.

Notation
We will refer to a particular cell in the grid using the notation R#C#. For instance, the cell in the third row and fourth column is denoted as R3C4.

The 9 boxes of 3x3 will be labeled with A-I in the following manner:

The most systematic way to solve Sudoku is to meticulously maintain a list of possible candidates for each cell. This process is usually tedious, error-prone and detracts the fun out of Sudoku. For a start, we will look at some of the simple strategies. *The list here will be updated from time to time:

1) Squeezing.
2) Cross-hatching

Matlab vs Java

The first thing I tried yesterday was to translate the Matlab function for verifying a Sudoku puzzle into Java. That was the first time I realized how easy it was to code in Matlab compared to Java.

As a comparison, let's look the codes. For matlab, to check for duplicate values , here's the code:
k = find(A(i,:) == j);

It's just a single line and I only need to check the length of k next to determine whether duplicate values exist or. For Java, I have write a loop to get the desired result.

int[] count = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int value = 0;
// check for duplicate values
for(int i = 0; i <>
value = cells[i];
count[value] += 1;
if(value != 0 && count[value] > 1) {
return true;
}

Conclusion: Matlab beats Java with a resounding victory. Of course, that only applies when it comes to ease of programming.

NetBeans vs Eclipse

So the GUI tutorial that I found uses NetBeans IDE instead of Eclipse. I installed Eclipse a few days earlier because well, it's popular. Although with hindsight, I probably should have done more research especially after running through Eclipse's not-up-to-date java tutorial. It's probably not a big deal if my wireless internet connection is not downloading stuff at 10 kilobytes/second, yeap that's about twice as fast as 56kbps dial-up connection. Unfortunately I'm forced to use the frequently disconnected wireless before my router arrives.

Anyway, after some Googling and exploring around, I found out that NetBeans is actually the better IDE for implementing GUI in java. I proceeded to download and installed it(which wasn't done until this morning because of the slow download speed). And yes, NetBeans GUI builder is so good I wish I have such a good builder when I was coding my MEng project. The drag and drop visual builder would have made my life easier and made my project looks prettier. I wasted so much time painstakingly aligning the various elements. Netbeans solved all that by having a grid that you can snap your elements to at a distance(from other elements) that makes it looks appealing.


Update: Here's how my Sudoku solver interface looks like in the Netbeans IDE(there are a few more buttons at the bottom but it's not shown). To the right is the palette containing all the elements that you can drag and drop to create your GUI. You can also switch back to the source code to see how each element is coded.

Bottomline: If you are a beginner at Java or are new to GUI, then NetBeans is definitely the preferred IDE.