Home > Experiments, Uncategorized > A sudoku checking program in C :)

A sudoku checking program in C :)

It just started when my younger bro, Shafeeq who reads hacker news everyday, found a little interesting blog post. It was about the authors experience in applying for an internship at Google. The candidate was asked to write a program to check a completed sudoku during the telephone interview  for errors, in his favorite programming language. I asked bro, “Why don’t you give it a try?!”. He’s now in 11th standard and started coding in C++ which he learns in Computer Science subject.  He came up with the code in one day, and then it was my turn to do that 🙂 Here’s the way I solved the problem and it’s in pure C.

You can find the code here, in github. The input is given as a plain text file that contains 9×9 numbers separated by space. A sample input is given below:

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

And to check for errors, please call the program with the file as argument, like this –

$checksudoku <data_file>

Hope you enjoyed it, Please go through the code and feel free to post your valuable comments and suggestions here. Thank you 🙂

Advertisements
  1. Nitish
    April 10, 2011 at 1:08 pm

    which algorithm did you use?

    • April 10, 2011 at 2:07 pm

      The program doesn’t solve the sudoku, hence I didn’t use any known algorithm. The program first checks the horizontal rows for duplicate numbers, then the vertical rows and then the individual sub-matrices. Has anyone defined this procedure as an algorithm? Thank you for the comment 🙂

  2. Prabhu
    June 25, 2011 at 1:51 pm

    I like this program.I would like to share this program with my friends, will you please send this program to my email..

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: