2021年1月28日星期四

Can someone help me with a recursive algorithm that generates a magic square in python please?

´I'm new to programming in python and I can't get this algorithm, please, someone to help me´ ´I have tried to perform with this code but it does not come out´

def cubomagico (matriz,fil,col,c,n):      if(c==n*n):          matriz[n-1][col]=c      else:          if(fil<0 and col==n):              cubomagico(matriz, fil+2,n-1, c, n)          else:              if(fil<0):                  cubomagico(matriz,n-1,col,c,n)              else:                  if(col==n):                      cubomagico(matriz,fil,0,c,n)                  else:                      if(matriz[fil][col]==0):                          matriz[fil][col]=c                          cubomagico(matriz, fil-1,col+1,c+1,n)                      else:                          cubomagico(matriz, fil+2,col-1,c,n)  
https://stackoverflow.com/questions/65948246/can-someone-help-me-with-a-recursive-algorithm-that-generates-a-magic-square-in January 29, 2021 at 11:06AM

没有评论:

发表评论