Anda di halaman 1dari 6

JANUARY 27, 2016

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

UML CLASS DIAGRAM

Figure shows the UML class diagram of the given java code

In the UML diagram, there is an arrow between Sudoku and matrixPos


class represents a relationship between the dependency of each other with
both cardinality 1 to 1.

2|Page

Code description:
Class Sudoku

I.

Create (): Input matrix data is fetched from the user.

II.

Display (): Displaying the input matrices.

III.

CheckSudokucondition (): it checks the similar number filled in the


same row and column and in the box.

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.

Append( ): it puts the value in the coordinates of a given matrix and


updates it.

VIII.

Variance( ): This will calculate the variance between the input


matrices and the generated matrix .

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

are used by the function append() to generate matrices. By iterating


over the stack, this will create the matrices in the stack. When all
the positions in the matrices are filled then the loop will go to the
function minimise() in the stack which will find out the minimum
variance corresponding to the matrix.

fig. shows the stack of matrices are created by filling possible values at each blank space

XI.

dispOut( ): this function displays the matrix output.

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

Anda mungkin juga menyukai