-module(irs). -compile(export_all). data() -> [-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]. go() -> find(9, data(), 0). find(N, L, _) when N == 0;L == [] -> []; find(N, L, _) when length(L) == N -> L; find(N, [H|T], S) -> With = [H | find(N-1, T, S - H)], case lists:sum(With) of S -> With; WS -> Without = find(N, T, S), case abs(WS - S) < abs(lists:sum(Without) - S) of true -> With; _ -> Without end end.