Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(lab02).
- -import(string,[concat/2]).
- -compile(export_all).
- %1
- mixBeverages(T1, T2) ->
- {concat(concat(element(1, T1), " + "), element(1, T2)), element(2, T1) + element(2, T2)}.
- %2
- isOlder(D1, D2) ->
- if
- D1 == D2 -> false;
- element(3, D1) < element(3,D2) -> true;
- element(3, D1) > element(3,D2) -> false;
- element(2, D1) < element(2,D2) -> true;
- element(2, D1) > element(2,D2) -> false;
- element(1, D1) < element(1,D2) -> true;
- element(1, D1) > element(1,D2) -> false
- end.
- %3
- moveDecimal([], _) ->
- [];
- moveDecimal([Head|Tail], D3) ->
- [math:pow(10, D3)*Head | moveDecimal(Tail, D3)].
- %4
- removeNegatives([]) ->
- [];
- removeNegatives([Head|Tail]) ->
- if
- Head >= 0 -> [Head|removeNegatives(Tail)];
- true -> removeNegatives(Tail)
- end.
- %5
- removeNegatives2(L1) ->
- helper(L1).
- helper([]) ->
- [];
- helper([Head|Tail]) ->
- if
- Head >= 0 -> [Head|helper(Tail)];
- true -> helper(Tail)
- end.
- %6
- calculatePay(T3) ->
- {element(1, T3), element(2, T3)*element(3, T3)}.
- %7
- generate(A1, A2, _) when
- A1 > A2 -> [];
- generate(A1,A2,A3) when
- (A1 =< A2) -> [A1 | generate(A1+A3, A2, A3)].
- %8
- getnth([], N) ->
- if
- length([]) == 0 -> {error, no_such_element};
- N < 1 -> {error, no_such_element};
- N > length([]) -> {error, no_such_element}
- end;
- getnth([Head|_], 1) ->
- Head;
- getnth([_|Tail], N) ->
- getnth(Tail, N-1).
- %9
- repeat(_, []) ->
- [];
- repeat([], _) ->
- [];
- repeat([Head1|Tail1], [Head|Tail]) ->
- lists:flatten([lists:duplicate(Head,Head1)|repeat(Tail1,Tail)]).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement