EEP702
SOFTWARE LAB
ASSIGNMENT-1
SHASHANK KUSHWAH
2012EE50556
Assignment 1
Is it possible to transform an input 4 4 integer array to a solution of a 2 2
Sudoku*? If yes, then design an algorithm and implement it. Make sure that the
solution generated have the minimum variance with reference to the original
matrix.
Sol.
1. Analysis
For this problem, we need to first find out the input and output matrix
relationship so that the variance between the two matrices is minimum
from all the 2*2 Sudoku solution possible.
2. Approach
To find out the matrix which has minimum variance with respect to the
input matrices, we have to find out all the possible 2*2 Sudoku solutions
and then calculate the variances of all the output matrices with respect to
the input matrices. By this, we can easily get the minimum variance of the
matrix and can identify the solution of the given problem.
3. Coding
To find out all the possible 2*2 Sudoku matrices, we have to fill all the
blanks of the matrices with possible values by applying Sudoku checking
condition at each step.
1|Page
Figure shows the UML class diagram of the given java code
2|Page
Code description:
Class Sudoku
I.
II.
III.
IV.
matrixgen (): we initialise the output matrix by filling all the values
to zero. Also create a stack of arraylist which adds all the generated
matrix by the matrixgen () function.
V.
firstblank (): this searches the first blank in the matrix and returns
the coordinates of the blank position which is here zero. If all the
places are filled, then it returns object of some value which can be
used in another function.
VI.
Possible (): generates an array list and adds the possible values in
array which can be filled in the given coordinates of matrix by
checking Sudoku condition.
VII.
VIII.
IX.
Minimise( ): this uses the stack of matrices and finds out the
variance of each matrix and gives the minimum variance matrix
X.
Iterate( ): this uses the stack of arraylist of matrices and iterate over
one by one. First uses the function firstblank() to find out blank
space, then uses function possible() to find out all the possible
values which can be filled in that position. Then all possible values
3|Page
fig. shows the stack of matrices are created by filling possible values at each blank space
XI.
Class matrixPos
I.
matrixPos( ): this creates the constructor which is used to find out the
position of matrices.
Class MainClass
I.
main( ): main function creates object in the sudoku class, then calls
function create() to create input matrix. Then uses display() to display
input matrix. And finally uses matrixgen() to generate matrix with
minimum variance.
4|Page
Test cases:
Case-1
Case-2
5|Page