% PD 2008-09: practica_9.pl (13 de Enero de 2009)
% Departamento de Ciencias de la Computación e I.A.
% Universidad de Sevilla 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 1. Definir la relación máximo(X,Y,Z) que se verifique si Z es
% el máximo de los números X e Y. Por ejemplo, 
%    ?- maximo(3,5,Z).
%    Z=5
%    ?- maximo(2,3,X). 
%    X = 3
%    ?- maximo(3,2,X). 
%    X = 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2. (Algoritmo de Euclides) Dados dos enteros positivos X e Y,
% el máximo común divisor (mcd) D puede obtenerse de la siguiente
% manera: 
%  * Si X e Y son iguales, entonces D es igual a X
%  * Si X<Y, entonces D es igual al máximo común divisor de X y la
%    diferencia Y-X. 
%  * Si Y<X entonces hacemos lo mismo que en caso anterior con X e Y
%    intercambiados. 
% Definir la relación mcd(X,Y,D) que calcule el mcd D de los enteros
% positivos X e Y. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 3. Definir la relación longitud(L,N) que se verifique si N es
% la longitud de la lista L. Por ejemplo, 
%    ?- longitud([],N).
%    N = 0 
%    ?- longitud([a,b,c],N).
%    N = 3 
%    ?- longitud([a,[b,c]],N).
%    N = 2
% Nota: La relación predefinida correspondiente a longitud es length.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 4. Definir la relación maximo_lista(L,N) que se verifique si
% N es el máximo de los elementos de la lista de números L. Por ejemplo,
%    ?- maximo_lista([1,3,9,5],N). 
%    N = 9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 5. Definir la relación entre(N1,N2,X) que se verifique si X
% es mayor o igual que N1 y menor o igual que N2. Por ejemplo,
%    ?- entre(2,5,X). 
%    X = 2 ; 
%    X = 3 ; 
%    X = 4 ;  
%    X = 5 ; 
%    No 
%    ?- entre(2,1,X). 
%    No
% Nota: La relación predefinida correspondiente a entre es between.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6. (Base de datos familiar)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% En este ejercicio vamos a considerar el programa familia.pl del Tema
% 8. Las personas se representan mediante estructuras de la
% forma 
%    persona([Nombre,Apellido_1,Apellido_2],
%            fecha(Día,Mes,Año),
%            trabajo(Profesión,Sueldo))
% La base de datos de las familias se definen por la relación
% familia(P,M,L) que se verifica si existe una familia con padre P,
% madre M y lista de hijos L. 
familia(persona([tomas,garcia,perez],
                fecha(7,mayo,1950),
                trabajo(profesor,75)),
        persona([ana,lopez,ruiz],
                fecha(10,marzo,1952),
                trabajo(medica,100)),
        [ persona([juan,garcia,lopez],
                  fecha(5,enero,1970),
                  estudiante),
          persona([maria,garcia,lopez],
                  fecha(12,abril,1972),
                  estudiante) ]).
familia(persona([jose,perez,ruiz],
                fecha(6,marzo,1953),
                trabajo(pintor,150)),
        persona([luisa,galvez,perez],
                fecha(12,mayo,1954),
                trabajo(medica,100)),
        [ persona([juan_luis,perez,perez],
                  fecha(5,febrero,1980),
                  estudiante),
          persona([maria_jose,perez,perez],
                  fecha(12,junio,1982),
                  estudiante),
          persona([jose_maria,perez,perez],
                  fecha(12,julio,1984),
                  estudiante) ]).
% La relación casado(X) que se verifica si X es un hombre casado y la
% relación casada(X) que se verifica si X es un mujer casada.  
casado(X) :-
   familia(X,_,_).

casada(X) :-
   familia(_,X,_).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.1. Definir la relación hijo(X) que se verifique si X figura
