Last active
March 16, 2022 09:13
-
-
Save mrsolarius/de71ca0ee8d1ef0f6a254338341779b9 to your computer and use it in GitHub Desktop.
Comment trouver le minimum d'une liste en Erlang ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Spec : mini/1 | |
% mini(L) renvoie le minimum de L | |
% | |
% Exemple : | |
% mini([1,2,3]) = 1 | |
% mini([3,1,2]) = 1 | |
% Analyse | |
% sur L : 2 cas | |
% 1) L = [] : le minimum non défini (Pas de clause pour le cas 1) | |
% 2) L =/= [] : L = [Pr|Fin] | |
% Soit M le minimum de Fin (M = mini(Fin) | |
mini([])->false; | |
mini([Pr|Fin])-> | |
M = mini(Fin), | |
case Pr<M of | |
true->Pr | |
false->M | |
end. | |
% Réaliser mini/1 sans utiliser le case. | |
% Introduction d'un nouvelle fonction mini/2 | |
% Spec | |
% mini(L,X) est le minimum entre X et le Minimum de L | |
mini([],X)-> | |
X; | |
mini([Pr|Liste],X) when X<Pr -> | |
mini(Liste,X); | |
mini([Pr|Liste],X) when X>=Pr -> | |
mini(Liste,Pr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment