def permutations(N):
    """Computes all the permutations of [0 ... n-1]"""

    def aux(elements):
        if len(elements) == 1:
            return [[elements.pop()]]

        perms = []

        for x in elements:
            for perm in aux(elements - {x}):
                perms.append([x] + perm)

        return perms

    return aux(set(range(N)))