append([], X, [X]). append([H|L], X, [H | L1]) :- append(L, X, L1). reverse([], []). reverse([H|L], R) :- reverse(L, L1), append(L1, H, R). insertitem(X, [], [X]). insertitem(X, [H|L], [X, H | L]) :- X =< H. insertitem(X, [H|L], [H |R]) :- X>H, insertitem(X, L, R). distance1([],[], 0). distance1([H1|L1], [H2|L2], X):- Y is (H1-H2)*(H1-H2), distance1(L1, L2, Z), X is Y+Z. distance(V1, V2, D):- distance1(V1, V2, D1), D is sqrt(D1).