Archive

Posts Tagged ‘sudoku’

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 🙂