[Community Puzzle] Sudoku Validator


Send your feedback or ask for help here!

Created by @redCroc,validated by @Deltaspace,@TBali and @lhm.
If you have any issues, feel free to ping them.

Hello , i got a problem. I validated everything but when i submit it gives me subgrid error. I don’t understand why. I give you my subgrid algo if c != 0 ERROR. Sorry for the complexity i just began in programming and i’m not now working on optimization. Is there a problem you see ?

for ( int k = 0 ; k < 9 ; k += 3){// subgrill x of the grill
        for ( int x = 0 ; x < 9; x += 3){// subgrill y of the grill
            int tab[9] = { 1,2,3,4,5,6,7,8,9};//tab with each number possible by grill
            for ( int i = 0 ; i < 3 ; i++){// x of the sub grill
                for ( int j = 0 ; j < 3 ; j++){// y of the surbgrill
                    for (int z =0 ; z < 9 ; z++){//take off the correspondent number of the tab
                        if ( sudoku[i][j] == tab[z]){ tab[z] = 0;}
            for (int m = 0 ; m < 9; m++){
                c += tab[m];//if there was a mising number took frome the tab c !=0
            if ( c != 0){break;}

@LouisGel Hint: You never use k and x

1 Like

Oh okay , the fact that the test sub-grid was working inducted me in error. Thank you very much !!

In the classic Sudoku you need to also have distinct numbers on the diagonals. It was a fun problem, though.

@Qoss No, adding the diagonal constraints is a variant sometimes referred to as X-Sudoku (or Sudoku X).

1 Like

Yes, you are right. I don’t know what I was thinking. Lol

You should add another test case.

A wrong way to validate a sudoku grid would be to assume that all lines & columns & subgrid would sum to 45 (I did just that as a “joke”). As this is true for a correctly filled sudoku grid, it will be also true… with a grid filled with only 5’s.

1 Like

Hello, I’m having an issue and I don’t know what to do.
I wrote a solution in Python3, all tests passed in IDE and when I submit it, it fails the “Column error” test and this message appears:

The following validators differ from the puzzle test cases to prevent hard coded solutions. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.

But my solution is not at all hardcoded. Since I’m not sure you can see my solution I’ll post it here:

numbers = set(range(1, 10))
sudoku = []
for i in range(9):
    row = list(map(int, input().split()))
    if numbers - set(row):
for i in range(9):
    col = {x[0] for x in sudoku}
    sub = {z for x in sudoku[(i//3)*3:(i//3)*3+3] for z in x[i*3%9:i*3%9+3]}
    if numbers - col | numbers - sub:

What makes it seem hardcoded? How can I improve my solution?

Props to @redCroc, I love sudoku :heart:
Thanks a lot :slight_smile:

The message is not accusing anyone of hardcoding. It is just attempting to answer a FAQ of “why I can pass the test cases but still fail the validator”. Perhaps it should not have mentioned hardcoding but to find better wording for explanation.

So you should not follow the “hardcoding” hint to trace the cause of failure. It is just that there is a bug in your code which was not triggered in the test case but was triggered in the hidden validator. This situation is very common to everyone. Just try your best to debug it, by reviewing, analysing the code, by using a debugger, by unit tests, by testing the code using extra inputs, etc.

1 Like

Hi Kariin,
You effectively made a mistake in your code, this error is unfortunately not caught by the IDE tests, but well caught by the validator tests.
I won’t tell you where you made a mistake exactly but I’m sure you can find it relatively easily.
Thanks for your message :wink:

1 Like

OMG!!! Ahahahha so embarrassing, here I was thinking I did something great and there was a ninja 0! Damn ninjas! Sorry for wasting your time :sweat_smile:

Does “ninja” mean bug in this context? Now I learned something new…

Don’t be embarassed, making mistakes and failing some validators is happening sometimes with all of us.

Nice small puzzle mister Croc.
Et bonsoir ! :grin: :fr:

What does subgrid error mean?

For example, if a subgrid (one of the nine 3×3 square) is not correct.

1 Like

Very hard for a nooby like me Haha.
I’ll see in few days if I pass it !

I failed testcase 4 even though not hardcoded I think?


Please don’t post complete code like this.
Validators are different from the tests to avoid hard-coded solution, but your code can fail to pass them even if it is not hard-coded, if it don’t handle a border-case not present in the IDE’s tests…

1 Like

Hi guys! I was trying to find someone who has more experience than me on this platform because I’m stuck with a python game (Sudoku Validator). To me it seems like I did nothing wrong, so if anyone can give me a tip, I would be glad to receive it.

i = 0
while i  <  len(myList)  - 1:  # for example: myList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
     if myList[ i ] == myList[ i + 1]:
            print("false")  # to validate, either "false" or "true"
            i += 1


This returns incorrect on “column error”, “subgrid error” and “rubbish error”, the others test cases are correct.