Está en la página 1de 2

:- style_check(-singleton).

p1(X):-Y=2,X=Y+1.
p2(X):-X=Y+1,Y=2.
p3(X):-Y=2,X is Y+1.
p4(X):-X is Y+1,Y=2.
p5(X):-X=1,X=2.
p6(X):-X=2*Y,X=Z*3.
p11(X):-X=2+1.
p12(X):-X is 2+1.
p13(X):-X=1,X=2.
p14(X):-X*3=Y*3.
suma(X,Y,Z):-Z is X+Y.
edge(a,b).
edge(a,c).
edge(b,a).
edge(c,d).
edge(d,d).
edge(d,e).
edge(e,f).
edge(f,g).
edge(g,e).
agregar(L1,L2,0,Rta):-append(L1,L2,Rta).
agregar(L1,[A|L2],s(X),[A|Rta]):-
agregar(L1,L2,X,Rta).
reducible_por_restas([0]).
reducible_por_restas(Xs):-reducir(Xs,Zs),
reducible_por_restas(Zs).
reducir([X,Y|Xs],[X|Rta]):-X<Y,reducir([Y|Xs],Rta).
reducir([X,Y|Xs],Rta):-X>=Y,Z is X-Y,append([Z],Xs,Rta).
suma_consec([X],[]).
suma_consec([X,Y|L1],[Z|L2]):-Z is X+Y,suma_consec([Y|L1],L2).
max(X,Y,X):-X>Y.
max(X,Y,Y):-Y>=X.
altura(#,-1).
altura(bin(R,Hi,Hd),A):-altura(Hi,AHi),
altura(Hd,AHd),
A is max(AHi,AHd)+1.
profundidad(#,0).
profundidad(bin(R,Hi,Hd),P):-profundidad(Hi,Pi),
profundidad(Hd,Pd),
P is max(Pi,Pd) + 1.
nivel(N,#,[]).
nivel(0,bin(R,Hi,Hd),[R]).
nivel(N,bin(R,Hi,Hd),L):-N1 is N-1,
nivel(N1,Hi,L1),nivel(N1,Hd,L2),
append(L1,L2,L).
difabs(X,Y,Z):-X>Y,Z is X-Y.
difabs(X,Y,Z):-X=<Y,Z is Y-X.
balanceado(#).
balanceado(bin(_, #, #)).
balanceado(bin(_, Hi, Hd)):-
altura(Hi, Mi),
altura(Hd, Md),
difabs(Mi,Md,M),
M=<1,
balanceado(Hi),
balanceado(Hd).
profundos(N,#,[]).
profundos(0,bin(R,Hi,Hd),[R|L]):-
profundos(0,Hi,L1), profundos(0,Hd,L2),append(L1,L2,L).
profundos(N,bin(R,Hi,Hd),L):-N1 is N-1,
profundos(N1,Hi,L1),profundos(N1,Hd,L2),
append(L1,L2,L).
producto_cartesiano(A,B,AxB):-
findall([X,Y],(member(X,A),member(Y,B)),AxB).
cant_veces([],E,0).
cant_veces([E|L],E,V):-cant_veces(L,E,C),V is C+1.
cant_veces([X|L],E,V):-X\=E,cant_veces(L,E,V).
masveces([X],X,1).
masveces([X|L],X,R):-masveces(L,E,V),cant_veces([X|L],X,R),
R>V.
masveces([X|L],E,V):-masveces(L,E,V),cant_veces([X|L],X,R),
R=<V.
hallarCiclos(Vertice,Ciclos):-
findall(Ciclo,ciclo(Vertices,Ciclo),Ciclos).
ciclo([X,Y|Vertices],[X|Ciclo]):-edge(X,Y),camino(Y,X,Ciclo).
camino(X,Y,[X|Cs]) :- camino(X,Y,[X],Cs).
camino(X,X,_,[]).
camino(X,Y,Visitados,[Z|Cs]) :-edge(X,Z), not(member(Z,Visitados)),
camino(Z,Y,[Z|Visitados],Cs).
no_pertenece(X,[]).
no_pertenece(X,[Y|Ys]):-X\=Y,no_pertenece(X,Ys).

También podría gustarte