Created
March 9, 2022 10:08
-
-
Save mrsolarius/0980cd50e300f25643a4d49152b723fa to your computer and use it in GitHub Desktop.
Comment aplatire une liste de liste en une liste 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 : flat/1 | |
% flat(L) vas concatener toutes les sous listes de L | |
% On supose ici que L est une liste de listes | |
% | |
% Exemple : | |
% flat([[1,2],[3,4],[5,6]]) = [1,2,3,4,5,6] | |
% Analyse | |
% | |
% flat(L)? | |
% / \ | |
% [] [Pr|Fin] | |
% ^ ^ | |
% | | | |
% Liste Liste de Liste | |
% | |
% Exemple : | |
% [[1,2]|[3],[4,5,6]]] | |
% |___| |__________| | |
% Pr Fin | |
% |____________| | |
% | | | |
% [1,2|3,4,5,6] flat <-+ +-> flat [3,4,5,6] | |
% | |
% sur L : 2 cas | |
% 1) L = [] : dans se cas renvoie d'une liste vide | |
flat([])->[]; | |
% 2) L =/= [] : L = [Pr|Fin] | |
flat([Pr|Fin])->flat(Pr)++flat(Fin). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment