I'm new in Prolog world. I want to find out if a permutation is 'one-cycle'.

I'm trying to write a predicate to generate cycle from permutation. Here is my code (not working):

```
find_next([E|_], [N|_], E, N).

find_next([_|L1], [_|L2], E, N) :-
  find_next(L1, L2, E, N).

find_cycle(L1, L2, E, C) :-
    append(C, [E], C1),
    find_next(L1, L2, E, N),
    find_cycle(L1, L2, N, C1).

```

Permutations are represented by two lists (for example: [1, 2, 3, 4], [3, 4, 2, 1]).
`find_next` generates next cycle element (N) for element (E) (for example: E=1, N=3).
`find_cycle` looks for cycle (C) starting from element E.

Unfortunately I don't know how to stop my recurrence when find\_next returns N same as first element of cycle C.

**EDIT:** some examples.

```
find_cycle([1, 2, 3, 4], [3, 4, 2, 1], 1, X).

```

should return:

```
X = [1, 3, 2, 4];
false.

```

and:

```
find_cycle([1, 2, 3, 4], [4, 2, 1, 3], 1, X).

```

should return:

```
X = [1, 4, 3];
false.

```

Why?
It is simple decomposition of permutation into disjointed cycles.
Let's analyze second permutation: `[1, 2, 3, 4], [4, 2, 1, 3]`.

```
Take first element: 1.
1 goes into 4
4 goes into 3
3 goes into 1
end of cycle.

```

This permutation is not decomposable into one cycle (length of generated cycle is smaller than length of permutation).