Created
October 7, 2018 19:07
-
-
Save Reflej0/9ad0a3fa2fbe11984090fd70753d107d to your computer and use it in GitHub Desktop.
Ejercicios de Prolog UNLAM Programacion Avanzada 2018 2C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Enunciado https://docs.google.com/document/d/1LyNxWoKkv-WjcqT05i1O-u_4J5ybIgAfw5rIs-wVgkM/edit# | |
hombre(pedro) . | |
hombre(manuel) . | |
hombre(arturo) . | |
mujer(maría). | |
padre(pedro, manuel). | |
padre(pedro, arturo). | |
padre(pedro, maría) . | |
nino(X,Y):-padre(Y,X). | |
hijo(X,Y):-padre(Y,X),hombre(X). | |
hija(X,Y):-padre(Y,X),mujer(X). | |
hermanoohermana(X,Y):-nino(X,Z),nino(Y,Z),not(X==Y). | |
%fin clauses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Enunciado https://docs.google.com/document/d/1LyNxWoKkv-WjcqT05i1O-u_4J5ybIgAfw5rIs-wVgkM/edit# | |
%clauses | |
transporte(roma,20). | |
transporte(londres,30). | |
transporte(tunez,10). | |
alojamiento(roma,hotel,50). | |
alojamiento(roma,hostal,30). | |
alojamiento(roma,camping,10). | |
alojamiento(londres,hotel,60). | |
alojamiento(londres,hostal,40). | |
alojamiento(londres,camping,20). | |
alojamiento(tunez,hotel,40). | |
alojamiento(tunez,hostal,20). | |
alojamiento(tunez,camping,5). | |
%finclauses | |
multiplicar(P,X,Y):-P is X*Y. | |
sumar(S,X,Y):-S is X+Y. | |
menor(X,Y):-X<Y. | |
%que se interpreta por: el viaje a la ciudad C | |
%durante S semanas con estancia en H cuesta P pesos. | |
%viaje(C,S,H,P):-transporte(C, Z),alojamiento(C, H, ). | |
viaje(C,S, H, P):-transporte(C,T),alojamiento(C,H,W),multiplicar(P1, W, S),sumar(P, P1, T). | |
viajeeconomico(C,S,H,P,Pmax):-transporte(C,T),alojamiento(C,H,W),multiplicar(P1, W, S),sumar(P, P1, T),menor(P,Pmax). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Enunciado https://docs.google.com/document/d/1LyNxWoKkv-WjcqT05i1O-u_4J5ybIgAfw5rIs-wVgkM/edit# | |
%clauses | |
parcial1(ana,7). | |
parcial1(juan,4). | |
parcial1(camila, 8). | |
parcial1(rodrigo, 7). | |
parcial1(matias, 5). | |
parcial1(rodolfo, 10). | |
parcial2(ana,9). | |
parcial2(juan,8). | |
parcial2(camila, 8). | |
parcial2(rodrigo, 6). | |
parcial2(matias, 10). | |
parcial2(rodolfo, 2). | |
%finclauses | |
multiplicar(P,X,Y):-P is X*Y. | |
sumar(S,X,Y):-S is X+Y. | |
menor(X,Y):-X<Y. | |
mayor(X,Y):-X>Y. | |
promedio(P, X, Y):-P is (X+Y)/2. | |
promocionados(N, NF):-parcial1(N, T),parcial2(N, W),mayor(T, 6),mayor(W, 6),promedio(NF, T, W). | |
aprobados(N):-parcial1(N, T),parcial2(N, W),mayor(T, 3),mayor(W, 3),(menor(T, 7);menor(W, 7)). | |
recursantes(N):-parcial1(N, T),parcial2(N, W),(menor(T, 4);menor(W, 4)). | |
%https://stackoverflow.com/questions/22469584/store-result-as-a-list-using-prolog | |
mejor_promedio(MP):-findall(Y, promocionados(_, Y), Lista),maxValue(Lista, MP). | |
alumnos_mejor_promedio(N, MP):-promocionados(N, Y),mejor_promedio(MP),MP==Y. | |
%https://stackoverflow.com/questions/27455034/find-max-integer-in-a-list-in-prolog | |
maxValue([H|T], Y):- | |
maxValue(T,X), | |
(H > X -> | |
H = Y; | |
Y = X). | |
maxValue([X],X). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Enunciado https://docs.google.com/document/d/1LyNxWoKkv-WjcqT05i1O-u_4J5ybIgAfw5rIs-wVgkM/edit# | |
%clauses | |
parcial1(ana,7). | |
parcial1(juan,4). | |
parcial1(camila, 8). | |
parcial1(rodrigo, 7). | |
parcial1(matias, 5). | |
%parcial1(rodolfo, 10). | |
parcial2(ana,9). | |
%parcial2(juan,8). | |
parcial2(camila, 8). | |
parcial2(rodrigo, 6). | |
parcial2(matias, 10). | |
parcial2(rodolfo, 2). | |
%finclauses | |
multiplicar(P,X,Y):-P is X*Y. | |
sumar(S,X,Y):-S is X+Y. | |
menor(X,Y):-X<Y. | |
mayor(X,Y):-X>Y. | |
promedio(P, X, Y):-P is (X+Y)/2. | |
promocionados(N, NF):-parcial1(N, T),parcial2(N, W),mayor(T, 6),mayor(W, 6),promedio(NF, T, W). | |
aprobados(N):-parcial1(N, T),parcial2(N, W),mayor(T, 3),mayor(W, 3),(menor(T, 7);menor(W, 7)). | |
recursantes(N):-parcial1(N, T),parcial2(N, W),(menor(T, 4);menor(W, 4)). | |
%https://stackoverflow.com/questions/22469584/store-result-as-a-list-using-prolog | |
mejor_promedio(MP):-findall(Y, promocionados(_, Y), Lista),maxValue(Lista, MP). | |
alumnos_mejor_promedio(N, MP):-promocionados(N, Y),mejor_promedio(MP),MP==Y. | |
%https://stackoverflow.com/questions/27455034/find-max-integer-in-a-list-in-prolog | |
maxValue([H|T], Y):- | |
maxValue(T,X), | |
(H > X -> | |
H = Y; | |
Y = X). | |
maxValue([X],X). | |
alumnos_ambos_parciales(N):-parcial1(N, _),parcial2(N,_). | |
todos_alumnos(N):-parcial1(N, _);parcial2(N,_). | |
alumnos_ausentes(N):- | |
findall(T, todos_alumnos(T), Todos), | |
findall(U, alumnos_ambos_parciales(U), Ambos), | |
subtract(Todos,Ambos, N). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Enunciado https://docs.google.com/document/d/1LyNxWoKkv-WjcqT05i1O-u_4J5ybIgAfw5rIs-wVgkM/edit# | |
es_un_pais(argentina). | |
es_un_pais(peru). | |
es_un_pais(chile). | |
es_un_pais(brasil). | |
es_un_pais(uruguay). | |
limita_con(argentina,brasil). | |
limita_con(argentina,uruguay). | |
limita_con(uruguay, brasil). | |
limita_con(peru, brasil). | |
limita_con(chile, argentina). | |
limitrofes(X,Y):-limita_con(X,Y);limita_con(Y,X). | |
es_translimitrofe(X,Z):-limitrofes(X,Y),limitrofes(Y,Z),not(limitrofes(X,Z)),not(X==Z). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment