This function arranges a list of number. If we try z= [4, 4, 2 ] the result will be after some steps 4,3,2,1 but my list is z = [ 1, 1] and I want if a cycle of number coming up again and again the main program will discover it and print this is a cycle before it takes 25 steps.
My conditions are following:
if ordna(z)== z:
elif z==ordna(z)and ordna (z)==z:
see my code

def ordna(x):
    b = 0
    y = []
    for j in x:
        new_j = j-1
        if new_j<0:
            del new_j
        else:
            y.append(new_j)
            b+=1
    y.append (b)
    y.sort()
    y.reverse ()
    return y

z=[1,1]
if __name__ =="__main__":
   
    for k in range (0,25):
        if ordna(z)== z:
            print " Ok"
            break
        elif z==ordna(z)and ordna (z)==z:
            print 'plying round'
            break
        else:
            z=ordna(z)
        print " ".join (map(str,z))
    if z!=ordna(z) and k==24:
        print"Not OK"

Thanks for help and tips!

Recommended Answers

All 2 Replies

I don't get the purpose of ordna. What is it supposed to do?
To arrange a list could not entail adding members, I don't get it.

Ordna get a list of number and arrange them in this way, if mylist = [4, 4, 2] ordna arrange it like following;
Mylist =[4, 4, 2]

3 3 3 1
4 2 2 2 0
4 3 1 1 1
5 3 2 0 0 0
4 3 2 1
4 3 2 1 0
------------------
It is ok

If mylist = [1, 1]
Ordna arrange it in this way;

2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
1 1
2 0 0
------------------
Not OK

In this case when mylist = [1,1] the cycle of number coming up again and again and I want that the main program will discover it and stop it before it takes 25 steps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.