Commit aa783fce by Paul Lesur

parent c366cc4d
 ### Member # Fiche aide IA02 Prolog ## Member ```prolog member(X, [X|_]). member(X, [_|Tail]) :- member(X, [_|Tail]) :-, member(X, Tail). ``` ### Append ## Append / Concat ```prolog append([],X,X). append([X|Y],Z,[X|W]) :- append(Y,Z,W). ``` ### Reverse ## Reverse ```prolog reverse([],[]). reverse([X|Xs],YsX) :- reverse(Xs,Ys), append(Ys,[X],YsX). ``` ### Length ## Length ```prolog len([], 0). len([_ | Tail], Length) :- ... ... @@ -25,8 +26,19 @@ len([_ | Tail], Length) :- Length is Length1 + 1,!. ``` ### Nième élément ## Nième élément ```prolog element_n(1,[X|Q],X):-!. element_n(N,[T|Q],X):-M is N-1, element_n(M,Q,X). ``` ## Tri à bulles ```prolog bubble_sort(List,Sorted):-b_sort(List,[],Sorted). b_sort([],Acc,Acc). b_sort([H|T],Acc,Sorted):-bubble(H,T,NT,Max),b_sort(NT,[Max|Acc],Sorted). bubble(X,[],[],X). bubble(X,[Y|T],[Y|NT],Max):-X>Y,bubble(X,T,NT,Max). bubble(X,[Y|T],[X|NT],Max):-X=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!