1. -module(irs).
  2. -compile(export_all).
  3. data() ->
  4.     [-50,-21,13,171,14,-42,-58,109,4,7,-23,-44,-98,-121,101, 33,87,-121,-40,-65,43,54,-45,-12,-12,38,25,3,7,8].
  5. go() ->
  6.      find(9, data(), 0).
  7. find(N, L, _) when N == 0;L == [] -> [];
  8. find(N, L, _) when length(L) == N -> L;
  9. find(N, [H|T], S) ->
  10.     With = [H | find(N-1, T, S - H)],
  11.     case lists:sum(With) of
  12.         S ->
  13.             With;
  14.         WS ->
  15.             Without = find(N, T, S),
  16.             case abs(WS - S) < abs(lists:sum(Without) - S) of
  17.                 true -> With;
  18.                 _ -> Without
  19.             end
  20.     end.
  21. View this file Here (Right Click and save As)