1 / 12

Prolog

Prolog. Def . Recursiva d isjuntos([],_). d isjuntos([X|Y],Z) :- not ( pert (X,Z)),disjuntos(Y,Z). Def . Conjuntos Disjuntos.- Dos conjuntos A y B son disjuntos si A  B = . Def . Iterativa disjuntos_iter (X,Y) :- not ( ( pert (Z,X), pert (Z,Y))). Ejercicio.

enya
Download Presentation

Prolog

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Prolog Def. Recursiva disjuntos([],_). disjuntos([X|Y],Z) :-not (pert(X,Z)),disjuntos(Y,Z). Def. Conjuntos Disjuntos.- Dos conjuntos A y B son disjuntos si A B =  Def. Iterativa disjuntos_iter(X,Y) :-not( (pert(Z,X),pert(Z,Y))).

  2. Ejercicio Def. Subconjunto. Sean A y B dos conjuntos tal que cada elemento de A es también elemento de B. Entonces, se dice que: A es subconjunto de B, y se denota A  B Def. Recursiva subconjunto([],_). subconjunto([X|Y],Z):-pert(X,Z), subconjunto(Y,Z). Def. Iterativa subconj_iter([],_). subconj_iter(X,Y):-not((pert(Z,X), not(pert(Z,Y)))).

  3. Otra ver. de Subconjunto subconjunto([],[]). subconjunto([X|L1],[X|L2]):-subconjunto(L1,L2). subconjunto(L1,[_|L2]):-subconjunto(L1,L2).

  4. Combinatoria ?- combinacion([a,b,c],2,L). L = [a,b] ; L = [a,c] ; L = [b,c] ; false

  5. Def. Combinatoria combinacion(L1,N,L2):-combinacion_1(L1,N,L2). combinacion_1(L1,N,L2):-subconjunto(L2,L1),length(L2,N). combinacion(L1,N,L2):-combinacion_2(L1,N,L2). combinacion_2(L1,N,L2):-length(L2,N),subconjunto(L2,L1).

  6. Permutaciones ?- select(X,[a,b,c],L). X = a L = [b, c] ; X = b L = [a, c] ; X = c L = [a, b] ; false ?- select(a,L,[b,c]). L = [a, b, c] ; L = [b, a, c] ; L = [b, c, a] ; false

  7. Implementaciones permuta([],[]). permuta(L1,[X|L2]):-select(X,L1,L3),permuta(L3,L2).

  8. Cuadrado Mágico Enunciado: Colocar los números 1,2,3,4,5,6,7,8,9 en un cuadrado 3x3 de forma que todas las líneas (filas, columnas y diagonales) sumen igual.

  9. Implementación cuadrado_1([A,B,C,D,E,F,G,H,I]) :- permutación([1,2,3,4,5,6,7,8,9], [A,B,C,D,E,F,G,H,I]), A+B+C =:= 15, D+E+F =:= 15, G+H+I =:= 15, A+D+G =:= 15, B+E+H =:= 15, C+F+I =:= 15, A+E+I =:= 15, C+E+G =:= 15.

  10. Solución Cuadrado Mágico

  11. Solución Cuadrado Mágico

  12. Planeación d(a,b). d(b,e). d(b,c). d(d,e). d(c,d). d(e,f). d(g,e). go(X,X,T). Go(X,Y,T)

More Related