-
Notifications
You must be signed in to change notification settings - Fork 0
/
3x3.py
73 lines (57 loc) · 1.52 KB
/
3x3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 3x3 sudoku
import random
def duplicate_checker(a):
b = set(a)
result = len(a) != len(b)
#print(result)
if(result == True):
return True
def checkrow_horz(a):
for x in a:
if(duplicate_checker(x) == True):
return True
def checkrow_vert(a):
for y in range(len(a)):
temp = []
for x in a:
temp.append(x[y])
if(duplicate_checker(temp) == True):
return True
def display_grid(grid):
print("")
count =1
print(" 1 2 3")
for x in grid:
print(count,x,end=" ")
count+=1
print()
def scramble(grid):
for x in range(6):
y = random.randint(0,2)
x = random.randint(0,2)
grid[x][y] = 0
grid = [[1, 2, 3],[3, 1, 2] ,[2, 3, 1]]
solved = False
scramble(grid)
display_grid(grid)
while solved != True:
y = int(input("enter vertical [1,3] "))-1
x = int(input("enter horizontal [1,3]"))-1
num = int(input("enter number]"))
if grid[y][x] == 0:
grid[y][x] = num
else:
if input("overwrite? [y/n]") == "y":
grid[y][x] = num
display_grid(grid)
full = True
for x in grid:
for y in x:
if(y == 0):
full = False
if(full ==True):
if(checkrow_horz(grid)==True or checkrow_vert(grid) == True):
print("try again")
else:
print("solved")
solved =True