fork download
  1. -module(prog).
  2. -export([main/0]).
  3.  
  4. twoCombination([]) -> [];
  5. twoCombination([H|T]) -> [{H, X} || X <- T] ++ twoCombination(T).
  6.  
  7. lesser(ValList) ->
  8. DiffList = lists:map(fun({A, B}) -> {abs(A - B), {A, B}} end, twoCombination(ValList)),
  9. {_, Values} = lists:foldl(fun({Diff, DiffValues}, {Acc, AccValues}) ->
  10. case Diff =< Acc of
  11. true -> {Diff, DiffValues};
  12. false -> {Acc, AccValues}
  13. end
  14. end, {65535, 0}, DiffList),
  15. Values.
  16.  
  17. main() ->
  18. Result = lesser([41, 21, 19, 34, 111, 2, 5]),
  19. io:format("~p", [Result]),
  20. true.
Success #stdin #stdout 0.19s 23456KB
stdin
Standard input is empty
stdout
{21,19}