Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
% inversa.pl % Ejemplo de acumuladores: inversa de una lista. % José A. Alonso Jiménez <https://jaalonso.github.io> % Sevilla, 21-mayo-2022 % ============================================================================= % inversa(+L1,-L2) se verifica si L2 es la lista inversa de L1. Por ejemplo, % ?- inversa([a,b,c],L). % L = [c, b, a] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% § Definición básica %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% inversa_1([],[]). inversa_1([X|L1],L2):- inversa_1(L1,L3), append(L3,[X],L2). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% § Definición con acumuladores %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% inversa_2(L1,L2):- inversa_2_aux(L1,[],L2). inversa_2_aux([],L,L). inversa_2_aux([X|L1],L3,L2):- inversa_2_aux(L1,[X|L3],L2). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% § Sesión %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ?- numlist(1,1000,_L1), time(inversa_1(_L1,_)). % % 501,500 inferences, 0.030 CPU in 0.030 seconds (100% CPU, 16534294 Lips) % true. % % ?- numlist(1,1000,_L1), time(inversa_2(_L1,_)). % % 1,001 inferences, 0.000 CPU in 0.000 seconds (99% CPU, 4847528 Lips) % true.