Checking if you are Sudoku

I posted it earlier, but it is possible that the link did not meet the terms, so I deleted it and reposted. I also tried to correct the pointed out point. Last time, I realized it by using three while statements, but I changed it to a for statement. I have received advice on using .numpy, so I would like to understand that and take on the challenge.

target1 = [[1,2,3],
           [2,3,1],
           [3,1,2]]
target2 = [[1,1,1],
           [2,2,2],
           [3,3,3]]
target3 = [[1,2,3],
           [2,3,1],
           [1,3,2]]
target4 = [[1,2,3,4,5],
           [2,3,4,5,1],
           [3,4,5,1,2],
           [4,5,1,2,3],
           [5,1,2,3,4]]
           
def check(target):
    n = len(target)
    digit = 1
    for i in range(0, n):  #The number of elements is 3, which is 0 to 3, that is, 0.,1,2
        row_count = 0
        col_count = 0
        for j in range(0, n):
            if target[i][j] == digit:
                row_count += 1
            if target[j][i] == digit:
                col_count += 1
        if row_count != 1 or col_count != 1:
            return False
        digit += 1
    return True
def test():
    print('For Sudoku form')
    assert check(target1) == True
    print('If the contents of the list are all the same number')
    assert check(target2) == False
    print('If only the last list does not meet the criteria')
    assert check(target3) == False
    print('Normal system in the case of 5 × 5')
    assert check(target4) == True
    print('test ok')
test()

Recommended Posts

Checking if you are Sudoku
Where are you from
If you cd, ls. Shiroyo ……
What to do if you are addicted to Windows character code
If you say TemplateDoesNotExist at
[Papers and Implementation] If you are asked "Is this dataset difficult?" ...
pathlib Are you all using it?
Are you having trouble with "pipenv.exceptions.ResolutionFailure"?
Ask you guys! Are you a programmer! !!
If you ride the Titanic ... die.
If you are told cannot by Python import, review the file name