In[112]:= SeedRandom[11111111];
data = RandomInteger[{0, 200}, 100]
min = Infinity;
n = Length[data];
Timing[Do[
tot = Total[
Map[Min,
Thread[{Abs[data - data[[j]]], Abs[data - data[[k]]]}]]];
If[tot < min,
Print[{data[[j]], data[[k]], tot}];
min = tot;
bestpair = data[[{j, k}]]];
, {j, n}, {k, j, n}];
bestpair]
Out[113]= {66, 74, 141, 104, 59, 59, 152, 149, 91, 183, 153, 188, 58, \
147, 145, 11, 129, 97, 36, 199, 57, 157, 181, 29, 34, 9, 104, 104, \
138, 157, 136, 73, 95, 200, 152, 172, 94, 57, 116, 184, 95, 87, 195, \
37, 32, 123, 154, 83, 50, 130, 143, 114, 52, 100, 143, 70, 33, 71, \
113, 65, 47, 27, 9, 159, 167, 1, 188, 188, 112, 109, 45, 48, 139, \
129, 150, 68, 193, 12, 124, 83, 49, 137, 39, 107, 68, 174, 55, 193, \
35, 60, 121, 33, 79, 18, 173, 196, 96, 97, 142, 104}
During evaluation of In[112]:= {66,66,5402}
During evaluation of In[112]:= {66,74,4882}
During evaluation of In[112]:= {66,141,2431}
During evaluation of In[112]:= {66,152,2378}
During evaluation of In[112]:= {141,59,2368}
During evaluation of In[112]:= {141,58,2364}
During evaluation of In[112]:= {141,57,2362}
During evaluation of In[112]:= {59,152,2347}
During evaluation of In[112]:= {59,149,2346}
During evaluation of In[112]:= {59,147,2344}
During evaluation of In[112]:= {149,58,2343}
During evaluation of In[112]:= {149,57,2342}
During evaluation of In[112]:= {58,147,2341}
During evaluation of In[112]:= {147,57,2340}
Out[116]= {0.294364, {147, 57}}
Could be done as above. (Would have preferred to say "Could be done as below", but once I had that formatted code block my cursor seemed unwilling to sneak above it to get into text mode. This is an unfortunate predicament for a cursor of but little understanding in the ways of the world.)