Commit 23dc6f32 by Paul Lesur

### Ajouts : flatten, retire, ajoute

parent aa783fce
 # Fiche aide IA02 Prolog ## Member ### Member ```prolog member(X, [X|_]). member(X, [_|Tail]) :-, member(X, Tail). ``` ## Append / Concat ### 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) :- ... ... @@ -26,13 +25,13 @@ 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 ### Tri à bulles ```prolog bubble_sort(List,Sorted):-b_sort(List,[],Sorted). b_sort([],Acc,Acc). ... ... @@ -42,3 +41,21 @@ 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!