Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giving Wrong Solution #3

Open
ThisMonkeysGoneToHeaven opened this issue Dec 23, 2019 · 4 comments
Open

Giving Wrong Solution #3

ThisMonkeysGoneToHeaven opened this issue Dec 23, 2019 · 4 comments

Comments

@ThisMonkeysGoneToHeaven

Hey Tim,
try this matrix for board in the solver (text) file. this is giving incorrect solution. you can verify correct answer if you wish from https://anysudokusolver.com/.

correct solution
image

board = [
[1, 0, 0, 0, 4, 0, 0, 0, 0],
[0, 9, 2, 6, 0, 0, 3, 0, 0],
[3, 0, 0, 0, 0, 5, 1, 0, 0],
[0, 7, 0, 1, 0, 0, 0, 0, 4],
[0, 0, 4, 0, 5, 0, 6, 0, 0],
[2, 0, 0, 0, 0, 4, 0, 8, 0],
[0, 0, 9, 4, 0, 0, 0, 0, 1],
[0, 0, 8, 0, 0, 6, 5, 2, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 6]
]

your code solution is :
image

@ayushdiagarwal
Copy link

Yep, got me the wrong answer too.

@Malcador360px
Copy link

#Check Col

for i in range(0, len(bo)):

    if bo[i][pos[1]] == num and pos[1] != i:
       return False

Here is this problem - it should be pos[0] != i instead of pos[1]

@AbeJ370
Copy link

AbeJ370 commented Feb 4, 2020

I'm getting (sorry to post entire thing):

IndexError Traceback (most recent call last)
in
96
97 pp = pprint.PrettyPrinter(width=41, compact=True)
---> 98 solve(board)
99 pp.pprint(board)

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
12 bo[row][col] = i
13
---> 14 if solve(bo):
15 return True
16

in solve(bo)
9
10 for i in range(1,10):
---> 11 if valid(bo, i, (row, col)):
12 bo[row][col] = i
13

in valid(bo, num, pos)
37 for i in range(box_y3, box_y3 + 3):
38 for j in range(box_x * 3, box_x*3 + 3):
---> 39 if bo[i][j] == num and (i,j) != pos:
40 return False
41

IndexError: list index out of range

@uripeled2
Copy link

current code:

#Check Col

for i in range(0, len(bo)):

if bo[i][pos[1]] == num and pos[1] != i:
   return False

should be:

#Check Col

for i in range(0, len(bo)):

if bo[i][pos[1]] == num and pos[0] != i:
   return False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants