[ create a new paste ] login | about

Link: http://codepad.org/8QOxXdEu    [ raw code | output | fork ]

Python, pasted on Nov 23:
1
2
3
4
5
6
7
8
9
10
11
S = [5,4,0,3,1,2,6]
items = set()
index = 0
while True:
    a = S[index]
    if index not in items:
        items.add(index)
        index = a
    else:
        print(len(items))
        break


Output:
1
3


Create a new paste based on this one


Comments: