Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

matrix - Hi, I'm new to programming, how do I execute this code?

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)
question from:https://stackoverflow.com/questions/65946147/hi-im-new-to-programming-how-do-i-execute-this-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've slightly modifed your program.

Now, to run this program, there are steps outlined here or here .

#!/usr/bin/python3

def cubomagico(matriz,fil,col,c,n):
    if (c==n*n):
        matriz[n-1][col]=c
    elif (fil<0 and col==n):
        cubomagico(matriz, fil+2,n-1, c, n)
    elif (fil<0):
        cubomagico(matriz,n-1,col,c,n)
    elif (col==n):
        cubomagico(matriz,fil,0,c,n)
    elif (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)

C,N=4,4
M=[[0]*C for i in range(0,N)]

cubomagico(M,1,1,C,N)

print(M)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...