Sum of list numbers smaller than one goal












4












$begingroup$


I have five values ​​that I would like to add them so that they can be equal to or less than 3000.



v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
Subsets [{v1, v2, v3, v4, v5}]


For example:



v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1


-> 2940



v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2


-> 2940



v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v3


-> 2940



v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v4


-> 2940



v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v5


-> 2940



v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2


-> 2940



v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2 + v2


-> 2940



All are possibilities, among other possibilities.



Is there a feature that validates these possibilities?










share|improve this question











$endgroup$

















    4












    $begingroup$


    I have five values ​​that I would like to add them so that they can be equal to or less than 3000.



    v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
    Subsets [{v1, v2, v3, v4, v5}]


    For example:



    v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1


    -> 2940



    v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2


    -> 2940



    v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v3


    -> 2940



    v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v4


    -> 2940



    v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v5


    -> 2940



    v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2


    -> 2940



    v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2 + v2


    -> 2940



    All are possibilities, among other possibilities.



    Is there a feature that validates these possibilities?










    share|improve this question











    $endgroup$















      4












      4








      4





      $begingroup$


      I have five values ​​that I would like to add them so that they can be equal to or less than 3000.



      v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
      Subsets [{v1, v2, v3, v4, v5}]


      For example:



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v3


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v4


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v5


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2 + v2


      -> 2940



      All are possibilities, among other possibilities.



      Is there a feature that validates these possibilities?










      share|improve this question











      $endgroup$




      I have five values ​​that I would like to add them so that they can be equal to or less than 3000.



      v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
      Subsets [{v1, v2, v3, v4, v5}]


      For example:



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v3


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v4


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v5


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2


      -> 2940



      v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v1 + v2 + v2 + v2


      -> 2940



      All are possibilities, among other possibilities.



      Is there a feature that validates these possibilities?







      combinatorics






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 21 at 19:18







      LCarvalho

















      asked Jan 21 at 18:15









      LCarvalhoLCarvalho

      5,67642886




      5,67642886






















          5 Answers
          5






          active

          oldest

          votes


















          7












          $begingroup$

          Append 1 to the list of vs and use FrobeniusSolve:



          w = {v1, v2, v3, v4, v5, 1};
          res = FrobeniusSolve[w, 3000][[2;;, ;; 5]];
          Length[res]



          1345




          Short @ res



          {{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1336>>,{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




          And @@ Thread[Total /@ res <= 3000]



          True




          Up to ordering, res is the same as Henrik's resulttable:



          Sort[res] == Sort[resulttable]



          True




          An alternative way to use IntegerPartitions using w:



          res2 = DeleteCases[Rest@IntegerPartitions[3000, All, w], 1, 2];
          Length@res2



          1345




          restab = Map[Lookup[Counts[#], Most @ w, 0] &] @ res2;
          Sort[res] == Sort[restab]



          True




          To get the totals that can be obtained using vs:



          Sort[DeleteDuplicates[res.Most[w]]] (* or *)
          Sort[3000 - DeleteDuplicates@Rest[FrobeniusSolve[w, 3000]][[All, -1]]]



          {140, 280, 420, 560, 700, 840, 980, 1120, 1260, 1400, 1540, 1680,
          1820, 1960, 2100, 2240, 2380, 2520, 2660, 2800, 2940}




          Sort @ Counts[res.Most[w]]



          <|140 -> 1, 280 -> 2, 420 -> 3, 560 -> 5, 700 -> 7, 840 -> 10,
          980 -> 13, 1120 -> 18, 1260 -> 23, 1400 -> 30, 1540 -> 37,
          1680 -> 47, 1820 -> 57, 1960 -> 70, 2100 -> 84, 2240 -> 101,
          2380 -> 119, 2520 -> 141, 2660 -> 164, 2800 -> 192, 2940 -> 221|>




          Update: You can also use Reduce and Solve:



          v = {v1, v2, v3, v4, v5};
          xv = Array[x, 5];
          resReduce = Reduce[{v.xv <= 3000, ##&@@Thread[xv >= 0]}, xv, Integers][[2;;, All, -1]] /.
          {And | Or -> List};
          resSolve = xv /. Rest@Solve[{v.xv <= 3000, ## & @@ Thread[xv >= 0]}, xv, Integers];
          res == resReduce == resSolve



          True







          share|improve this answer











          $endgroup$





















            4












            $begingroup$

            a = {140, 280, 420, 560, 700};
            results = Join @@ DeleteCases[
            IntegerPartitions[#, {1, ∞}, a] & /@ Range[3000],
            {}
            ];
            And @@ Thread[Total /@ results <= 3000]
            resulttable = Map[Lookup[Counts[#], a, 0] &, results];
            resulttable // Short



            True



            {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, <<1341>> , {19, 1, 0, 0, 0}, {21, 0, 0, 0, 0}}







            share|improve this answer











            $endgroup$





















              3












              $begingroup$

              v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
              Select[Subsets[{v1, v2, v3, v4, v5}], Total[#] <= goal &]


              Are you sure your "goal" is 3000? Every subset totals less than that.



              And what does 21 * v1 in your question refer to? What is $21$, and why multiplication?






              share|improve this answer









              $endgroup$





















                3












                $begingroup$

                a = {140, 280, 420, 560, 700};
                coef = Tuples[Range[0, 21], 5];
                vec = coef.a;

                Extract[coef, Position[Ramp[vec - 3000], 0]] // Short



                {{0,0,0,0,0},{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1335>>,{18,1,0,0,0},{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                Pick[vec, Ramp[vec - 3000], 0] // Short



                {0,700,1400,2100,2800,560,1260,1960,2660,1120,1820,2520,1680,2380,<<1318>>,2940,2800,2380,2940,2800,2660,2940,2520,2940,2800,2660,2940,2800,2940}







                share|improve this answer









                $endgroup$





















                  2












                  $begingroup$

                  Could use integer linear programming via Maximize, for example. The constraint I use is overkill, all we really need to enforce is that values be nonnegative.



                  vals = {140, 280, 420, 560, 700};
                  goal = 3000;
                  vars = Array[v, Length[vals]];
                  Maximize[{vars.vals,
                  Flatten[{vars.vals <= goal,
                  MapIndexed[0 <= # <= Floor[goal/vals[[#2[[1]]]]] &,
                  vars]}]}, vars, Integers]

                  (* Out[1287]= {2940, {v[1] -> 10, v[2] -> 4, v[3] -> 1,
                  v[4] -> 0, v[5] -> 0}} *)





                  share|improve this answer









                  $endgroup$













                    Your Answer





                    StackExchange.ifUsing("editor", function () {
                    return StackExchange.using("mathjaxEditing", function () {
                    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
                    });
                    });
                    }, "mathjax-editing");

                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "387"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: false,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: null,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189957%2fsum-of-list-numbers-smaller-than-one-goal%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    5 Answers
                    5






                    active

                    oldest

                    votes








                    5 Answers
                    5






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    7












                    $begingroup$

                    Append 1 to the list of vs and use FrobeniusSolve:



                    w = {v1, v2, v3, v4, v5, 1};
                    res = FrobeniusSolve[w, 3000][[2;;, ;; 5]];
                    Length[res]



                    1345




                    Short @ res



                    {{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1336>>,{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                    And @@ Thread[Total /@ res <= 3000]



                    True




                    Up to ordering, res is the same as Henrik's resulttable:



                    Sort[res] == Sort[resulttable]



                    True




                    An alternative way to use IntegerPartitions using w:



                    res2 = DeleteCases[Rest@IntegerPartitions[3000, All, w], 1, 2];
                    Length@res2



                    1345




                    restab = Map[Lookup[Counts[#], Most @ w, 0] &] @ res2;
                    Sort[res] == Sort[restab]



                    True




                    To get the totals that can be obtained using vs:



                    Sort[DeleteDuplicates[res.Most[w]]] (* or *)
                    Sort[3000 - DeleteDuplicates@Rest[FrobeniusSolve[w, 3000]][[All, -1]]]



                    {140, 280, 420, 560, 700, 840, 980, 1120, 1260, 1400, 1540, 1680,
                    1820, 1960, 2100, 2240, 2380, 2520, 2660, 2800, 2940}




                    Sort @ Counts[res.Most[w]]



                    <|140 -> 1, 280 -> 2, 420 -> 3, 560 -> 5, 700 -> 7, 840 -> 10,
                    980 -> 13, 1120 -> 18, 1260 -> 23, 1400 -> 30, 1540 -> 37,
                    1680 -> 47, 1820 -> 57, 1960 -> 70, 2100 -> 84, 2240 -> 101,
                    2380 -> 119, 2520 -> 141, 2660 -> 164, 2800 -> 192, 2940 -> 221|>




                    Update: You can also use Reduce and Solve:



                    v = {v1, v2, v3, v4, v5};
                    xv = Array[x, 5];
                    resReduce = Reduce[{v.xv <= 3000, ##&@@Thread[xv >= 0]}, xv, Integers][[2;;, All, -1]] /.
                    {And | Or -> List};
                    resSolve = xv /. Rest@Solve[{v.xv <= 3000, ## & @@ Thread[xv >= 0]}, xv, Integers];
                    res == resReduce == resSolve



                    True







                    share|improve this answer











                    $endgroup$


















                      7












                      $begingroup$

                      Append 1 to the list of vs and use FrobeniusSolve:



                      w = {v1, v2, v3, v4, v5, 1};
                      res = FrobeniusSolve[w, 3000][[2;;, ;; 5]];
                      Length[res]



                      1345




                      Short @ res



                      {{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1336>>,{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                      And @@ Thread[Total /@ res <= 3000]



                      True




                      Up to ordering, res is the same as Henrik's resulttable:



                      Sort[res] == Sort[resulttable]



                      True




                      An alternative way to use IntegerPartitions using w:



                      res2 = DeleteCases[Rest@IntegerPartitions[3000, All, w], 1, 2];
                      Length@res2



                      1345




                      restab = Map[Lookup[Counts[#], Most @ w, 0] &] @ res2;
                      Sort[res] == Sort[restab]



                      True




                      To get the totals that can be obtained using vs:



                      Sort[DeleteDuplicates[res.Most[w]]] (* or *)
                      Sort[3000 - DeleteDuplicates@Rest[FrobeniusSolve[w, 3000]][[All, -1]]]



                      {140, 280, 420, 560, 700, 840, 980, 1120, 1260, 1400, 1540, 1680,
                      1820, 1960, 2100, 2240, 2380, 2520, 2660, 2800, 2940}




                      Sort @ Counts[res.Most[w]]



                      <|140 -> 1, 280 -> 2, 420 -> 3, 560 -> 5, 700 -> 7, 840 -> 10,
                      980 -> 13, 1120 -> 18, 1260 -> 23, 1400 -> 30, 1540 -> 37,
                      1680 -> 47, 1820 -> 57, 1960 -> 70, 2100 -> 84, 2240 -> 101,
                      2380 -> 119, 2520 -> 141, 2660 -> 164, 2800 -> 192, 2940 -> 221|>




                      Update: You can also use Reduce and Solve:



                      v = {v1, v2, v3, v4, v5};
                      xv = Array[x, 5];
                      resReduce = Reduce[{v.xv <= 3000, ##&@@Thread[xv >= 0]}, xv, Integers][[2;;, All, -1]] /.
                      {And | Or -> List};
                      resSolve = xv /. Rest@Solve[{v.xv <= 3000, ## & @@ Thread[xv >= 0]}, xv, Integers];
                      res == resReduce == resSolve



                      True







                      share|improve this answer











                      $endgroup$
















                        7












                        7








                        7





                        $begingroup$

                        Append 1 to the list of vs and use FrobeniusSolve:



                        w = {v1, v2, v3, v4, v5, 1};
                        res = FrobeniusSolve[w, 3000][[2;;, ;; 5]];
                        Length[res]



                        1345




                        Short @ res



                        {{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1336>>,{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                        And @@ Thread[Total /@ res <= 3000]



                        True




                        Up to ordering, res is the same as Henrik's resulttable:



                        Sort[res] == Sort[resulttable]



                        True




                        An alternative way to use IntegerPartitions using w:



                        res2 = DeleteCases[Rest@IntegerPartitions[3000, All, w], 1, 2];
                        Length@res2



                        1345




                        restab = Map[Lookup[Counts[#], Most @ w, 0] &] @ res2;
                        Sort[res] == Sort[restab]



                        True




                        To get the totals that can be obtained using vs:



                        Sort[DeleteDuplicates[res.Most[w]]] (* or *)
                        Sort[3000 - DeleteDuplicates@Rest[FrobeniusSolve[w, 3000]][[All, -1]]]



                        {140, 280, 420, 560, 700, 840, 980, 1120, 1260, 1400, 1540, 1680,
                        1820, 1960, 2100, 2240, 2380, 2520, 2660, 2800, 2940}




                        Sort @ Counts[res.Most[w]]



                        <|140 -> 1, 280 -> 2, 420 -> 3, 560 -> 5, 700 -> 7, 840 -> 10,
                        980 -> 13, 1120 -> 18, 1260 -> 23, 1400 -> 30, 1540 -> 37,
                        1680 -> 47, 1820 -> 57, 1960 -> 70, 2100 -> 84, 2240 -> 101,
                        2380 -> 119, 2520 -> 141, 2660 -> 164, 2800 -> 192, 2940 -> 221|>




                        Update: You can also use Reduce and Solve:



                        v = {v1, v2, v3, v4, v5};
                        xv = Array[x, 5];
                        resReduce = Reduce[{v.xv <= 3000, ##&@@Thread[xv >= 0]}, xv, Integers][[2;;, All, -1]] /.
                        {And | Or -> List};
                        resSolve = xv /. Rest@Solve[{v.xv <= 3000, ## & @@ Thread[xv >= 0]}, xv, Integers];
                        res == resReduce == resSolve



                        True







                        share|improve this answer











                        $endgroup$



                        Append 1 to the list of vs and use FrobeniusSolve:



                        w = {v1, v2, v3, v4, v5, 1};
                        res = FrobeniusSolve[w, 3000][[2;;, ;; 5]];
                        Length[res]



                        1345




                        Short @ res



                        {{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1336>>,{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                        And @@ Thread[Total /@ res <= 3000]



                        True




                        Up to ordering, res is the same as Henrik's resulttable:



                        Sort[res] == Sort[resulttable]



                        True




                        An alternative way to use IntegerPartitions using w:



                        res2 = DeleteCases[Rest@IntegerPartitions[3000, All, w], 1, 2];
                        Length@res2



                        1345




                        restab = Map[Lookup[Counts[#], Most @ w, 0] &] @ res2;
                        Sort[res] == Sort[restab]



                        True




                        To get the totals that can be obtained using vs:



                        Sort[DeleteDuplicates[res.Most[w]]] (* or *)
                        Sort[3000 - DeleteDuplicates@Rest[FrobeniusSolve[w, 3000]][[All, -1]]]



                        {140, 280, 420, 560, 700, 840, 980, 1120, 1260, 1400, 1540, 1680,
                        1820, 1960, 2100, 2240, 2380, 2520, 2660, 2800, 2940}




                        Sort @ Counts[res.Most[w]]



                        <|140 -> 1, 280 -> 2, 420 -> 3, 560 -> 5, 700 -> 7, 840 -> 10,
                        980 -> 13, 1120 -> 18, 1260 -> 23, 1400 -> 30, 1540 -> 37,
                        1680 -> 47, 1820 -> 57, 1960 -> 70, 2100 -> 84, 2240 -> 101,
                        2380 -> 119, 2520 -> 141, 2660 -> 164, 2800 -> 192, 2940 -> 221|>




                        Update: You can also use Reduce and Solve:



                        v = {v1, v2, v3, v4, v5};
                        xv = Array[x, 5];
                        resReduce = Reduce[{v.xv <= 3000, ##&@@Thread[xv >= 0]}, xv, Integers][[2;;, All, -1]] /.
                        {And | Or -> List};
                        resSolve = xv /. Rest@Solve[{v.xv <= 3000, ## & @@ Thread[xv >= 0]}, xv, Integers];
                        res == resReduce == resSolve



                        True








                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 22 at 14:35

























                        answered Jan 21 at 19:34









                        kglrkglr

                        181k10200413




                        181k10200413























                            4












                            $begingroup$

                            a = {140, 280, 420, 560, 700};
                            results = Join @@ DeleteCases[
                            IntegerPartitions[#, {1, ∞}, a] & /@ Range[3000],
                            {}
                            ];
                            And @@ Thread[Total /@ results <= 3000]
                            resulttable = Map[Lookup[Counts[#], a, 0] &, results];
                            resulttable // Short



                            True



                            {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, <<1341>> , {19, 1, 0, 0, 0}, {21, 0, 0, 0, 0}}







                            share|improve this answer











                            $endgroup$


















                              4












                              $begingroup$

                              a = {140, 280, 420, 560, 700};
                              results = Join @@ DeleteCases[
                              IntegerPartitions[#, {1, ∞}, a] & /@ Range[3000],
                              {}
                              ];
                              And @@ Thread[Total /@ results <= 3000]
                              resulttable = Map[Lookup[Counts[#], a, 0] &, results];
                              resulttable // Short



                              True



                              {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, <<1341>> , {19, 1, 0, 0, 0}, {21, 0, 0, 0, 0}}







                              share|improve this answer











                              $endgroup$
















                                4












                                4








                                4





                                $begingroup$

                                a = {140, 280, 420, 560, 700};
                                results = Join @@ DeleteCases[
                                IntegerPartitions[#, {1, ∞}, a] & /@ Range[3000],
                                {}
                                ];
                                And @@ Thread[Total /@ results <= 3000]
                                resulttable = Map[Lookup[Counts[#], a, 0] &, results];
                                resulttable // Short



                                True



                                {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, <<1341>> , {19, 1, 0, 0, 0}, {21, 0, 0, 0, 0}}







                                share|improve this answer











                                $endgroup$



                                a = {140, 280, 420, 560, 700};
                                results = Join @@ DeleteCases[
                                IntegerPartitions[#, {1, ∞}, a] & /@ Range[3000],
                                {}
                                ];
                                And @@ Thread[Total /@ results <= 3000]
                                resulttable = Map[Lookup[Counts[#], a, 0] &, results];
                                resulttable // Short



                                True



                                {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, <<1341>> , {19, 1, 0, 0, 0}, {21, 0, 0, 0, 0}}








                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jan 21 at 19:09

























                                answered Jan 21 at 18:41









                                Henrik SchumacherHenrik Schumacher

                                51.3k469146




                                51.3k469146























                                    3












                                    $begingroup$

                                    v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
                                    Select[Subsets[{v1, v2, v3, v4, v5}], Total[#] <= goal &]


                                    Are you sure your "goal" is 3000? Every subset totals less than that.



                                    And what does 21 * v1 in your question refer to? What is $21$, and why multiplication?






                                    share|improve this answer









                                    $endgroup$


















                                      3












                                      $begingroup$

                                      v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
                                      Select[Subsets[{v1, v2, v3, v4, v5}], Total[#] <= goal &]


                                      Are you sure your "goal" is 3000? Every subset totals less than that.



                                      And what does 21 * v1 in your question refer to? What is $21$, and why multiplication?






                                      share|improve this answer









                                      $endgroup$
















                                        3












                                        3








                                        3





                                        $begingroup$

                                        v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
                                        Select[Subsets[{v1, v2, v3, v4, v5}], Total[#] <= goal &]


                                        Are you sure your "goal" is 3000? Every subset totals less than that.



                                        And what does 21 * v1 in your question refer to? What is $21$, and why multiplication?






                                        share|improve this answer









                                        $endgroup$



                                        v1 = 140; v2 = 280; v3 = 420; v4 = 560; v5 = 700; goal = 3000;
                                        Select[Subsets[{v1, v2, v3, v4, v5}], Total[#] <= goal &]


                                        Are you sure your "goal" is 3000? Every subset totals less than that.



                                        And what does 21 * v1 in your question refer to? What is $21$, and why multiplication?







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jan 21 at 18:38









                                        David G. StorkDavid G. Stork

                                        24.2k22153




                                        24.2k22153























                                            3












                                            $begingroup$

                                            a = {140, 280, 420, 560, 700};
                                            coef = Tuples[Range[0, 21], 5];
                                            vec = coef.a;

                                            Extract[coef, Position[Ramp[vec - 3000], 0]] // Short



                                            {{0,0,0,0,0},{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1335>>,{18,1,0,0,0},{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                                            Pick[vec, Ramp[vec - 3000], 0] // Short



                                            {0,700,1400,2100,2800,560,1260,1960,2660,1120,1820,2520,1680,2380,<<1318>>,2940,2800,2380,2940,2800,2660,2940,2520,2940,2800,2660,2940,2800,2940}







                                            share|improve this answer









                                            $endgroup$


















                                              3












                                              $begingroup$

                                              a = {140, 280, 420, 560, 700};
                                              coef = Tuples[Range[0, 21], 5];
                                              vec = coef.a;

                                              Extract[coef, Position[Ramp[vec - 3000], 0]] // Short



                                              {{0,0,0,0,0},{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1335>>,{18,1,0,0,0},{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                                              Pick[vec, Ramp[vec - 3000], 0] // Short



                                              {0,700,1400,2100,2800,560,1260,1960,2660,1120,1820,2520,1680,2380,<<1318>>,2940,2800,2380,2940,2800,2660,2940,2520,2940,2800,2660,2940,2800,2940}







                                              share|improve this answer









                                              $endgroup$
















                                                3












                                                3








                                                3





                                                $begingroup$

                                                a = {140, 280, 420, 560, 700};
                                                coef = Tuples[Range[0, 21], 5];
                                                vec = coef.a;

                                                Extract[coef, Position[Ramp[vec - 3000], 0]] // Short



                                                {{0,0,0,0,0},{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1335>>,{18,1,0,0,0},{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                                                Pick[vec, Ramp[vec - 3000], 0] // Short



                                                {0,700,1400,2100,2800,560,1260,1960,2660,1120,1820,2520,1680,2380,<<1318>>,2940,2800,2380,2940,2800,2660,2940,2520,2940,2800,2660,2940,2800,2940}







                                                share|improve this answer









                                                $endgroup$



                                                a = {140, 280, 420, 560, 700};
                                                coef = Tuples[Range[0, 21], 5];
                                                vec = coef.a;

                                                Extract[coef, Position[Ramp[vec - 3000], 0]] // Short



                                                {{0,0,0,0,0},{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,3},{0,0,0,0,4},{0,0,0,1,0},<<1335>>,{18,1,0,0,0},{19,0,0,0,0},{19,1,0,0,0},{20,0,0,0,0},{21,0,0,0,0}}




                                                Pick[vec, Ramp[vec - 3000], 0] // Short



                                                {0,700,1400,2100,2800,560,1260,1960,2660,1120,1820,2520,1680,2380,<<1318>>,2940,2800,2380,2940,2800,2660,2940,2520,2940,2800,2660,2940,2800,2940}








                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Jan 21 at 19:45









                                                Okkes DulgerciOkkes Dulgerci

                                                4,5251817




                                                4,5251817























                                                    2












                                                    $begingroup$

                                                    Could use integer linear programming via Maximize, for example. The constraint I use is overkill, all we really need to enforce is that values be nonnegative.



                                                    vals = {140, 280, 420, 560, 700};
                                                    goal = 3000;
                                                    vars = Array[v, Length[vals]];
                                                    Maximize[{vars.vals,
                                                    Flatten[{vars.vals <= goal,
                                                    MapIndexed[0 <= # <= Floor[goal/vals[[#2[[1]]]]] &,
                                                    vars]}]}, vars, Integers]

                                                    (* Out[1287]= {2940, {v[1] -> 10, v[2] -> 4, v[3] -> 1,
                                                    v[4] -> 0, v[5] -> 0}} *)





                                                    share|improve this answer









                                                    $endgroup$


















                                                      2












                                                      $begingroup$

                                                      Could use integer linear programming via Maximize, for example. The constraint I use is overkill, all we really need to enforce is that values be nonnegative.



                                                      vals = {140, 280, 420, 560, 700};
                                                      goal = 3000;
                                                      vars = Array[v, Length[vals]];
                                                      Maximize[{vars.vals,
                                                      Flatten[{vars.vals <= goal,
                                                      MapIndexed[0 <= # <= Floor[goal/vals[[#2[[1]]]]] &,
                                                      vars]}]}, vars, Integers]

                                                      (* Out[1287]= {2940, {v[1] -> 10, v[2] -> 4, v[3] -> 1,
                                                      v[4] -> 0, v[5] -> 0}} *)





                                                      share|improve this answer









                                                      $endgroup$
















                                                        2












                                                        2








                                                        2





                                                        $begingroup$

                                                        Could use integer linear programming via Maximize, for example. The constraint I use is overkill, all we really need to enforce is that values be nonnegative.



                                                        vals = {140, 280, 420, 560, 700};
                                                        goal = 3000;
                                                        vars = Array[v, Length[vals]];
                                                        Maximize[{vars.vals,
                                                        Flatten[{vars.vals <= goal,
                                                        MapIndexed[0 <= # <= Floor[goal/vals[[#2[[1]]]]] &,
                                                        vars]}]}, vars, Integers]

                                                        (* Out[1287]= {2940, {v[1] -> 10, v[2] -> 4, v[3] -> 1,
                                                        v[4] -> 0, v[5] -> 0}} *)





                                                        share|improve this answer









                                                        $endgroup$



                                                        Could use integer linear programming via Maximize, for example. The constraint I use is overkill, all we really need to enforce is that values be nonnegative.



                                                        vals = {140, 280, 420, 560, 700};
                                                        goal = 3000;
                                                        vars = Array[v, Length[vals]];
                                                        Maximize[{vars.vals,
                                                        Flatten[{vars.vals <= goal,
                                                        MapIndexed[0 <= # <= Floor[goal/vals[[#2[[1]]]]] &,
                                                        vars]}]}, vars, Integers]

                                                        (* Out[1287]= {2940, {v[1] -> 10, v[2] -> 4, v[3] -> 1,
                                                        v[4] -> 0, v[5] -> 0}} *)






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Jan 22 at 15:42









                                                        Daniel LichtblauDaniel Lichtblau

                                                        46.8k276163




                                                        46.8k276163






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Mathematica Stack Exchange!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                            Use MathJax to format equations. MathJax reference.


                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189957%2fsum-of-list-numbers-smaller-than-one-goal%23new-answer', 'question_page');
                                                            }
                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            An IMO inspired problem

                                                            Management

                                                            Has there ever been an instance of an active nuclear power plant within or near a war zone?