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.
i got an issue , i tried creating a list that contain another list to check the columns :
[Mod edit: Avoid posting your code on the forum]
in the end my list " big_list " is just empty because the “register_list.clear()” clears even the ones inside my list(i know my code isnt working for 3x3 yet but i want to clear the columns before.)
It seems that your issue with the big_list being empty or not behaving as expected stems from how Python handles references to mutable objects like lists.
When you try to append register_list to big_list, you’re appending a reference to register_list into big_list, not a copy of it. So when you later call register_list.clear(), you’re also clearing the list inside big_list, because they both point to the same object in memory.
One solution is to make sure you append a cloned list.
very fun puzzle!
The “When summing is not enough” test case cought me offguard
. So I said to my self, will multiplication be enough? So I qickly changed += to *= and to my surpice, it passed all the tests.
However I knew this was wrong, and tought to my self OK, what if track both the product and the sum. This has to be good enogut? Right? No! It is not.
I present to you, a sudoku grid, that has the same sum and the same product for each row, column and subgrid as a valid sudoku grid.
Please consider adding this to the test cases, to stop those lazy people like me, who pass tests with wrong solutions to real world problems!
4 9 5 4 2 9 7 4 1
2 4 4 5 7 1 4 9 9
1 9 7 4 9 4 5 2 4
4 4 2 1 9 5 9 4 7
9 7 4 2 4 4 9 1 5
9 5 1 7 4 9 2 4 4
5 1 9 9 4 2 4 7 4
4 4 4 9 5 7 1 9 2
7 2 9 4 1 4 4 5 9
Thank you