length_3([], M, M). % length_3(L, M, N): the lenth of list L is N-M
length_3(L, M, N) :-
	  L = [_|L_prime]
	, M_prime is M + 1
	, length_3(L_prime, M_prime, N).
length_2(L, N) :- length_3(L, 0, N).

%permutation_2([], []).
%permutation_2([H|X], Y) :-
%	  permutation_2(X, Z)
%	, select(H, Y, Z).

permutation_3([], X, X).

permutation_3(X_1, X_2, X) :-
	  X_1 = [H_1|X_1prime]
	, select(H_1, X_2prime, X_2)
	, permutation_3(X_1prime, X_2prime, X).

permutation_2(L, Lp) :- permutation_3(L, [], Lp).