% en alguna lista de hijos. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.2. Definir la relación existe(X) que se verifique si X es
% una persona existente en la base de datos. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.3. Hacer una pregunta tal que que las respuestas sean las
% listas de la forma [nombre, apellido1, apellido2] de todas las
% personas que existen.  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.4. Determinar todos los estudiantes nacidos antes de 1983.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.5. Definir la relación fecha_de_nacimiento(X,Y) de forma
% que si X es una persona, entonces Y es su fecha de nacimiento.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.6. Buscar todos los hijos nacidos en 1982.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.7. Definir la relación sueldo(X,Y) que se verifique si el
% sueldo de la persona X es Y. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.8. Buscar todas las personas nacidas antes de 1954 cuyo
% sueldo sea superior a 72 euros.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.9. Definir la relación total(L,Y) que se verifique si Y es
% la suma de los sueldos de las personas de la lista L. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6.10. Calcular los ingresos totales de cada familia.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 7. (Simulación del autómata)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% En este ejercicio consideraremos el programa automata.pl del Tema
% 8. El autómata se define mediante las siguientes relaciones 
%  * final(E) que se verifica si E es el estado final.
%  * trans(E1,X,E2) que se verifica si se puede pasar del estado E1 al
%    estado E2 usando la letra X. 
%  * nulo(E1,E2) que se verifica si se puede pasar del estado E1 al
%    estado E2 mediante un movimiento nulo. 
% El autómata del ejemplo está definido por
final(e3).

trans(e1,a,e1).
trans(e1,a,e2).
trans(e1,b,e1).
trans(e2,b,e3).
trans(e3,b,e4).

