### Valid Sudoku

How to validate Sudoku board and check the input correctness programatically.

Navigation

Filter by Category

Filter by Author

General

How to validate Sudoku board and check the input correctness programatically.

Posted by Baraa Abuzaid

React Native

Fixing react native unable to launch android emulator error

Posted by Baraa Abuzaid

AWS

Creating a new user on EC2 instance and access it remotely via ssh.

Posted by Baraa Abuzaid

General

How to fix React native ./gradlew access error

Posted by Baraa Abuzaid

General

Implementing an algorithm for finding an identity matrix.

Posted by Baraa Abuzaid

Dart

Going through the fundamentals of stream api in dart programming language.

Posted by Baraa Abuzaid

Kotlin

Tutorial on how to implement the proxy design pattern with Kotlin

Posted by Baraa Abuzaid

Kotlin

Tutorial on composite design pattern with code example In Kotlin

Posted by Baraa Abuzaid

Android Core

Here we'll implement a draggable map with a fixed marker on top. that's only change when moving the map just like UBER.

Posted by Baraa Abuzaid

Kotlin

Get up and running with Kotlin in no time

Posted by Baraa Abuzaid

View Latest Posts

How to validate Sudoku board and check the input correctness programatically.

Baraa Abuzaid

@baraaabuzaid

Valid Sudoku

Posted by Baraa Abuzaid

So this article is about validating a fun logic game called sudoku.

Sudoku board is consists of 9×9 gird, which contains 3×3 subgrids.

The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids that form the main grid has no duplicate number.

The condition is to:

- Each row must contain the digits 1-9 without repetition.
- Each column must contain the digits 1-9 without repetition.
- Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.

So the sudoku validator(Valid Sudoku) we are about to build will validate against the above conditions. While ignores none filled cells.We’ll start with a lengthy solution that’s easier to reason about, then compose it down into a much more concise solution at the end.

If we have a 9×9 Sudoku board it can be represented programatically with nested arrays in which each array of the nested array represents a row in the board.

Let’s assume we’ve got the magical function isValidSubBox(), which would allow us to validate each of the nine 3×3 subgrids. Then all we have to do is to iterate through the board and call isValidSubbox().

Iterating on the board by making the loop outer and inner step size equal to the height and width of the 3×3 grid respectively. If any of the subgrids is not valid sudoku no need to continue, we return false.

Now let’s dig down and see what’s isValidSubBox() function is made of. The idea is to iterate over the subgrid column by column. If we encounter the same cell twice, that means it isn’t valid sudoku. Meanwhile, we ignore the empty cells indicated by dots and keep track of other cells using a hash map.

For this we can iterate over each row in Sudoku board array. checking against duplication with help of hash map.

And likewise we do the same steps, only this time we iterate the board column wise.

You can combine all of the above steps and **voilà**! now you have it. a Sudoku validator. Although, we can do all of the above steps into one nested iteration and make the code more concise, But for the seek of demonstration breaking it into multiple iterations will make the concept clear and easier to grasp.

If you are getting this error and you are pulling your hair off try to figure out what goes wrong! look no further here are few steps you can take to solve this issue. error...

Posted on by Baraa Abuzaid

Basically, the identity matrix is a matrix of zero elements except for the main diagonal elements is set to one. a more formal definition could be written as A matrix I ∈...

Posted on by Baraa Abuzaid