A friend of mine came up with this while bored in class; I made it into a little VB .NET app. The goal is to drop the numbers 1-9 onto a 9x9 grid without repeating the same number in any row or column. I'm betting there is an easy pattern, but I just wrote the thing- I'm not good at it. Let me know what you think.

Note: This will install the .NET Compact Framework if you don't have it, which could take awhile.

Here it is:
http://www.millertechnologyconsulting.com/81/EightyOne_1_0_0_2.zip

Recommended Answers

All 22 Replies

You already posted that

Mia Culpa- poor form.

Duh - this is a joke, right? I didn't download the app - it's too easy.

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8

I should have mentioned that the first nine numbers are placed randomly...

This is called "sudoku", and is already a popular form of puzzle.

Cool problem. We should see who can come up with the best programmatical solution ;)

As I mentioned... this is a well-known and very popular puzzle form, called "sudoku". There are several generalized solving techniques. A simple web-search on the term will generate all the information you're likely to need on the topic.

I dig. Still, it's rewarding to pull a good idea from the aether, even if only to find out that it's been popular and remained difficult to solve, no?

Ummm, ok, maybe I'm just missing the boat here...

Even if the numbers are placed radomly, wont the numbers still be the same in each column like I listed above??? Just move the columns around, right?

Ok, I think I see what u r saying now. The pattern I listed only works if the numbers are placed randomly within the grid, AND there is only one number in each row and column.

Exactly. And yet, I asill suspect that there is a intuitive way to complete the grid regardless of the initial state. Sadly, I was never good with a Rubick's Cube- Matricies are not my strong point.

Indeed. Brute force is cheating, though... ;)

I figured it couldn't be as easy as I was making it, cuz I'm not really that smart, so yeah... I see the difficulty, now. Thanks for clarifying!

Cheers. Let me know if you find a general solution- I can't solve my own puzzle!

There is an old Chinese tale, that one day, the King's daughter was kidnapped. The King sent out his soldiers, and promised any reward to whoever rescued her. All the soldiers couldn't find her, but one day a peseant boy appeared before the King with his rescued daughter. The King was very happy, so offered the peasant boy any reward. The boy, after some thinking, saw a Chess board which gave him an idea.

The boy requested that a single grain of rice be put on the first square of the Chess board, two on the next, four on the one after, then eight...... so he could have plenty of rice for his family

The King thought that was not much to ask, so he agreed, and set people off to collect the rice as requested. The problem was, that he had agreed to give the boy 18400,000,000,000,000,000 grains of rice, which of course, meant all the rice in the land still wasn't enough...

The moral of this story - Do the Math

Here is the solution to the GIF posted before.

4 8 1 5 6 7 3 9 2
1 6 3 2 7 8 4 5 9
8 5 6 1 2 9 7 4 3
9 4 5 8 1 3 2 7 6
3 7 4 9 8 6 1 2 5
2 3 9 7 4 1 5 6 8
7 9 8 4 5 2 6 3 1
5 1 2 6 3 4 9 8 7
6 2 7 3 9 5 8 1 4

This solution was formed by performing row and column swapping operations until each number possessed its own 2:30 - 7:30 diagonal. (There are nine diagonals; they wrap around.) Then these numbers can be slid up and down their diagonals to fill the whole matrix with numbers. This produced a matrix of

5 1 6 2 3 7 9 4 8
1 6 2 3 7 9 4 8 5
6 2 3 7 9 4 8 5 1
2 3 7 9 4 8 5 1 6
3 7 9 4 8 5 1 6 2
7 9 4 8 5 1 6 2 3
9 4 8 5 1 6 2 3 7
4 8 5 1 6 2 3 7 9
8 5 1 6 2 3 7 9 4

Then I performed the same row and column swapping operations, in reverse order, to bring the nine digits to their original positions, giving the solution matrix.

The algorithm is simple once you maneuver every number to its own diagonal. But maneuvering numbers to diagonals is the tricky part. I think it can be done given any input, but I'm not sure what a general algorithm would be. Not many swaps are needed. I used seven in the above problem.

The rules of "Sudoku": Each row must have the digits 1-9, no repetitions. Each column must have the digits 1-9, no repetitions. The grid is further divided into 9 3x3 cells. Each cell must have the digits 1-9, no repetitions.

With the "easy" puzzles, each cell can easily be determined by exclusion: it can't be any digit already in the cell, row, or column. There are various levels of difficulty, however. On the most difficult puzzles, you have to form networks of true/false pairs, and steadily exclude any candidates that don't fit in the "network".

I actually had never heard of Sudoku puzzles before coding the 81 game. The 'Cheat' code uses just what you cited: no same rows/columns allowed. I am loathe to attempt a more complex Sudoku puzzle, but having seen the challenge I think I will be a very busy individual indeed.

Su-Doku is different from this, or the solutions Rashakil prescribed certainly. Not only does each row and column require to contain the number 1-9 (no repetition), but there are nine boxes of 3x3 across the square that also have to contain the numbers 1-9 (no repetition obviously).

http://www.sudoku.com/

Duh - this is a joke, right? I didn't download the app - it's too easy.

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8

Hi friend u r looking good in SUDOKU.Then plz try to solve my problem...
Here it is..

http://www.daniweb.com/techtalkforums/showthread.php?t=48788&highlight=sudoku

hmm the setup doesnt seem to be working as it has trouble downloading the third compenent. From the looks of the screenshot though, it is looking good. Well done. And why does it matter that it has already been done.. just think of the number of tetris clones.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.