Write a python program that generates a sudoku puzzle.1. Enter n (which is the size of the sudoku puzzle #2. Keep generating random permutations of n using python built in function until you find permutation that can be incorporated as a new component of the sudoku grid.
format for puzzle should be output 1 2 3
3 1 2
2 3 1
import random
x = int(input())
e,f = x,x
def RandomList(st,ed,nom):
tp = []
temp = random.randint(st, ed)
for x in range(nom):
while temp in tp:
temp = random.randint(st, ed)
tp.append(temp)
return tp
lis = RandomList(1,x,x)
sudoku = []
for i in range(len(lis)):
sudoku.append(lis[i:] + lis[:i])
for s in range(x):
for d in range(0,e,f):
for si in range(s,e,f):
for li in range(d,d+f):
print(sudoku[si][li],end = ' ')
print()
Get Answers For Free
Most questions answered within 1 hours.