It’s not enough to check uniqueness that way (which is also incorrect, btw). Read the statement and break it down in that same way, meaning, for instance, create different functions to check each sudoku property: 1. rows, 2. columns, 3. sub-grids, and combine them all together for a final decision.
Thanks for answering. I did create those functions and I tried combining them too. It works on other code editors but it doesn’t work on codingame.
“When summing is not enough”
summing is the only thing i do
Continuing the discussion from [Community Puzzle] Sudoku Validator:
Hello everyone, I can’t figure out the problem with the “sub-grid error” test. I pass all the other tests but this one subgrid test returns “true” instead of false. So I checked with my eyes these subgrids and they’re all valid, only unique numbers from 1 to 9, so it should return true. Can anyone help me figure this out?
Example of error: top-left sub-grid contains two 8s.
Thks for replying but no two 8s in the first subgrid:
[4, 3, 5], [2, 6, 9], [7, 8, 1]
[4, 3, 5], [2, 6, 9], [7, 8, 1] is the first row not the first subgrid.
The first subgrid is [4, 3, 5], [6, 8, 2], [8, 9, 7].
Ok the problem is settled. I hadn’t got the subgrids right. thank you.
Hi,
I’m failing the row and collumn sollutions during submittions and cant really find whats wrong, any hints? heres my logic to check rows and collumns:
for i in range(1,10):
# first checking
found = [False, False]
lastsum = 0
for x in range(9):
for y in range(9):
found[0] = True if grid[y][x] == i else found[0]
found[1] = True if grid[x][y] == i else found[1]
last_sum = sum(found)
#cascade of breaking if its not valid
if last_sum == 2:
break
if not last_sum == 2:
valid = False
break
if not last_sum == 2:
break
where valid is used for its check and starts on True
Try this case with your code:
1 5 2 4 8 9 3 7 6
2 4 6 8 9 5 7 1 3
3 8 7 9 2 4 6 5 5
4 6 8 3 7 1 2 9 5
5 9 2 8 6 3 4 1 1
6 2 5 9 4 8 1 3 7
7 3 9 2 5 6 8 4 1
8 7 3 5 1 2 9 6 4
9 1 4 6 3 7 5 8 2
It gives me false, which i believe is correct.
EDIT:
i rewrote it, and my new solution works fine.
EDIT 2:
@Remi, it returns false, which is correct, thats what i meant, theres also 2 5s in the last collumn
It’s not correct, the two “6” on the left are in the same 3x3 square.
OK sorry I didn’t understand ^^
Case 1-2 error but other all passed wth
Hi, I don’t understand why my code doesn’t work in the 5th test.
[Mod edit: Please avoid posting codes on the forum.]
con you help me?
In Test 5 (“Subgrid error”), the top left 3x3 box contains two 8s but no 1, and your code fails to detect that. The reason is that your code to extract the numbers from the boxes is wrong. Try print(element, file=sys.stderr, flush=True)
to see the value of element
.
A useful debugging technique is to print out the variables and see if their values are the same as what you expect.