# Select subsets from a list based on a criterion?

Assume we have a set of numbers, for instance $$A=\{2,3,4,5,6,7,8,9,10\}$$ and we are looking for the sums of reciprocals such that they are less than one. I mean I am looking for all $$S_B$$'s $$S_B=\sum_{i\in B}\frac1i<1,$$ where $$B\subset A$$. How can I write such code in "Mathematica"?

I wrote the following code but it does not work properly

Clear[A]
A = {2, 3, 4, 5, 6, 7, 8, 9, 10};
Table[If[SubsetQ[A,B] == True&& Sum[1/i, {i, B}]<1,Sum[1/i, {i, B}], Nothing], {B,A}]


Something like this?

A = Subsets@Range[2., 10.];
Select[{#, Sum[i^-1, {i, #}]} & /@ A, #[] < 1 &]


{{{},0},{{2.},0.5},{{3.},0.333333},{{4.},0.25},<<267>>,{{4.,5.,7.,8.,9.,10.},0.928968},{{4.,6.,7.,8.,9.,10.},0.895635},{{5.,6.,7.,8.,9.,10.},0.845635}}

• thanks, what if we need only the second values, {0,0.5,0.3333,0.25,...}? – asad Nov 11 at 10:42
• @asad If you only want the sums and don't care about the subsets that correspond to them, then just use Select[Sum[i^-1, {i, #}] & /@ A, # < 1 &]. – That Gravity Guy Nov 11 at 10:50
• The sum can also be written as Total[1/#]& for improved readability & speed – Lukas Lang Nov 11 at 13:16
selected = Select[# < 1 &] @ Total[Subsets[1. /Range[2, 10]], {2}];

selected // Short


{0., 0.5, 0.333333, 0.25, 0.2, << 265 >>, 0.952778, 0.928968, 0.895635, 0.845635}

Length @ selected


274