Jump to content

[Python] Script que resolve Sudokus


Recommended Posts

Foi feito para uma aula ... Uso de função recursiva


def doit():
    if i==-1:return 1
    for n in range(1,10):
        if linok(i,j,n) and colok(i,j,n) and quadok(i,j,n):
            if doit():return 1
    return 0

def linok(i,p,n):
    for j in range(9):
        if m[i][j]==n:return 0
    return 1

def colok(p,j,n):
    for i in range(9):
        if m[i][j]==n: return 0
    return 1

def quadok(i,j,n):
    for x in range(li,li+3):
        for y in range(lj,lj+3):
            if m[x][y]==n: return 0
    return 1

def pz():
    for i in range(9):
        for j in range(9):
            if m[i][j]==0:return i,j
    return -1,0

for p in m: print p
for p in m: print p

Acho que dá para todas as "grelhas" ...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.