Advertisement
krot

пример рекурсии

Jul 28th, 2019
1,629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.47 KB | None | 0 0
  1. -export([ld/1]).
  2. ld([])->0;
  3. ld([2|T])->1+ld(T);
  4. ld([_|T])->0+ld(T).
  5. х
  6. ld(E)->ld(E,0).
  7. ld([],Len)->Len;
  8. ld([_|E],Len)->ld(E,Len+1).
  9.  
  10. get_users()->
  11. [
  12. {user,1,"a",10},
  13. {user,2,"b",150},
  14. {user,3,"c",160},
  15. {user,4,"d",107}
  16. ].
  17.  
  18. get_sum(E)->get_sum(E,0).
  19. get_sum([],N)->N;
  20. get_sum([E|I],N)->
  21. {user,X,_,_}=E,
  22. get_sum(I,N+X).
  23.  
  24. filter(E)->filter(E,[]).
  25. filter([],Ac)->Ac;
  26. filter([E|I],Ac)->
  27.  case E of
  28.  {user,_,"bob",_}-> filter(I,[E|Ac]) ;
  29.  _-> filter(I,Ac)
  30. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement