I am analyzing the [routine](https://codesays.com/2014/solution-to-perm-check-by-codility/) which checks if an array of N integers is a permutation (sequence containing each element from 1 to N). 

 I am new to python. I can't grasp how this routine gets the correct answer. Could anybody explain the logic behind the loop? especially the use of the `counter[element-1]`.

 Is the counter a built-in function working on every element of A? does the `counter[element-1]` reference position/value of elements of A by default because the loop is defined on an array? 

```
A=[4,1,3,2]

    def solution(A):
        counter = [0]*len(A)
        limit = len(A)
        for element in A:
            if not 1 <= element <= limit:
                return 0
            else:
                if counter[element-1] != 0:
                    return 0
                else:
                    counter[element-1] = 1

        return 1

```

**Update:**
I modified the code to see the values used within the loop, for example

```
def solution(A):
    counter = [0]*len(A)
    limit = len(A)
    for element in A:
        if not 1 <= element <= limit:
            print element
            print 'outside'
            return 0
        else:
            if counter[element-1] != 0:
                print 'element %d' % element
                print [element-1]
                print counter[element-1]
                return 0
            else:
                counter[element-1] = 1
                print 'element %d' % element
                print [element-1]
                print counter[element-1]

    return 1

```

gives me

```
element 4
[3]
1
element 1
[0]
1
element 3
[2]
1
element 2
[1]
1
1

```

I still don't get the logic. For example fot the first element, why [3] gives 1?