Background:
The question derive from this question.But some criteria is omited by me.So I try to post a new question for this.If my expression is dimness and you have got it,just tell me or edit my post in place please.
I have a list2 like this:
SeedRandom[2016317];
list2 = RandomSample[Range@100, 20];
I want gather it whith two element but whithout no repeat element to nearest 100.As the answer,I make a function to serve this:
Pair[l_List] := Module[{k, f}, k = Subsets[Range@Length@l, {2}];
f = Nearest[# -> Range@Length@#] &[Plus @@ l[[#]] & /@ k];
k[[f[100, Length[l]/2]]]]
This result
Pair[list2]
{{6,14},{7,11},{11,19},{2,5},{9,11},{12,16},{3,4},{3,12},{6,20},{15,19}}
We can found out some elements is used two times,such as the 19th,11th,12th and 12th.It's unexpectation for me.I still feel some descriptions is not accurate.If you get it,help me improve this question.I'll appreciate you very much.