Browse Source

work on prolog

Andrea Gus 9 years ago
parent
commit
591b056dd3
1 changed files with 30 additions and 0 deletions
  1. 30 0
      prolog/prolog1.pl

+ 30 - 0
prolog/prolog1.pl

@@ -0,0 +1,30 @@
+find([X|_], X).
+find([_|L], X) :- find(L,X).
+
+concatenate([X|L1], L2, [X|L3]) :- concatenate(L1,L2,L3).
+concatenate([],L,L).
+
+pow(_,0,1).
+pow(X,1,X) :- !.
+pow(X,N,R) :- N1 is N-1, pow(X,N1,R1), R is X*R1. 
+
+
+powb(_,0,1) :- !.
+powb(X,1,X) :- !.
+powb(X,N,R) :- N1 is N-1, powb(X,N1,R1), R is R1*X. 
+
+part([X|L],Y,[X|L1],L2) :- X =< Y, !, part(L,Y,L1,L2).
+part([X|L],Y,L1,[X|L2]) :- X > Y, !, part(L,Y,L1,L2).
+part([],_,[],[]).
+
+quicksort([],[]).
+quicksort([H|T], Sorted) :- part(T,H,L1,L2), !, quicksort(L1,Sorted1), quicksort(L2,Sorted2), append(Sorted1,[H|Sorted2],Sorted). 
+
+map(_,[],[]).
+map(C,[X|Xs],[Y|Ys]) :- call(C,X,Y), !, map(C,Xs,Ys).
+
+square(N,R) :- R is N*N.
+
+not(X) :- call(X), !, fail.
+not(_).
+