nulo(e2,e4).
nulo(e3,e1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 7.1. Definir la relación acepta_acotada(S,L,N) que se
% verifique si el autómata, a partir del estado S, acepta la lista L y
% la longitud de L es N.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 7.2. Buscar las cadenas aceptadas a partir de e1 con
% longitud 3. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 7.3. Definir la relación acepta_acotada_2(S,L,N) que se
% verifique si el autómata, a partir del estado S, acepta la lista L y
% la longitud de L es menor o igual que N.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 8. (Banda de músicos)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Se sabe que
%  1. Una banda está compuesta por tres músicos de distintos paises y
%     que tocan distintos instrumentos. 
%  2. El pianista toca primero.
%  3. Juan toca el saxo y toca antes que el australiano.
%  4. Marcos es francés y toca antes que el violinista.
%  5. Hay un músico japonés.
%  6. Un músico se llama Saúl.
%  Determinar el nombre, el país y el instrumento que toca cada uno de
%  los músicos de la banda.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 9. (Movimientos del caballo)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Supongamos que los cuadros del tablero de ajedrez los representamos
% por pares de números [X,Y] con X e Y entre 1 y 8.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 9.1. Definir la relación salta(+C1,?C2) que se verifique si
% el caballo puede pasar en un movimiento del cuadrado C1 al cuadrado
% C2. Por ejemplo,  
%     ?- salta([1,1],S).
%     S=[3,2];
%     S=[2,3];
%     No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 9.2. Definir la relación camino(L) que se verifique si L es
% una lista de cuadrados representando el camino recorrido por un
% caballo sobre un tablero vacío. Por ejemplo, 
%     ?- camino([[1,1],C]).
%     C=[3,2];
%     C=[2,3];
%     No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 9.3. Usando la relación camino, escribir una pregunta para
% determinar los caminos de longitud 4 por los que puede desplazarse un
% caballo desde cuadro [2,1] hasta el otro extremo del tablero (Y=8) de
% forma que en el segundo movimiento pase por el cuadro [5,4]. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 9.4. Calcular el menor número de movimientos necesarios para
% desplazar el caballo del cuadro [1,1] al [2,2]. ¿Cuántos caminos de
% dicha longitud hay de [1,1] a [2,2]? 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 10. Definir la relación diferencia(C1,C2,C3) que se verifique
% si C3 es la diferencia de los conjuntos C1 y C2. Por ejemplo, 
%    ?- diferencia([a,b],[b,c],X) 
%    X = [a] ;
%    No 
% Escribir una versión con not y otra con corte.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 11. Definir la relación agregar(X,L,L1) que se verifique si
% L1 es la lista obtenida añadiéndole X a L, si X no pertenece a L y es
% L en caso contrario. Por ejemplo,  
%    ?- agregar(a,[b,c],L).
%    L = [a,b,c]
%    ?- agregar(b,[b,c],L).
%    L = [b,c]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 12. Definir la relación separa(L1,L2,L3) que separa la lista
% de números L1 en dos listas: L2 formada por los números positivos y L3
% formada por los números negativos o cero. Por ejemplo, 
%    ?- separa([2,0,-3,5,0,2],L2,L3).
%    L2 = [2, 5, 2]
%    L3 = [0, -3, 0] 
%    Yes
% Proponer dos soluciones, una sin corte y otra con corte.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 13. Definir la relación suma_pares(L,N) que se verifica si N
% es la suma de todos los números pares de la lista L. Por ejemplo, 
%    ?- suma_pares([2,3,4],N).
%    N = 6 
%    ?- suma_pares([1,3,5,6,9,11,24],N).
%    N = 30 
% Escribir dos definiciones, una versión con negación y otra con corte.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 14. Definir la relación exponente_de_dos(N,Exp) que se
% verifique si E es el exponente de 2 en la descomposición de N como
% producto de factores primos. Por ejemplo, 
%    ?- exponente_de_dos(40,E).
%    E=3
%    ?- exponente_de_dos(49,E).
%    E=0
% Proponer una versión con negación y otra con corte.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 15. Definir la relación lista_a_conjunto(+L,-C) que se
% verifique si C es el conjunto correspondiente a la lista L (es decir,
% C contiene los mismos elementos que L en el mismo orden, pero si L
% tiene elementos repetidos sólo se incluye en C la última aparición de
% cada elemento). Por ejemplo, 
%    ?- lista_a_conjunto([b,a,b,d],C).
%    C = [a, b, d]
% Nota: La relación lista_a_conjunto se corresponde con la relación
% predefinida list_to_set. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 16. Definir la relación crecimientos(+L1,-L2) que se verifique
% si L2 es la lista correspondientes a los crecimientos de la lista
% numérica L1; es decir, entre cada par de elementos consecutivos X e Y
% de L1 coloca el signo + si X < Y e y signo - en caso contrario. Por
% ejemplo,
%    ?- crecimientos([1,3,2,2,5,3],L).
%    L = [1, +, 3, -, 2, -, 2, +, 5, -]
% Dar una definición sin corte y otra con corte.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 17. Definir las siguientes relaciones:
%  * menor_divisor_propio(+N,?X) que se verifique si X es el menor
%    divisor de N mayor o igual que 2. Por ejemplo,  
%       ?- menor_divisor_propio(30,X).
%       X = 2
%       ?- menor_divisor_propio(3,X).
%       X = 3
%  * factorizacion(+N,-L) que se verifique si L es la lista
%    correspondiente a la descomposición del número N en factores primos
%    (se considera que lo elementos de L están ordenados de manera
%    creciente). Por ejemplo,  
%       ?- factorizacion(12,L).
%       L = [2, 2, 3] ;
%       No
%       ?- factorizacion(1,L).
%       L = [] ;
%       No
% Indicación: Se pueden usar las funciones floor, sqrt y mod.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 18. Definir la relación calcula(+N,+M,?X) que se verifique si
% X es el menor múltiplo de N tal que la suma de sus dígitos es mayor
% que M. Por ejemplo, 
%    ?- calcula(3,10,X).
%    X = 39
%    Yes
%    ?- calcula(7,20,X).
%    X = 399 
%    Yes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 19. Un número es libre de cuadrados si no es divisible por el
% cuadrado de ningún número mayor que 1. Definir la relación
% libre_de_cuadrados(+N) que se verifique si el número N es libre de
% cuadrados. Por ejemplo, 
%    ?- libre_de_cuadrados(30).
%    Yes
%    ?- libre_de_cuadrados(12).
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 20. Definir la relación suma_libres_de_cuadrados(+L,-S) que
% se verifique si S es la suma de los números libres de cuadrados la
% lista numérica L. Por ejemplo, 
%    ?- suma_libres_de_cuadrados([6,12,18,30],S).
%    S = 36 
% Nota: Dar dos definiciones, una con negación y otra con corte.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 21. Definir la relación max_lista(+L,-N) que se verifique si
% N es el mayor número de la lista L. Por ejemplo,
%    ?- max_lista([2,a23,5,7+9],N).
%    N = 5
%    ?- max_lista([-2,a23,-5,7+9],N).
%    N = -2 
%    ?- max_lista([a23,7+9],N).
%    No
% Nota: Se puede usar la relación number(X) que se verifica si X es un número.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 22. Definir la relación longitud_scm(+L1,+L2,-N) que se
% verifique si N es la longitud de las subsucesiones comunes maximales
% de las listas L1 y L2. Por ejemplo, 
%    ?- longitud_scm([2,1,4,5,2,3,5,2,4,3],[1,7,5,3,2],N).
%    N = 4 ;
%    No
% ya que [1,5,3,2] es una subsucesión de las dos listas y no poseen
% ninguna otra subsucesión común de mayor longitud. Obsérvese que los
% elementos de la subsucesión no son necesariamente elementos adyacentes
% en las listas. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

