Monday 1 August 2016

28 LINE CODE TO CREATE SUDOKU 6 X 6 in python



 28 LINE CODE TO CREATE SUDOKU 6 X 6

I will call this method as a fake method or wrong method because this code is generated using a wrong way,but it will give you the output.you should have a good chance optimize this code,because it's generated without optimization.i generated this code mainly for the beginners ,i just meant to help them.
so here is the code,just paste it and then run.

CODE


list1=[];list2=[];list3=[];list4=[];list5=[];list6=[];//initialisation of lists
f=1400
import random //include library random
r=random.randrange(1,7,1)  //generate random no b/w 1 and 7
while  f>=0 :
  if r in list1 :
    r=random.randrange(1,7,1)
    f-=1
  else :
    list1.append(r)//append  variable r to list1
    f-=1
    

var1=list1[0];var2=list1[1];var3=list1[2];var4=list1[3];var5=list1[4];var6=list1[5]

list2.append(var6);list2.append(var4);list2.append(var5);list2.append(var3);list2.append(var1);list2.append(var2)//create list 2

list3.append(var5);list3.append(var6);list3.append(var4);list3.append(var2);list3.append(var3);list3.append(var1)//create list 3

list4=list2[:];// create list4  
list6=list1[:] //create list 6

list5.append(var2);list5.append(var3);list5.append(var1);list5.append(var5);list5.append(var6);list5.append(var4)//create list 5

print list1[0:3],"\t",list4[0:3]
print list1[3:6],"\t",list4[3:6]
print"\n"
print list2[0:3],"\t",list5[0:3]
print list2[3:6],"\t",list5[3:6]
print"\n"
print list3[0:3],"\t",list6[0:3]
print list3[3:6],"\t",list6[3:6]
print"\n"

SOME TIPS
//there is no need to create list4 and list6 there are just copies of list1 and list2

IDEA

The basic idea behind this is create a list (here it's list1) and make arrangement on all other lists based on it.when a change is made on  list1 all others get changed accordingly.

this code is generated from the Sudoku given below

5  2  3      6 1 4
1  4  6        3 5 2 


                                         6 1 4          2 3 5
                                          3 5 2          4 6 1

                                          4 6 1          5 2 3
                                           2 3 5          1 4 6

#for any queries comment below



#HAPPY CODING


  

No comments:

Post a Comment

How to Invert an SVG image using CSS ?

You can invert your svg easily by using following css code svg { -webkit-filter: invert(100%); /* safari 6.0 - 9.0 */ filter...