Understanding the list will be awkward because it inevitably has to do something for each element of the list. To create an understanding of the list, you should try to figure out if it is an odd or even element that you are talking to. Here is the idea of what I'm talking about:
pair(L) -> L2 = lists:zip(lists:seq(1, length(L)), L), [[A, B] || {Ai, A} <- L2, {Bi, B} <- L2, Ai rem 2 == 1, Bi rem 2 == 0, Ai + 1 == Bi].
The time complexity in this case is probably terrible, because, as far as I know, Erlang does not optimize it in any way.
I do not think that something is wrong with your function, and you should stick to it.
source share