Advertisement
ed195cm

Untitled

Nov 22nd, 2022
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.56 KB | Source Code | 0 0
  1. -module(lab02).
  2.  
  3. -import(string,[concat/2]).
  4. -compile(export_all).
  5.  
  6. %1
  7. mixBeverages(T1, T2) ->
  8.     {concat(concat(element(1, T1), " + "), element(1, T2)), element(2, T1) + element(2, T2)}.
  9.    
  10. %2
  11. isOlder(D1, D2) ->
  12.     if
  13.         D1 == D2 -> false;
  14.         element(3, D1) < element(3,D2) -> true;
  15.         element(3, D1) > element(3,D2) -> false;
  16.         element(2, D1) < element(2,D2) -> true;
  17.         element(2, D1) > element(2,D2) -> false;
  18.         element(1, D1) < element(1,D2) -> true;
  19.         element(1, D1) > element(1,D2) -> false
  20.     end.
  21.    
  22.    
  23. %3
  24. moveDecimal([], _) ->
  25.     [];
  26. moveDecimal([Head|Tail], D3) ->
  27.     [math:pow(10, D3)*Head | moveDecimal(Tail, D3)].
  28.    
  29. %4
  30. removeNegatives([]) ->
  31.     [];
  32. removeNegatives([Head|Tail]) ->
  33.     if
  34.         Head >= 0 -> [Head|removeNegatives(Tail)];
  35.         true -> removeNegatives(Tail)
  36.     end.
  37.        
  38. %5
  39. removeNegatives2(L1) ->
  40.     helper(L1).
  41. helper([]) ->
  42.     [];
  43. helper([Head|Tail]) ->
  44.     if
  45.         Head >= 0 -> [Head|helper(Tail)];
  46.         true -> helper(Tail)
  47.     end.   
  48.    
  49. %6
  50. calculatePay(T3) ->
  51.     {element(1, T3), element(2, T3)*element(3, T3)}.
  52.    
  53. %7
  54. generate(A1, A2, _) when
  55.         A1 > A2 -> [];
  56. generate(A1,A2,A3) when
  57.         (A1 =< A2) -> [A1 | generate(A1+A3, A2, A3)].
  58.    
  59. %8
  60. getnth([], N) ->
  61.     if
  62.         length([]) == 0 -> {error, no_such_element};
  63.         N < 1 -> {error, no_such_element};
  64.         N > length([]) -> {error, no_such_element}
  65.     end;       
  66. getnth([Head|_], 1) ->
  67.     Head;
  68. getnth([_|Tail], N) ->
  69.     getnth(Tail, N-1).
  70.        
  71. %9
  72. repeat(_, []) ->
  73.     [];
  74. repeat([], _) ->
  75.     [];
  76. repeat([Head1|Tail1], [Head|Tail]) ->
  77.     lists:flatten([lists:duplicate(Head,Head1)|repeat(Tail1,Tail)]).
  78.    
  79.  
  80.  
  81.    
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement