A problem in outputting a list [closed]

asked 2024-06-22 16:50:28 +0200

hamouda gravatar image

I want to output a list depending on two parameters $m$ and $t$, My attempt is

def L(m,t):
List=[]
dim=0
for k in srange(m+1):
    for j in srange(0,3):
        for i in srange(1,m-k+1):
            List.extend([(k,i,j)])
            dim=dim+1
for j in srange(floor(t)+1):
    for k in srange(floor(m/t)*j,m+1):
        for i in srange(0,1):
            List.extend([(k,i,j)]) # Indentation fixed here
            dim=dim+1
    return List

When we call len(L(3,1)) i.e.$m=3$ and $t=1$; sage outputs 22, this is not logical for me because I implemented again without using the function the length of the list (also for $m=3$ and $t=1$) becomes 23 as the following code

dim=0
List=[]
for k in srange(4):
    for j in srange(0,3):
        for i in srange(1,4-k):
            List.extend([(k,i,j)])
            dim=dim+1
for j in srange(2):
    for k in srange(3*j,4):
        for i in srange(0,1):
            List.extend([(k,i,j)]) 
            dim=dim+1

So where is the problem to solve it ?

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by John Palmieri
close date 2024-06-22 18:16:17.206104

Comments

I'm closing this as a duplicate of https://ask.sagemath.org/question/779...

John Palmieri gravatar imageJohn Palmieri ( 2024-06-22 18:16:12 +0200 )edit