Optimize my wings order

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
9
down vote

favorite
1












This tweet lists the possible orders for Wings of a Chinese restaurant1:



Wings menu



When ordering Pizza I usually calculate what size gives me the best Pizza-price ratio which is a simple calculation. However minimizing the price of an order at this restaurant isn't such a simple task, so I'd like to be prepared for my next order there.



Challenge



Given an integer greater or equal to $4$, your task is to return one possible order which minimizes the price (overall cheapest) and the number of deals.



Example



If I were to order $100$ Wings, it turns out the best bargain will cost $$111.20$. However there are multiple orders which will cost that amount, namely:



[50,50],[25,25,50],[25,25,25,25]


Since the first order will use the least amount of deals ($2$) the result will be [50,50].



Rules



  • Input will be some integer $n geq 4$

  • Output will be a list/array/... of order sizes that sum up to $n$ and minimize the order's price

    • you may choose to return all possible orders


Testcases



4 -> [4] (4.55)
23 -> [23] (26.10)
24 -> [6,18],[9,15],[12,12] (27.20)
31 -> [6,25] (34.60)
32 -> [4,28],[6,26],[7,25] (35.75)
33 -> [4,29],[5,28],[6,27],[7,26],[8,25] (36.90)
34 -> [6,28],[9,25] (38.00)
35 -> [35] (39.15)
125 -> [125,125] (139.00)
200 -> [25,50,125] (222.40)
201 -> [26,50,125] (223.55)
250 -> [125,125] (278.00)
251 -> [26,50,50,125] (279.15)
418 -> [15,28,125,125,125],[18,25,125,125,125] (465.20)
1001 -> [26,50,50,125,125,125,125,125,125,125] (1113.15)
12345 -> [15,80,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[25,70,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[45,50,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125] (13728.10)


Note: These testcases list all possible outputs including the price, you're only required to output one and you're not required to output the price!




1: You can find the data as a CSV here.










share|improve this question



















  • 1




    The real question is, who orders 200 or even 100 wings? ...
    – Erik the Outgolfer
    4 hours ago










  • Why the Kolmogorov-complexity tag? Also, very hungry people @EriktheOutgolfer
    – Veskah
    4 hours ago










  • Kolmogorov is all about fixed output though. If the challenge was to output the menu, then it'd be a good tag for this.
    – Veskah
    4 hours ago










  • @Veskah: It's not, it's about generating a fixed object (which often happens to be the output). For example the third challenge in the tag-wiki is not about constant output.
    – BMO
    4 hours ago






  • 1




    @Quintec: Why, do you need more testcases?
    – BMO
    3 hours ago














up vote
9
down vote

favorite
1












This tweet lists the possible orders for Wings of a Chinese restaurant1:



Wings menu



When ordering Pizza I usually calculate what size gives me the best Pizza-price ratio which is a simple calculation. However minimizing the price of an order at this restaurant isn't such a simple task, so I'd like to be prepared for my next order there.



Challenge



Given an integer greater or equal to $4$, your task is to return one possible order which minimizes the price (overall cheapest) and the number of deals.



Example



If I were to order $100$ Wings, it turns out the best bargain will cost $$111.20$. However there are multiple orders which will cost that amount, namely:



[50,50],[25,25,50],[25,25,25,25]


Since the first order will use the least amount of deals ($2$) the result will be [50,50].



Rules



  • Input will be some integer $n geq 4$

  • Output will be a list/array/... of order sizes that sum up to $n$ and minimize the order's price

    • you may choose to return all possible orders


Testcases



4 -> [4] (4.55)
23 -> [23] (26.10)
24 -> [6,18],[9,15],[12,12] (27.20)
31 -> [6,25] (34.60)
32 -> [4,28],[6,26],[7,25] (35.75)
33 -> [4,29],[5,28],[6,27],[7,26],[8,25] (36.90)
34 -> [6,28],[9,25] (38.00)
35 -> [35] (39.15)
125 -> [125,125] (139.00)
200 -> [25,50,125] (222.40)
201 -> [26,50,125] (223.55)
250 -> [125,125] (278.00)
251 -> [26,50,50,125] (279.15)
418 -> [15,28,125,125,125],[18,25,125,125,125] (465.20)
1001 -> [26,50,50,125,125,125,125,125,125,125] (1113.15)
12345 -> [15,80,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[25,70,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[45,50,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125] (13728.10)


Note: These testcases list all possible outputs including the price, you're only required to output one and you're not required to output the price!




1: You can find the data as a CSV here.










share|improve this question



















  • 1




    The real question is, who orders 200 or even 100 wings? ...
    – Erik the Outgolfer
    4 hours ago










  • Why the Kolmogorov-complexity tag? Also, very hungry people @EriktheOutgolfer
    – Veskah
    4 hours ago










  • Kolmogorov is all about fixed output though. If the challenge was to output the menu, then it'd be a good tag for this.
    – Veskah
    4 hours ago










  • @Veskah: It's not, it's about generating a fixed object (which often happens to be the output). For example the third challenge in the tag-wiki is not about constant output.
    – BMO
    4 hours ago






  • 1




    @Quintec: Why, do you need more testcases?
    – BMO
    3 hours ago












up vote
9
down vote

favorite
1









up vote
9
down vote

favorite
1






1





This tweet lists the possible orders for Wings of a Chinese restaurant1:



Wings menu



When ordering Pizza I usually calculate what size gives me the best Pizza-price ratio which is a simple calculation. However minimizing the price of an order at this restaurant isn't such a simple task, so I'd like to be prepared for my next order there.



Challenge



Given an integer greater or equal to $4$, your task is to return one possible order which minimizes the price (overall cheapest) and the number of deals.



Example



If I were to order $100$ Wings, it turns out the best bargain will cost $$111.20$. However there are multiple orders which will cost that amount, namely:



[50,50],[25,25,50],[25,25,25,25]


Since the first order will use the least amount of deals ($2$) the result will be [50,50].



Rules



  • Input will be some integer $n geq 4$

  • Output will be a list/array/... of order sizes that sum up to $n$ and minimize the order's price

    • you may choose to return all possible orders


Testcases



4 -> [4] (4.55)
23 -> [23] (26.10)
24 -> [6,18],[9,15],[12,12] (27.20)
31 -> [6,25] (34.60)
32 -> [4,28],[6,26],[7,25] (35.75)
33 -> [4,29],[5,28],[6,27],[7,26],[8,25] (36.90)
34 -> [6,28],[9,25] (38.00)
35 -> [35] (39.15)
125 -> [125,125] (139.00)
200 -> [25,50,125] (222.40)
201 -> [26,50,125] (223.55)
250 -> [125,125] (278.00)
251 -> [26,50,50,125] (279.15)
418 -> [15,28,125,125,125],[18,25,125,125,125] (465.20)
1001 -> [26,50,50,125,125,125,125,125,125,125] (1113.15)
12345 -> [15,80,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[25,70,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[45,50,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125] (13728.10)


Note: These testcases list all possible outputs including the price, you're only required to output one and you're not required to output the price!




1: You can find the data as a CSV here.










share|improve this question















This tweet lists the possible orders for Wings of a Chinese restaurant1:



Wings menu



When ordering Pizza I usually calculate what size gives me the best Pizza-price ratio which is a simple calculation. However minimizing the price of an order at this restaurant isn't such a simple task, so I'd like to be prepared for my next order there.



Challenge



Given an integer greater or equal to $4$, your task is to return one possible order which minimizes the price (overall cheapest) and the number of deals.



Example



If I were to order $100$ Wings, it turns out the best bargain will cost $$111.20$. However there are multiple orders which will cost that amount, namely:



[50,50],[25,25,50],[25,25,25,25]


Since the first order will use the least amount of deals ($2$) the result will be [50,50].



Rules



  • Input will be some integer $n geq 4$

  • Output will be a list/array/... of order sizes that sum up to $n$ and minimize the order's price

    • you may choose to return all possible orders


Testcases



4 -> [4] (4.55)
23 -> [23] (26.10)
24 -> [6,18],[9,15],[12,12] (27.20)
31 -> [6,25] (34.60)
32 -> [4,28],[6,26],[7,25] (35.75)
33 -> [4,29],[5,28],[6,27],[7,26],[8,25] (36.90)
34 -> [6,28],[9,25] (38.00)
35 -> [35] (39.15)
125 -> [125,125] (139.00)
200 -> [25,50,125] (222.40)
201 -> [26,50,125] (223.55)
250 -> [125,125] (278.00)
251 -> [26,50,50,125] (279.15)
418 -> [15,28,125,125,125],[18,25,125,125,125] (465.20)
1001 -> [26,50,50,125,125,125,125,125,125,125] (1113.15)
12345 -> [15,80,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[25,70,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125],[45,50,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125] (13728.10)


Note: These testcases list all possible outputs including the price, you're only required to output one and you're not required to output the price!




1: You can find the data as a CSV here.







code-golf optimization integer-partitions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago

























asked 5 hours ago









BMO

10.3k21877




10.3k21877







  • 1




    The real question is, who orders 200 or even 100 wings? ...
    – Erik the Outgolfer
    4 hours ago










  • Why the Kolmogorov-complexity tag? Also, very hungry people @EriktheOutgolfer
    – Veskah
    4 hours ago










  • Kolmogorov is all about fixed output though. If the challenge was to output the menu, then it'd be a good tag for this.
    – Veskah
    4 hours ago










  • @Veskah: It's not, it's about generating a fixed object (which often happens to be the output). For example the third challenge in the tag-wiki is not about constant output.
    – BMO
    4 hours ago






  • 1




    @Quintec: Why, do you need more testcases?
    – BMO
    3 hours ago












  • 1




    The real question is, who orders 200 or even 100 wings? ...
    – Erik the Outgolfer
    4 hours ago










  • Why the Kolmogorov-complexity tag? Also, very hungry people @EriktheOutgolfer
    – Veskah
    4 hours ago










  • Kolmogorov is all about fixed output though. If the challenge was to output the menu, then it'd be a good tag for this.
    – Veskah
    4 hours ago










  • @Veskah: It's not, it's about generating a fixed object (which often happens to be the output). For example the third challenge in the tag-wiki is not about constant output.
    – BMO
    4 hours ago






  • 1




    @Quintec: Why, do you need more testcases?
    – BMO
    3 hours ago







1




1




The real question is, who orders 200 or even 100 wings? ...
– Erik the Outgolfer
4 hours ago




The real question is, who orders 200 or even 100 wings? ...
– Erik the Outgolfer
4 hours ago












Why the Kolmogorov-complexity tag? Also, very hungry people @EriktheOutgolfer
– Veskah
4 hours ago




Why the Kolmogorov-complexity tag? Also, very hungry people @EriktheOutgolfer
– Veskah
4 hours ago












Kolmogorov is all about fixed output though. If the challenge was to output the menu, then it'd be a good tag for this.
– Veskah
4 hours ago




Kolmogorov is all about fixed output though. If the challenge was to output the menu, then it'd be a good tag for this.
– Veskah
4 hours ago












@Veskah: It's not, it's about generating a fixed object (which often happens to be the output). For example the third challenge in the tag-wiki is not about constant output.
– BMO
4 hours ago




@Veskah: It's not, it's about generating a fixed object (which often happens to be the output). For example the third challenge in the tag-wiki is not about constant output.
– BMO
4 hours ago




1




1




@Quintec: Why, do you need more testcases?
– BMO
3 hours ago




@Quintec: Why, do you need more testcases?
– BMO
3 hours ago










1 Answer
1






active

oldest

votes

















up vote
4
down vote













JavaScript (ES6), 123 bytes



Returns the order as a space-separated string.





f=n=>n?(x=n>128|n==125?125:n>50?n<54?25:n-70?302256705>>n-80&n>79&n<109?80:50:n:n-24&&n-49?n<31|n%5<1?n:25:9)+' '+f(n-x):''


Try it online!



How?



Given a number $n$ of wings, we recursively apply the following strategy.



High values: $n>128$ or $n=125$



For high values, our best option is to buy $125$ wings. So that's what we're doing as long as $n$ is greater than or equal to $129$ or when $n$ is exactly equal to $125$.



We can't do that for $125 < n < 129$ because we'd be left with less than $4$ wings to buy, which is not possible.



Low values: $n<31$



For $n<31$, the best deal is to buy all remaining wings at once, except for $n=24$ which must be purchased as either $2times 12$, $18+6$ or $15+9$. We arbitrarily buy $9$ wings in that case.



Range $31 le n le 50$



In this range, buying $25$ wings usually leads to an optimal order. But the following exceptions apply:



  • If $n$ is a multiple of $5$, we must buy all remaining wings at once.

  • If $n=49$, the best deals are $40+9$ and $28+21$. We arbitrarily buy $9$ wings in that case.

Range $51 le n le 53$



We can't buy $50$ wings in that range or we'll be left with less than $4$ wings. Our best option is to buy $25$ of them instead. (We could buy $2times26$ wings for $n=52$, but buying $25+27$ is just as good.)



Range $54 le n le 128$ with $n neq 125$



In this range, buying $50$ wings usually leads to an optimal order. But the following exceptions apply:



  • If $n=70$, we must buy all of them at once.


  • If $n$ is in $80,86,89,92,98,105,108$, we must buy $80$ wings. These values are encoded with the following bitmask, where the least significant bit is mapped to $80$ and the most significant one to $108$:



    $$10010000001000001001001000001_(2) = 302256705_(10)$$







share|improve this answer






















    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.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "200"
    ;
    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174808%2foptimize-my-wings-order%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote













    JavaScript (ES6), 123 bytes



    Returns the order as a space-separated string.





    f=n=>n?(x=n>128|n==125?125:n>50?n<54?25:n-70?302256705>>n-80&n>79&n<109?80:50:n:n-24&&n-49?n<31|n%5<1?n:25:9)+' '+f(n-x):''


    Try it online!



    How?



    Given a number $n$ of wings, we recursively apply the following strategy.



    High values: $n>128$ or $n=125$



    For high values, our best option is to buy $125$ wings. So that's what we're doing as long as $n$ is greater than or equal to $129$ or when $n$ is exactly equal to $125$.



    We can't do that for $125 < n < 129$ because we'd be left with less than $4$ wings to buy, which is not possible.



    Low values: $n<31$



    For $n<31$, the best deal is to buy all remaining wings at once, except for $n=24$ which must be purchased as either $2times 12$, $18+6$ or $15+9$. We arbitrarily buy $9$ wings in that case.



    Range $31 le n le 50$



    In this range, buying $25$ wings usually leads to an optimal order. But the following exceptions apply:



    • If $n$ is a multiple of $5$, we must buy all remaining wings at once.

    • If $n=49$, the best deals are $40+9$ and $28+21$. We arbitrarily buy $9$ wings in that case.

    Range $51 le n le 53$



    We can't buy $50$ wings in that range or we'll be left with less than $4$ wings. Our best option is to buy $25$ of them instead. (We could buy $2times26$ wings for $n=52$, but buying $25+27$ is just as good.)



    Range $54 le n le 128$ with $n neq 125$



    In this range, buying $50$ wings usually leads to an optimal order. But the following exceptions apply:



    • If $n=70$, we must buy all of them at once.


    • If $n$ is in $80,86,89,92,98,105,108$, we must buy $80$ wings. These values are encoded with the following bitmask, where the least significant bit is mapped to $80$ and the most significant one to $108$:



      $$10010000001000001001001000001_(2) = 302256705_(10)$$







    share|improve this answer


























      up vote
      4
      down vote













      JavaScript (ES6), 123 bytes



      Returns the order as a space-separated string.





      f=n=>n?(x=n>128|n==125?125:n>50?n<54?25:n-70?302256705>>n-80&n>79&n<109?80:50:n:n-24&&n-49?n<31|n%5<1?n:25:9)+' '+f(n-x):''


      Try it online!



      How?



      Given a number $n$ of wings, we recursively apply the following strategy.



      High values: $n>128$ or $n=125$



      For high values, our best option is to buy $125$ wings. So that's what we're doing as long as $n$ is greater than or equal to $129$ or when $n$ is exactly equal to $125$.



      We can't do that for $125 < n < 129$ because we'd be left with less than $4$ wings to buy, which is not possible.



      Low values: $n<31$



      For $n<31$, the best deal is to buy all remaining wings at once, except for $n=24$ which must be purchased as either $2times 12$, $18+6$ or $15+9$. We arbitrarily buy $9$ wings in that case.



      Range $31 le n le 50$



      In this range, buying $25$ wings usually leads to an optimal order. But the following exceptions apply:



      • If $n$ is a multiple of $5$, we must buy all remaining wings at once.

      • If $n=49$, the best deals are $40+9$ and $28+21$. We arbitrarily buy $9$ wings in that case.

      Range $51 le n le 53$



      We can't buy $50$ wings in that range or we'll be left with less than $4$ wings. Our best option is to buy $25$ of them instead. (We could buy $2times26$ wings for $n=52$, but buying $25+27$ is just as good.)



      Range $54 le n le 128$ with $n neq 125$



      In this range, buying $50$ wings usually leads to an optimal order. But the following exceptions apply:



      • If $n=70$, we must buy all of them at once.


      • If $n$ is in $80,86,89,92,98,105,108$, we must buy $80$ wings. These values are encoded with the following bitmask, where the least significant bit is mapped to $80$ and the most significant one to $108$:



        $$10010000001000001001001000001_(2) = 302256705_(10)$$







      share|improve this answer
























        up vote
        4
        down vote










        up vote
        4
        down vote









        JavaScript (ES6), 123 bytes



        Returns the order as a space-separated string.





        f=n=>n?(x=n>128|n==125?125:n>50?n<54?25:n-70?302256705>>n-80&n>79&n<109?80:50:n:n-24&&n-49?n<31|n%5<1?n:25:9)+' '+f(n-x):''


        Try it online!



        How?



        Given a number $n$ of wings, we recursively apply the following strategy.



        High values: $n>128$ or $n=125$



        For high values, our best option is to buy $125$ wings. So that's what we're doing as long as $n$ is greater than or equal to $129$ or when $n$ is exactly equal to $125$.



        We can't do that for $125 < n < 129$ because we'd be left with less than $4$ wings to buy, which is not possible.



        Low values: $n<31$



        For $n<31$, the best deal is to buy all remaining wings at once, except for $n=24$ which must be purchased as either $2times 12$, $18+6$ or $15+9$. We arbitrarily buy $9$ wings in that case.



        Range $31 le n le 50$



        In this range, buying $25$ wings usually leads to an optimal order. But the following exceptions apply:



        • If $n$ is a multiple of $5$, we must buy all remaining wings at once.

        • If $n=49$, the best deals are $40+9$ and $28+21$. We arbitrarily buy $9$ wings in that case.

        Range $51 le n le 53$



        We can't buy $50$ wings in that range or we'll be left with less than $4$ wings. Our best option is to buy $25$ of them instead. (We could buy $2times26$ wings for $n=52$, but buying $25+27$ is just as good.)



        Range $54 le n le 128$ with $n neq 125$



        In this range, buying $50$ wings usually leads to an optimal order. But the following exceptions apply:



        • If $n=70$, we must buy all of them at once.


        • If $n$ is in $80,86,89,92,98,105,108$, we must buy $80$ wings. These values are encoded with the following bitmask, where the least significant bit is mapped to $80$ and the most significant one to $108$:



          $$10010000001000001001001000001_(2) = 302256705_(10)$$







        share|improve this answer














        JavaScript (ES6), 123 bytes



        Returns the order as a space-separated string.





        f=n=>n?(x=n>128|n==125?125:n>50?n<54?25:n-70?302256705>>n-80&n>79&n<109?80:50:n:n-24&&n-49?n<31|n%5<1?n:25:9)+' '+f(n-x):''


        Try it online!



        How?



        Given a number $n$ of wings, we recursively apply the following strategy.



        High values: $n>128$ or $n=125$



        For high values, our best option is to buy $125$ wings. So that's what we're doing as long as $n$ is greater than or equal to $129$ or when $n$ is exactly equal to $125$.



        We can't do that for $125 < n < 129$ because we'd be left with less than $4$ wings to buy, which is not possible.



        Low values: $n<31$



        For $n<31$, the best deal is to buy all remaining wings at once, except for $n=24$ which must be purchased as either $2times 12$, $18+6$ or $15+9$. We arbitrarily buy $9$ wings in that case.



        Range $31 le n le 50$



        In this range, buying $25$ wings usually leads to an optimal order. But the following exceptions apply:



        • If $n$ is a multiple of $5$, we must buy all remaining wings at once.

        • If $n=49$, the best deals are $40+9$ and $28+21$. We arbitrarily buy $9$ wings in that case.

        Range $51 le n le 53$



        We can't buy $50$ wings in that range or we'll be left with less than $4$ wings. Our best option is to buy $25$ of them instead. (We could buy $2times26$ wings for $n=52$, but buying $25+27$ is just as good.)



        Range $54 le n le 128$ with $n neq 125$



        In this range, buying $50$ wings usually leads to an optimal order. But the following exceptions apply:



        • If $n=70$, we must buy all of them at once.


        • If $n$ is in $80,86,89,92,98,105,108$, we must buy $80$ wings. These values are encoded with the following bitmask, where the least significant bit is mapped to $80$ and the most significant one to $108$:



          $$10010000001000001001001000001_(2) = 302256705_(10)$$








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 1 hour ago

























        answered 3 hours ago









        Arnauld

        67k584282




        67k584282



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174808%2foptimize-my-wings-order%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery