3
$\begingroup$

From the values:

{57.02, 71.04, 87.03, 97.05, 99.07, 101.05, 103.01, 113.08, 114.04, 115.03,
 128.06, 128.09, 129.04, 131.04, 137.06, 147.07, 156.10, 163.03, 186.08}

I would like to find all possible combinations of 3 values that have the sum of roughly 344.25 (+/- 0.05 would be ok). I have tried:

IntegerPartitions[344.2, {3}, {57.0, 71.0, 87.0, 97.1, 99.1, 101.1, 103.0, 113.1, 114.0, 115.0, 128.1, 128.1, 129.0, 131.0, 137.1, 147.1, 156.1, 163.0, 186.1}]

though IntegerPartitions only seems to accept whole numbers. Any help would be appreciated.

$\endgroup$
6
$\begingroup$
list = {57.0, 71.0, 87.0, 97.1, 99.1, 101.1, 103.0, 113.1, 114.0, 
   115.0, 128.1, 128.1, 129.0, 131.0, 137.1, 147.1, 156.1, 163.0,  186.1};

subsets = DeleteDuplicates @ Select[Subsets[list, {3}], 344.2 <= Total[#] <= 344.3 &]

{{57., 101.1, 186.1},
{87., 101.1, 156.1},
{101.1, 115., 128.1},
{103., 113.1, 128.1}}

DeleteDuplicates[Join @@ Permutations /@ subsets]

{{57., 101.1, 186.1}, {57., 186.1, 101.1}, {101.1, 57., 186.1}, {101.1, 186.1, 57.}, {186.1, 57., 101.1}, {186.1, 101.1, 57.},
{87., 101.1, 156.1}, {87., 156.1, 101.1}, {101.1, 87., 156.1}, {101.1, 156.1, 87.}, {156.1, 87., 101.1}, {156.1, 101.1, 87.},
{101.1, 115., 128.1}, {101.1, 128.1, 115.}, {115., 101.1, 128.1}, {115., 128.1, 101.1}, {128.1, 101.1, 115.}, {128.1, 115., 101.1},
{103., 113.1, 128.1}, {103., 128.1, 113.1}, {113.1, 103., 128.1}, {113.1, 128.1, 103.}, {128.1, 103., 113.1}, {128.1, 113.1, 103.}}

$\endgroup$
2
$\begingroup$

Use exact fractions for IntegerPartitions:

L = Round[{57.02, 71.04, 87.03, 97.05, 99.07, 101.05, 103.01, 113.08, 
           114.04, 115.03, 128.06, 128.09, 129.04, 131.04, 137.06, 147.07, 
           156.10, 163.03, 186.08}, 1/100];

Join @@ Table[IntegerPartitions[i, ∞, L], {i, 344, 345, 1/100}]

(*    {{11503/100, 11503/100, 2851/25},
       {11503/100, 11503/100, 2851/50, 2851/50},
       {10301/100, 1941/20, 8703/100, 2851/50},
       {3226/25, 6403/50, 8703/100},
       {3226/25, 2851/25, 2021/20}, 
       {3226/25, 2021/20, 2851/50, 2851/50},
       {3226/25, 8703/100, 1776/25, 2851/50},
       {6403/50, 11503/100, 2021/20},
       {11503/100, 2021/20, 1776/25, 2851/50},
       {11503/100, 8703/100, 1776/25, 1776/25},
       {4652/25, 2021/20, 2851/50},
       {4652/25, 8703/100, 1776/25},
       {3276/25, 2851/25, 9907/100},
       {3276/25, 9907/100, 2851/50, 2851/50},
       {6403/50, 2827/25, 10301/100},
       {2827/25, 10301/100, 1776/25, 2851/50},
       {1561/10, 3276/25, 2851/50},
       {3276/25, 1776/25, 1776/25, 1776/25},
       {3226/25, 12809/100, 8703/100},
       {2827/25, 8703/100, 8703/100, 2851/50},
       {10301/100, 9907/100, 1776/25, 1776/25},
       {12809/100, 11503/100, 2021/20},
       {2021/20, 9907/100, 8703/100, 2851/50},
       {9907/100, 8703/100, 8703/100, 1776/25},
       {1561/10, 2021/20, 8703/100},
       {12809/100, 2827/25, 10301/100},
       {2021/20, 2021/20, 1776/25, 1776/25}}    *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.