How much candy can you eat?











up vote
6
down vote

favorite












Credit to Geobits in TNB for the idea



A post without sufficient detail recently posited an interesting game:



2 children sit in front of an array of candy. Each piece of candy is numbered 1 to x, with x being the total amount of candy present. There is exactly 1 occurrence of each number.



The goal of the game is for the children to eat candy and multiply the values of the candy they have eaten to arrive at a final score, with the higher score winning.



However the original post missed key information, such as how candy is selected, so the kids in our story decided that the older kid gets to go first, and can eat up to half the candy, however once he announces the end of his turn, he can't change his mind.



One of the kids in this game doesn't like candy, so he wants to eat as little as possible, and he once watched his dad write some code once, and figures he can use the skills gained from that to work out how much candy he needs to eat to ensure victory, whilst still eating as little as possible.



The Challenge



Given the total number of candy x, your program or function should output the smallest amount of candy he has to eat to ensure victory, n, even if his opponent eats all the remaining candy.



Naturally bigger numbers make bigger numbers, so whatever amount you'll give him, he'll eat the n largest numbers.



The Rules





  • x will always be in the range 0 < x! <= l where l is the upper limit of your language's number handling capabilities

  • It is guaranteed that the kid will always eat the n largest numbers, for example for x = 5 and n = 2, he will eat 4 and 5


Test cases



x = 2
n = 1
(2 > 1)

x = 4
n = 2
(3 * 4 == 12 > 1 * 2 == 2)

x = 5
n = 2
(4 * 5 == 20 > 1 * 2 * 3 == 6)

x = 100
n = 42
(product([59..100]) > product([1..58]))

x = 500
n = 220
(product([281..500]) > product([1..280]))


Scoring



Unfortunately, our brave contestant has nothing to write his code with, so he has to arrange the pieces of candy into the characters of the code, as a result, your code needs to be as small as possible, smallest code in bytes wins!










share|improve this question




















  • 2




    How much candy can I eat? All of it. All of the candy.
    – AdmBorkBork
    6 hours ago










  • New title: "How much candy need you eat?"
    – Sparr
    5 hours ago






  • 1




    It looks like x=1 must be handled, could you confirm (since it's an edge case which should result in 1 rather than 0 or infinite loop as a couple of answers do)
    – Jonathan Allan
    4 hours ago












  • @JonathanAllan yes, x=1 must be handled, as it is within the bounds of 0 < x! <= l (because 1! is 1, which is greater than 0)
    – Skidsdev
    4 hours ago

















up vote
6
down vote

favorite












Credit to Geobits in TNB for the idea



A post without sufficient detail recently posited an interesting game:



2 children sit in front of an array of candy. Each piece of candy is numbered 1 to x, with x being the total amount of candy present. There is exactly 1 occurrence of each number.



The goal of the game is for the children to eat candy and multiply the values of the candy they have eaten to arrive at a final score, with the higher score winning.



However the original post missed key information, such as how candy is selected, so the kids in our story decided that the older kid gets to go first, and can eat up to half the candy, however once he announces the end of his turn, he can't change his mind.



One of the kids in this game doesn't like candy, so he wants to eat as little as possible, and he once watched his dad write some code once, and figures he can use the skills gained from that to work out how much candy he needs to eat to ensure victory, whilst still eating as little as possible.



The Challenge



Given the total number of candy x, your program or function should output the smallest amount of candy he has to eat to ensure victory, n, even if his opponent eats all the remaining candy.



Naturally bigger numbers make bigger numbers, so whatever amount you'll give him, he'll eat the n largest numbers.



The Rules





  • x will always be in the range 0 < x! <= l where l is the upper limit of your language's number handling capabilities

  • It is guaranteed that the kid will always eat the n largest numbers, for example for x = 5 and n = 2, he will eat 4 and 5


Test cases



x = 2
n = 1
(2 > 1)

x = 4
n = 2
(3 * 4 == 12 > 1 * 2 == 2)

x = 5
n = 2
(4 * 5 == 20 > 1 * 2 * 3 == 6)

x = 100
n = 42
(product([59..100]) > product([1..58]))

x = 500
n = 220
(product([281..500]) > product([1..280]))


Scoring



Unfortunately, our brave contestant has nothing to write his code with, so he has to arrange the pieces of candy into the characters of the code, as a result, your code needs to be as small as possible, smallest code in bytes wins!










share|improve this question




















  • 2




    How much candy can I eat? All of it. All of the candy.
    – AdmBorkBork
    6 hours ago










  • New title: "How much candy need you eat?"
    – Sparr
    5 hours ago






  • 1




    It looks like x=1 must be handled, could you confirm (since it's an edge case which should result in 1 rather than 0 or infinite loop as a couple of answers do)
    – Jonathan Allan
    4 hours ago












  • @JonathanAllan yes, x=1 must be handled, as it is within the bounds of 0 < x! <= l (because 1! is 1, which is greater than 0)
    – Skidsdev
    4 hours ago















up vote
6
down vote

favorite









up vote
6
down vote

favorite











Credit to Geobits in TNB for the idea



A post without sufficient detail recently posited an interesting game:



2 children sit in front of an array of candy. Each piece of candy is numbered 1 to x, with x being the total amount of candy present. There is exactly 1 occurrence of each number.



The goal of the game is for the children to eat candy and multiply the values of the candy they have eaten to arrive at a final score, with the higher score winning.



However the original post missed key information, such as how candy is selected, so the kids in our story decided that the older kid gets to go first, and can eat up to half the candy, however once he announces the end of his turn, he can't change his mind.



One of the kids in this game doesn't like candy, so he wants to eat as little as possible, and he once watched his dad write some code once, and figures he can use the skills gained from that to work out how much candy he needs to eat to ensure victory, whilst still eating as little as possible.



The Challenge



Given the total number of candy x, your program or function should output the smallest amount of candy he has to eat to ensure victory, n, even if his opponent eats all the remaining candy.



Naturally bigger numbers make bigger numbers, so whatever amount you'll give him, he'll eat the n largest numbers.



The Rules





  • x will always be in the range 0 < x! <= l where l is the upper limit of your language's number handling capabilities

  • It is guaranteed that the kid will always eat the n largest numbers, for example for x = 5 and n = 2, he will eat 4 and 5


Test cases



x = 2
n = 1
(2 > 1)

x = 4
n = 2
(3 * 4 == 12 > 1 * 2 == 2)

x = 5
n = 2
(4 * 5 == 20 > 1 * 2 * 3 == 6)

x = 100
n = 42
(product([59..100]) > product([1..58]))

x = 500
n = 220
(product([281..500]) > product([1..280]))


Scoring



Unfortunately, our brave contestant has nothing to write his code with, so he has to arrange the pieces of candy into the characters of the code, as a result, your code needs to be as small as possible, smallest code in bytes wins!










share|improve this question















Credit to Geobits in TNB for the idea



A post without sufficient detail recently posited an interesting game:



2 children sit in front of an array of candy. Each piece of candy is numbered 1 to x, with x being the total amount of candy present. There is exactly 1 occurrence of each number.



The goal of the game is for the children to eat candy and multiply the values of the candy they have eaten to arrive at a final score, with the higher score winning.



However the original post missed key information, such as how candy is selected, so the kids in our story decided that the older kid gets to go first, and can eat up to half the candy, however once he announces the end of his turn, he can't change his mind.



One of the kids in this game doesn't like candy, so he wants to eat as little as possible, and he once watched his dad write some code once, and figures he can use the skills gained from that to work out how much candy he needs to eat to ensure victory, whilst still eating as little as possible.



The Challenge



Given the total number of candy x, your program or function should output the smallest amount of candy he has to eat to ensure victory, n, even if his opponent eats all the remaining candy.



Naturally bigger numbers make bigger numbers, so whatever amount you'll give him, he'll eat the n largest numbers.



The Rules





  • x will always be in the range 0 < x! <= l where l is the upper limit of your language's number handling capabilities

  • It is guaranteed that the kid will always eat the n largest numbers, for example for x = 5 and n = 2, he will eat 4 and 5


Test cases



x = 2
n = 1
(2 > 1)

x = 4
n = 2
(3 * 4 == 12 > 1 * 2 == 2)

x = 5
n = 2
(4 * 5 == 20 > 1 * 2 * 3 == 6)

x = 100
n = 42
(product([59..100]) > product([1..58]))

x = 500
n = 220
(product([281..500]) > product([1..280]))


Scoring



Unfortunately, our brave contestant has nothing to write his code with, so he has to arrange the pieces of candy into the characters of the code, as a result, your code needs to be as small as possible, smallest code in bytes wins!







code-golf arithmetic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 hours ago

























asked 6 hours ago









Skidsdev

6,1982870




6,1982870








  • 2




    How much candy can I eat? All of it. All of the candy.
    – AdmBorkBork
    6 hours ago










  • New title: "How much candy need you eat?"
    – Sparr
    5 hours ago






  • 1




    It looks like x=1 must be handled, could you confirm (since it's an edge case which should result in 1 rather than 0 or infinite loop as a couple of answers do)
    – Jonathan Allan
    4 hours ago












  • @JonathanAllan yes, x=1 must be handled, as it is within the bounds of 0 < x! <= l (because 1! is 1, which is greater than 0)
    – Skidsdev
    4 hours ago
















  • 2




    How much candy can I eat? All of it. All of the candy.
    – AdmBorkBork
    6 hours ago










  • New title: "How much candy need you eat?"
    – Sparr
    5 hours ago






  • 1




    It looks like x=1 must be handled, could you confirm (since it's an edge case which should result in 1 rather than 0 or infinite loop as a couple of answers do)
    – Jonathan Allan
    4 hours ago












  • @JonathanAllan yes, x=1 must be handled, as it is within the bounds of 0 < x! <= l (because 1! is 1, which is greater than 0)
    – Skidsdev
    4 hours ago










2




2




How much candy can I eat? All of it. All of the candy.
– AdmBorkBork
6 hours ago




How much candy can I eat? All of it. All of the candy.
– AdmBorkBork
6 hours ago












New title: "How much candy need you eat?"
– Sparr
5 hours ago




New title: "How much candy need you eat?"
– Sparr
5 hours ago




1




1




It looks like x=1 must be handled, could you confirm (since it's an edge case which should result in 1 rather than 0 or infinite loop as a couple of answers do)
– Jonathan Allan
4 hours ago






It looks like x=1 must be handled, could you confirm (since it's an edge case which should result in 1 rather than 0 or infinite loop as a couple of answers do)
– Jonathan Allan
4 hours ago














@JonathanAllan yes, x=1 must be handled, as it is within the bounds of 0 < x! <= l (because 1! is 1, which is greater than 0)
– Skidsdev
4 hours ago






@JonathanAllan yes, x=1 must be handled, as it is within the bounds of 0 < x! <= l (because 1! is 1, which is greater than 0)
– Skidsdev
4 hours ago












8 Answers
8






active

oldest

votes

















up vote
3
down vote














Python 3, 76 bytes





F=lambda x:x<2or x*F(x-1)
f=lambda x,n=1:x<2or n*(F(x)>F(x-n)**2)or f(x,n+1)


Try it online!



Relies on the fact that for eating $n$ candies to still win and the total number of candies being $x$, $frac{x!}{(x-n)!}>(x-n)!$ must be true, which means $x!>((x-n)!)^2$.



-1 from Skidsdev



-3 -6 from BMO



-3 from Sparr



+6 to fix x = 1






share|improve this answer



















  • 1




    You can save 1 byte by replacing the top function with from math import factorial as F
    – Skidsdev
    5 hours ago






  • 1




    You can rewrite these recursion using short-circuiting behaviour, eg. for the second one: n*(F(x)>F(x-n)**2)or f(x,n+1). Similarly x<2or x*F(x-1) for the first one which is shorter than the import.
    – BMO
    5 hours ago








  • 1




    All three of those are nice suggestions, thanks. (And added)
    – nedla2004
    5 hours ago






  • 1




    -3 bytes with import math;F=math.factorial which I should probably go find the python tips meta to mention...
    – Sparr
    5 hours ago








  • 2




    @Sparr: But F=lambda x:x<2or x*F(x-1) is three bytes less?
    – BMO
    5 hours ago




















up vote
1
down vote














Haskell, 52 51 bytes



Using the straightforward approach: We check whether the product of the last $n$ numbers, which is $frac{x!}{(x-n)!}$ is less than the product of the first $n$ numbers, namely $(x-n)!$ and takes the least $n$ for which this is true.





g b=product[1..b]
f x=[n|n<-[1..],g(x-n)^2<=g x]!!0


Try it online!






share|improve this answer






























    up vote
    1
    down vote














    Clean, 57 bytes



    import StdEnv
    $x=while(e=prod[1..x-e]^2>prod[1..x])inc 1


    Try it online!



    A straight-forward solution.






    share|improve this answer






























      up vote
      1
      down vote














      Jelly, 9 bytes



      ḊPÐƤ<!€TL


      Try it online! Or see the test-suite.



      How?



      ḊPÐƤ<!€TL - Link: integer, x                   e.g. 7
      Ḋ - dequeue (implicit range of x) [ 2, 3, 4, 5, 6, 7]
      ÐƤ - for postfixes [all, allButFirst, ...]:
      P - product [5040,2520, 840, 210, 42, 7]
      € - for each (in implicit range of x):
      ! - factorial [ 1, 2, 6, 24, 120, 720, 5040]
      < - (left) less than (right)? [ 0, 0, 0, 0, 1, 1, 5040]
      - -- note right always 1 longer than left giving trailing x! like the 5040 ^
      T - truthy indices [ 5, 6, 7 ]
      L - length 3





      share|improve this answer























      • that's impressive but would be more educative if explained
        – Setop
        4 hours ago










      • It will be... :)
        – Jonathan Allan
        4 hours ago










      • @Setop - added.
        – Jonathan Allan
        4 hours ago










      • like it ! and it must be fast compare to all solutions with tons of factorials
        – Setop
        4 hours ago










      • Nah, still calculates all those products and factorials (more than some other solutions).
        – Jonathan Allan
        3 hours ago


















      up vote
      1
      down vote














      Python 3, 183 176 bytes





      R=reversed
      L=list
      def M(I):
      r=1
      for i in I:
      r*=i
      yield r
      def f(x):
      S=L(range(1,x+1))
      for(n,a,b)in zip([0]+S,R(L(M(S))),[0]+L(M(R(S)))):
      if(b>a):
      return n
      return x


      Try it online!



      It's is a lot faster than some other solutions - 0(N) multiplications instead of O(N²) - but I can't manage to reduce code size.






      share|improve this answer






























        up vote
        0
        down vote














        Jelly, 14 bytes



        ạ‘rP>ạ!¥
        1ç1#«


        Try it online!



        Handles 1 correctly.






        share|improve this answer




























          up vote
          0
          down vote













          JavaScript (ES6), 53 bytes





          n=>(g=p=>x<n?g(p*++x):q<p&&1+g(p/n,q*=n--))(q=x=1)||n


          Try it online!



          Works up to $a(170)$. Beyond that, we'd need BigInts (+1 byte).



          How?



          We start with $p=n!$ and $q=1$.



          You can think of $q$ as the product of our candies and of $p$ as the product of the candies of the other kid. (So at the beginning of the process, the other kid has all the candies and we have none.)



          Then we repeat the following operations:




          • divide $p$ by $n$

          • multiply $q$ by $n$

          • decrement $n$


          until $qge p$.



          The result is the number of required iterations. (At each iteration, we 'take the next highest candy from the other kid'.)



          Commented



          This is implemented as a single recursive function which first compute $n!$ and then enters the loop described above.



          n => (           // main function taking n
          g = p => // g = recursive function taking p
          x < n ? // if x is less than n:
          g( // this is the first part of the recursion:
          p * ++x // we're computing p = n! by multiplying p
          ) // by x = 1 .. n
          : // else (second part):
          q < p && // while q is less than p:
          1 + g( // add 1 to the final result
          p / n, // divide p by n
          q *= n-- // multiply q by n; decrement n
          ) //
          )(q = x = 1) // initial call to g with p = q = x = 1
          || n // edge cases: return n for n < 2





          share|improve this answer






























            up vote
            0
            down vote














            05AB1E, 15 bytes



            EI!IN-!n›Ði–#]1


            Try it online!



            EI!IN-!n›Ði–#]1

            E For loop with N from [1 ... input]
            I! Push factorial of input
            IN- Push input - N (x - n)
            ! Factorial
            n Square
            › Push input! > (input - N)^2 or x! > (x - n)^2
            Ð Triplicate, used for three upcoming operations (if, print, end)
            i If, run code after if top of stack is 1 (found minimum number of candies)
            – Print N if top of stack is 1
            #] Ends for loop and program is top of stack is 1
            1 Pushes 1 so that if the input is 1 and we leave the for loop without
            printing anything 1 is printed


            Uses the same approach as my Python submission. Very new to 05AB1E so any tips on code or explaination greatly appreciated.






            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: 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%2fcodegolf.stackexchange.com%2fquestions%2f177495%2fhow-much-candy-can-you-eat%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              8 Answers
              8






              active

              oldest

              votes








              8 Answers
              8






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote














              Python 3, 76 bytes





              F=lambda x:x<2or x*F(x-1)
              f=lambda x,n=1:x<2or n*(F(x)>F(x-n)**2)or f(x,n+1)


              Try it online!



              Relies on the fact that for eating $n$ candies to still win and the total number of candies being $x$, $frac{x!}{(x-n)!}>(x-n)!$ must be true, which means $x!>((x-n)!)^2$.



              -1 from Skidsdev



              -3 -6 from BMO



              -3 from Sparr



              +6 to fix x = 1






              share|improve this answer



















              • 1




                You can save 1 byte by replacing the top function with from math import factorial as F
                – Skidsdev
                5 hours ago






              • 1




                You can rewrite these recursion using short-circuiting behaviour, eg. for the second one: n*(F(x)>F(x-n)**2)or f(x,n+1). Similarly x<2or x*F(x-1) for the first one which is shorter than the import.
                – BMO
                5 hours ago








              • 1




                All three of those are nice suggestions, thanks. (And added)
                – nedla2004
                5 hours ago






              • 1




                -3 bytes with import math;F=math.factorial which I should probably go find the python tips meta to mention...
                – Sparr
                5 hours ago








              • 2




                @Sparr: But F=lambda x:x<2or x*F(x-1) is three bytes less?
                – BMO
                5 hours ago

















              up vote
              3
              down vote














              Python 3, 76 bytes





              F=lambda x:x<2or x*F(x-1)
              f=lambda x,n=1:x<2or n*(F(x)>F(x-n)**2)or f(x,n+1)


              Try it online!



              Relies on the fact that for eating $n$ candies to still win and the total number of candies being $x$, $frac{x!}{(x-n)!}>(x-n)!$ must be true, which means $x!>((x-n)!)^2$.



              -1 from Skidsdev



              -3 -6 from BMO



              -3 from Sparr



              +6 to fix x = 1






              share|improve this answer



















              • 1




                You can save 1 byte by replacing the top function with from math import factorial as F
                – Skidsdev
                5 hours ago






              • 1




                You can rewrite these recursion using short-circuiting behaviour, eg. for the second one: n*(F(x)>F(x-n)**2)or f(x,n+1). Similarly x<2or x*F(x-1) for the first one which is shorter than the import.
                – BMO
                5 hours ago








              • 1




                All three of those are nice suggestions, thanks. (And added)
                – nedla2004
                5 hours ago






              • 1




                -3 bytes with import math;F=math.factorial which I should probably go find the python tips meta to mention...
                – Sparr
                5 hours ago








              • 2




                @Sparr: But F=lambda x:x<2or x*F(x-1) is three bytes less?
                – BMO
                5 hours ago















              up vote
              3
              down vote










              up vote
              3
              down vote










              Python 3, 76 bytes





              F=lambda x:x<2or x*F(x-1)
              f=lambda x,n=1:x<2or n*(F(x)>F(x-n)**2)or f(x,n+1)


              Try it online!



              Relies on the fact that for eating $n$ candies to still win and the total number of candies being $x$, $frac{x!}{(x-n)!}>(x-n)!$ must be true, which means $x!>((x-n)!)^2$.



              -1 from Skidsdev



              -3 -6 from BMO



              -3 from Sparr



              +6 to fix x = 1






              share|improve this answer















              Python 3, 76 bytes





              F=lambda x:x<2or x*F(x-1)
              f=lambda x,n=1:x<2or n*(F(x)>F(x-n)**2)or f(x,n+1)


              Try it online!



              Relies on the fact that for eating $n$ candies to still win and the total number of candies being $x$, $frac{x!}{(x-n)!}>(x-n)!$ must be true, which means $x!>((x-n)!)^2$.



              -1 from Skidsdev



              -3 -6 from BMO



              -3 from Sparr



              +6 to fix x = 1







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 4 hours ago

























              answered 6 hours ago









              nedla2004

              3211310




              3211310








              • 1




                You can save 1 byte by replacing the top function with from math import factorial as F
                – Skidsdev
                5 hours ago






              • 1




                You can rewrite these recursion using short-circuiting behaviour, eg. for the second one: n*(F(x)>F(x-n)**2)or f(x,n+1). Similarly x<2or x*F(x-1) for the first one which is shorter than the import.
                – BMO
                5 hours ago








              • 1




                All three of those are nice suggestions, thanks. (And added)
                – nedla2004
                5 hours ago






              • 1




                -3 bytes with import math;F=math.factorial which I should probably go find the python tips meta to mention...
                – Sparr
                5 hours ago








              • 2




                @Sparr: But F=lambda x:x<2or x*F(x-1) is three bytes less?
                – BMO
                5 hours ago
















              • 1




                You can save 1 byte by replacing the top function with from math import factorial as F
                – Skidsdev
                5 hours ago






              • 1




                You can rewrite these recursion using short-circuiting behaviour, eg. for the second one: n*(F(x)>F(x-n)**2)or f(x,n+1). Similarly x<2or x*F(x-1) for the first one which is shorter than the import.
                – BMO
                5 hours ago








              • 1




                All three of those are nice suggestions, thanks. (And added)
                – nedla2004
                5 hours ago






              • 1




                -3 bytes with import math;F=math.factorial which I should probably go find the python tips meta to mention...
                – Sparr
                5 hours ago








              • 2




                @Sparr: But F=lambda x:x<2or x*F(x-1) is three bytes less?
                – BMO
                5 hours ago










              1




              1




              You can save 1 byte by replacing the top function with from math import factorial as F
              – Skidsdev
              5 hours ago




              You can save 1 byte by replacing the top function with from math import factorial as F
              – Skidsdev
              5 hours ago




              1




              1




              You can rewrite these recursion using short-circuiting behaviour, eg. for the second one: n*(F(x)>F(x-n)**2)or f(x,n+1). Similarly x<2or x*F(x-1) for the first one which is shorter than the import.
              – BMO
              5 hours ago






              You can rewrite these recursion using short-circuiting behaviour, eg. for the second one: n*(F(x)>F(x-n)**2)or f(x,n+1). Similarly x<2or x*F(x-1) for the first one which is shorter than the import.
              – BMO
              5 hours ago






              1




              1




              All three of those are nice suggestions, thanks. (And added)
              – nedla2004
              5 hours ago




              All three of those are nice suggestions, thanks. (And added)
              – nedla2004
              5 hours ago




              1




              1




              -3 bytes with import math;F=math.factorial which I should probably go find the python tips meta to mention...
              – Sparr
              5 hours ago






              -3 bytes with import math;F=math.factorial which I should probably go find the python tips meta to mention...
              – Sparr
              5 hours ago






              2




              2




              @Sparr: But F=lambda x:x<2or x*F(x-1) is three bytes less?
              – BMO
              5 hours ago






              @Sparr: But F=lambda x:x<2or x*F(x-1) is three bytes less?
              – BMO
              5 hours ago












              up vote
              1
              down vote














              Haskell, 52 51 bytes



              Using the straightforward approach: We check whether the product of the last $n$ numbers, which is $frac{x!}{(x-n)!}$ is less than the product of the first $n$ numbers, namely $(x-n)!$ and takes the least $n$ for which this is true.





              g b=product[1..b]
              f x=[n|n<-[1..],g(x-n)^2<=g x]!!0


              Try it online!






              share|improve this answer



























                up vote
                1
                down vote














                Haskell, 52 51 bytes



                Using the straightforward approach: We check whether the product of the last $n$ numbers, which is $frac{x!}{(x-n)!}$ is less than the product of the first $n$ numbers, namely $(x-n)!$ and takes the least $n$ for which this is true.





                g b=product[1..b]
                f x=[n|n<-[1..],g(x-n)^2<=g x]!!0


                Try it online!






                share|improve this answer

























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote










                  Haskell, 52 51 bytes



                  Using the straightforward approach: We check whether the product of the last $n$ numbers, which is $frac{x!}{(x-n)!}$ is less than the product of the first $n$ numbers, namely $(x-n)!$ and takes the least $n$ for which this is true.





                  g b=product[1..b]
                  f x=[n|n<-[1..],g(x-n)^2<=g x]!!0


                  Try it online!






                  share|improve this answer















                  Haskell, 52 51 bytes



                  Using the straightforward approach: We check whether the product of the last $n$ numbers, which is $frac{x!}{(x-n)!}$ is less than the product of the first $n$ numbers, namely $(x-n)!$ and takes the least $n$ for which this is true.





                  g b=product[1..b]
                  f x=[n|n<-[1..],g(x-n)^2<=g x]!!0


                  Try it online!







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 5 hours ago

























                  answered 5 hours ago









                  flawr

                  26.5k664186




                  26.5k664186






















                      up vote
                      1
                      down vote














                      Clean, 57 bytes



                      import StdEnv
                      $x=while(e=prod[1..x-e]^2>prod[1..x])inc 1


                      Try it online!



                      A straight-forward solution.






                      share|improve this answer



























                        up vote
                        1
                        down vote














                        Clean, 57 bytes



                        import StdEnv
                        $x=while(e=prod[1..x-e]^2>prod[1..x])inc 1


                        Try it online!



                        A straight-forward solution.






                        share|improve this answer

























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote










                          Clean, 57 bytes



                          import StdEnv
                          $x=while(e=prod[1..x-e]^2>prod[1..x])inc 1


                          Try it online!



                          A straight-forward solution.






                          share|improve this answer















                          Clean, 57 bytes



                          import StdEnv
                          $x=while(e=prod[1..x-e]^2>prod[1..x])inc 1


                          Try it online!



                          A straight-forward solution.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 4 hours ago

























                          answered 4 hours ago









                          Οurous

                          6,18311032




                          6,18311032






















                              up vote
                              1
                              down vote














                              Jelly, 9 bytes



                              ḊPÐƤ<!€TL


                              Try it online! Or see the test-suite.



                              How?



                              ḊPÐƤ<!€TL - Link: integer, x                   e.g. 7
                              Ḋ - dequeue (implicit range of x) [ 2, 3, 4, 5, 6, 7]
                              ÐƤ - for postfixes [all, allButFirst, ...]:
                              P - product [5040,2520, 840, 210, 42, 7]
                              € - for each (in implicit range of x):
                              ! - factorial [ 1, 2, 6, 24, 120, 720, 5040]
                              < - (left) less than (right)? [ 0, 0, 0, 0, 1, 1, 5040]
                              - -- note right always 1 longer than left giving trailing x! like the 5040 ^
                              T - truthy indices [ 5, 6, 7 ]
                              L - length 3





                              share|improve this answer























                              • that's impressive but would be more educative if explained
                                – Setop
                                4 hours ago










                              • It will be... :)
                                – Jonathan Allan
                                4 hours ago










                              • @Setop - added.
                                – Jonathan Allan
                                4 hours ago










                              • like it ! and it must be fast compare to all solutions with tons of factorials
                                – Setop
                                4 hours ago










                              • Nah, still calculates all those products and factorials (more than some other solutions).
                                – Jonathan Allan
                                3 hours ago















                              up vote
                              1
                              down vote














                              Jelly, 9 bytes



                              ḊPÐƤ<!€TL


                              Try it online! Or see the test-suite.



                              How?



                              ḊPÐƤ<!€TL - Link: integer, x                   e.g. 7
                              Ḋ - dequeue (implicit range of x) [ 2, 3, 4, 5, 6, 7]
                              ÐƤ - for postfixes [all, allButFirst, ...]:
                              P - product [5040,2520, 840, 210, 42, 7]
                              € - for each (in implicit range of x):
                              ! - factorial [ 1, 2, 6, 24, 120, 720, 5040]
                              < - (left) less than (right)? [ 0, 0, 0, 0, 1, 1, 5040]
                              - -- note right always 1 longer than left giving trailing x! like the 5040 ^
                              T - truthy indices [ 5, 6, 7 ]
                              L - length 3





                              share|improve this answer























                              • that's impressive but would be more educative if explained
                                – Setop
                                4 hours ago










                              • It will be... :)
                                – Jonathan Allan
                                4 hours ago










                              • @Setop - added.
                                – Jonathan Allan
                                4 hours ago










                              • like it ! and it must be fast compare to all solutions with tons of factorials
                                – Setop
                                4 hours ago










                              • Nah, still calculates all those products and factorials (more than some other solutions).
                                – Jonathan Allan
                                3 hours ago













                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote










                              Jelly, 9 bytes



                              ḊPÐƤ<!€TL


                              Try it online! Or see the test-suite.



                              How?



                              ḊPÐƤ<!€TL - Link: integer, x                   e.g. 7
                              Ḋ - dequeue (implicit range of x) [ 2, 3, 4, 5, 6, 7]
                              ÐƤ - for postfixes [all, allButFirst, ...]:
                              P - product [5040,2520, 840, 210, 42, 7]
                              € - for each (in implicit range of x):
                              ! - factorial [ 1, 2, 6, 24, 120, 720, 5040]
                              < - (left) less than (right)? [ 0, 0, 0, 0, 1, 1, 5040]
                              - -- note right always 1 longer than left giving trailing x! like the 5040 ^
                              T - truthy indices [ 5, 6, 7 ]
                              L - length 3





                              share|improve this answer















                              Jelly, 9 bytes



                              ḊPÐƤ<!€TL


                              Try it online! Or see the test-suite.



                              How?



                              ḊPÐƤ<!€TL - Link: integer, x                   e.g. 7
                              Ḋ - dequeue (implicit range of x) [ 2, 3, 4, 5, 6, 7]
                              ÐƤ - for postfixes [all, allButFirst, ...]:
                              P - product [5040,2520, 840, 210, 42, 7]
                              € - for each (in implicit range of x):
                              ! - factorial [ 1, 2, 6, 24, 120, 720, 5040]
                              < - (left) less than (right)? [ 0, 0, 0, 0, 1, 1, 5040]
                              - -- note right always 1 longer than left giving trailing x! like the 5040 ^
                              T - truthy indices [ 5, 6, 7 ]
                              L - length 3






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 3 hours ago

























                              answered 4 hours ago









                              Jonathan Allan

                              50.5k534165




                              50.5k534165












                              • that's impressive but would be more educative if explained
                                – Setop
                                4 hours ago










                              • It will be... :)
                                – Jonathan Allan
                                4 hours ago










                              • @Setop - added.
                                – Jonathan Allan
                                4 hours ago










                              • like it ! and it must be fast compare to all solutions with tons of factorials
                                – Setop
                                4 hours ago










                              • Nah, still calculates all those products and factorials (more than some other solutions).
                                – Jonathan Allan
                                3 hours ago


















                              • that's impressive but would be more educative if explained
                                – Setop
                                4 hours ago










                              • It will be... :)
                                – Jonathan Allan
                                4 hours ago










                              • @Setop - added.
                                – Jonathan Allan
                                4 hours ago










                              • like it ! and it must be fast compare to all solutions with tons of factorials
                                – Setop
                                4 hours ago










                              • Nah, still calculates all those products and factorials (more than some other solutions).
                                – Jonathan Allan
                                3 hours ago
















                              that's impressive but would be more educative if explained
                              – Setop
                              4 hours ago




                              that's impressive but would be more educative if explained
                              – Setop
                              4 hours ago












                              It will be... :)
                              – Jonathan Allan
                              4 hours ago




                              It will be... :)
                              – Jonathan Allan
                              4 hours ago












                              @Setop - added.
                              – Jonathan Allan
                              4 hours ago




                              @Setop - added.
                              – Jonathan Allan
                              4 hours ago












                              like it ! and it must be fast compare to all solutions with tons of factorials
                              – Setop
                              4 hours ago




                              like it ! and it must be fast compare to all solutions with tons of factorials
                              – Setop
                              4 hours ago












                              Nah, still calculates all those products and factorials (more than some other solutions).
                              – Jonathan Allan
                              3 hours ago




                              Nah, still calculates all those products and factorials (more than some other solutions).
                              – Jonathan Allan
                              3 hours ago










                              up vote
                              1
                              down vote














                              Python 3, 183 176 bytes





                              R=reversed
                              L=list
                              def M(I):
                              r=1
                              for i in I:
                              r*=i
                              yield r
                              def f(x):
                              S=L(range(1,x+1))
                              for(n,a,b)in zip([0]+S,R(L(M(S))),[0]+L(M(R(S)))):
                              if(b>a):
                              return n
                              return x


                              Try it online!



                              It's is a lot faster than some other solutions - 0(N) multiplications instead of O(N²) - but I can't manage to reduce code size.






                              share|improve this answer



























                                up vote
                                1
                                down vote














                                Python 3, 183 176 bytes





                                R=reversed
                                L=list
                                def M(I):
                                r=1
                                for i in I:
                                r*=i
                                yield r
                                def f(x):
                                S=L(range(1,x+1))
                                for(n,a,b)in zip([0]+S,R(L(M(S))),[0]+L(M(R(S)))):
                                if(b>a):
                                return n
                                return x


                                Try it online!



                                It's is a lot faster than some other solutions - 0(N) multiplications instead of O(N²) - but I can't manage to reduce code size.






                                share|improve this answer

























                                  up vote
                                  1
                                  down vote










                                  up vote
                                  1
                                  down vote










                                  Python 3, 183 176 bytes





                                  R=reversed
                                  L=list
                                  def M(I):
                                  r=1
                                  for i in I:
                                  r*=i
                                  yield r
                                  def f(x):
                                  S=L(range(1,x+1))
                                  for(n,a,b)in zip([0]+S,R(L(M(S))),[0]+L(M(R(S)))):
                                  if(b>a):
                                  return n
                                  return x


                                  Try it online!



                                  It's is a lot faster than some other solutions - 0(N) multiplications instead of O(N²) - but I can't manage to reduce code size.






                                  share|improve this answer















                                  Python 3, 183 176 bytes





                                  R=reversed
                                  L=list
                                  def M(I):
                                  r=1
                                  for i in I:
                                  r*=i
                                  yield r
                                  def f(x):
                                  S=L(range(1,x+1))
                                  for(n,a,b)in zip([0]+S,R(L(M(S))),[0]+L(M(R(S)))):
                                  if(b>a):
                                  return n
                                  return x


                                  Try it online!



                                  It's is a lot faster than some other solutions - 0(N) multiplications instead of O(N²) - but I can't manage to reduce code size.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited 2 hours ago

























                                  answered 2 hours ago









                                  Setop

                                  1586




                                  1586






















                                      up vote
                                      0
                                      down vote














                                      Jelly, 14 bytes



                                      ạ‘rP>ạ!¥
                                      1ç1#«


                                      Try it online!



                                      Handles 1 correctly.






                                      share|improve this answer

























                                        up vote
                                        0
                                        down vote














                                        Jelly, 14 bytes



                                        ạ‘rP>ạ!¥
                                        1ç1#«


                                        Try it online!



                                        Handles 1 correctly.






                                        share|improve this answer























                                          up vote
                                          0
                                          down vote










                                          up vote
                                          0
                                          down vote










                                          Jelly, 14 bytes



                                          ạ‘rP>ạ!¥
                                          1ç1#«


                                          Try it online!



                                          Handles 1 correctly.






                                          share|improve this answer













                                          Jelly, 14 bytes



                                          ạ‘rP>ạ!¥
                                          1ç1#«


                                          Try it online!



                                          Handles 1 correctly.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered 4 hours ago









                                          Erik the Outgolfer

                                          31k429102




                                          31k429102






















                                              up vote
                                              0
                                              down vote













                                              JavaScript (ES6), 53 bytes





                                              n=>(g=p=>x<n?g(p*++x):q<p&&1+g(p/n,q*=n--))(q=x=1)||n


                                              Try it online!



                                              Works up to $a(170)$. Beyond that, we'd need BigInts (+1 byte).



                                              How?



                                              We start with $p=n!$ and $q=1$.



                                              You can think of $q$ as the product of our candies and of $p$ as the product of the candies of the other kid. (So at the beginning of the process, the other kid has all the candies and we have none.)



                                              Then we repeat the following operations:




                                              • divide $p$ by $n$

                                              • multiply $q$ by $n$

                                              • decrement $n$


                                              until $qge p$.



                                              The result is the number of required iterations. (At each iteration, we 'take the next highest candy from the other kid'.)



                                              Commented



                                              This is implemented as a single recursive function which first compute $n!$ and then enters the loop described above.



                                              n => (           // main function taking n
                                              g = p => // g = recursive function taking p
                                              x < n ? // if x is less than n:
                                              g( // this is the first part of the recursion:
                                              p * ++x // we're computing p = n! by multiplying p
                                              ) // by x = 1 .. n
                                              : // else (second part):
                                              q < p && // while q is less than p:
                                              1 + g( // add 1 to the final result
                                              p / n, // divide p by n
                                              q *= n-- // multiply q by n; decrement n
                                              ) //
                                              )(q = x = 1) // initial call to g with p = q = x = 1
                                              || n // edge cases: return n for n < 2





                                              share|improve this answer



























                                                up vote
                                                0
                                                down vote













                                                JavaScript (ES6), 53 bytes





                                                n=>(g=p=>x<n?g(p*++x):q<p&&1+g(p/n,q*=n--))(q=x=1)||n


                                                Try it online!



                                                Works up to $a(170)$. Beyond that, we'd need BigInts (+1 byte).



                                                How?



                                                We start with $p=n!$ and $q=1$.



                                                You can think of $q$ as the product of our candies and of $p$ as the product of the candies of the other kid. (So at the beginning of the process, the other kid has all the candies and we have none.)



                                                Then we repeat the following operations:




                                                • divide $p$ by $n$

                                                • multiply $q$ by $n$

                                                • decrement $n$


                                                until $qge p$.



                                                The result is the number of required iterations. (At each iteration, we 'take the next highest candy from the other kid'.)



                                                Commented



                                                This is implemented as a single recursive function which first compute $n!$ and then enters the loop described above.



                                                n => (           // main function taking n
                                                g = p => // g = recursive function taking p
                                                x < n ? // if x is less than n:
                                                g( // this is the first part of the recursion:
                                                p * ++x // we're computing p = n! by multiplying p
                                                ) // by x = 1 .. n
                                                : // else (second part):
                                                q < p && // while q is less than p:
                                                1 + g( // add 1 to the final result
                                                p / n, // divide p by n
                                                q *= n-- // multiply q by n; decrement n
                                                ) //
                                                )(q = x = 1) // initial call to g with p = q = x = 1
                                                || n // edge cases: return n for n < 2





                                                share|improve this answer

























                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  JavaScript (ES6), 53 bytes





                                                  n=>(g=p=>x<n?g(p*++x):q<p&&1+g(p/n,q*=n--))(q=x=1)||n


                                                  Try it online!



                                                  Works up to $a(170)$. Beyond that, we'd need BigInts (+1 byte).



                                                  How?



                                                  We start with $p=n!$ and $q=1$.



                                                  You can think of $q$ as the product of our candies and of $p$ as the product of the candies of the other kid. (So at the beginning of the process, the other kid has all the candies and we have none.)



                                                  Then we repeat the following operations:




                                                  • divide $p$ by $n$

                                                  • multiply $q$ by $n$

                                                  • decrement $n$


                                                  until $qge p$.



                                                  The result is the number of required iterations. (At each iteration, we 'take the next highest candy from the other kid'.)



                                                  Commented



                                                  This is implemented as a single recursive function which first compute $n!$ and then enters the loop described above.



                                                  n => (           // main function taking n
                                                  g = p => // g = recursive function taking p
                                                  x < n ? // if x is less than n:
                                                  g( // this is the first part of the recursion:
                                                  p * ++x // we're computing p = n! by multiplying p
                                                  ) // by x = 1 .. n
                                                  : // else (second part):
                                                  q < p && // while q is less than p:
                                                  1 + g( // add 1 to the final result
                                                  p / n, // divide p by n
                                                  q *= n-- // multiply q by n; decrement n
                                                  ) //
                                                  )(q = x = 1) // initial call to g with p = q = x = 1
                                                  || n // edge cases: return n for n < 2





                                                  share|improve this answer














                                                  JavaScript (ES6), 53 bytes





                                                  n=>(g=p=>x<n?g(p*++x):q<p&&1+g(p/n,q*=n--))(q=x=1)||n


                                                  Try it online!



                                                  Works up to $a(170)$. Beyond that, we'd need BigInts (+1 byte).



                                                  How?



                                                  We start with $p=n!$ and $q=1$.



                                                  You can think of $q$ as the product of our candies and of $p$ as the product of the candies of the other kid. (So at the beginning of the process, the other kid has all the candies and we have none.)



                                                  Then we repeat the following operations:




                                                  • divide $p$ by $n$

                                                  • multiply $q$ by $n$

                                                  • decrement $n$


                                                  until $qge p$.



                                                  The result is the number of required iterations. (At each iteration, we 'take the next highest candy from the other kid'.)



                                                  Commented



                                                  This is implemented as a single recursive function which first compute $n!$ and then enters the loop described above.



                                                  n => (           // main function taking n
                                                  g = p => // g = recursive function taking p
                                                  x < n ? // if x is less than n:
                                                  g( // this is the first part of the recursion:
                                                  p * ++x // we're computing p = n! by multiplying p
                                                  ) // by x = 1 .. n
                                                  : // else (second part):
                                                  q < p && // while q is less than p:
                                                  1 + g( // add 1 to the final result
                                                  p / n, // divide p by n
                                                  q *= n-- // multiply q by n; decrement n
                                                  ) //
                                                  )(q = x = 1) // initial call to g with p = q = x = 1
                                                  || n // edge cases: return n for n < 2






                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited 4 hours ago

























                                                  answered 5 hours ago









                                                  Arnauld

                                                  71.3k688298




                                                  71.3k688298






















                                                      up vote
                                                      0
                                                      down vote














                                                      05AB1E, 15 bytes



                                                      EI!IN-!n›Ði–#]1


                                                      Try it online!



                                                      EI!IN-!n›Ði–#]1

                                                      E For loop with N from [1 ... input]
                                                      I! Push factorial of input
                                                      IN- Push input - N (x - n)
                                                      ! Factorial
                                                      n Square
                                                      › Push input! > (input - N)^2 or x! > (x - n)^2
                                                      Ð Triplicate, used for three upcoming operations (if, print, end)
                                                      i If, run code after if top of stack is 1 (found minimum number of candies)
                                                      – Print N if top of stack is 1
                                                      #] Ends for loop and program is top of stack is 1
                                                      1 Pushes 1 so that if the input is 1 and we leave the for loop without
                                                      printing anything 1 is printed


                                                      Uses the same approach as my Python submission. Very new to 05AB1E so any tips on code or explaination greatly appreciated.






                                                      share|improve this answer



























                                                        up vote
                                                        0
                                                        down vote














                                                        05AB1E, 15 bytes



                                                        EI!IN-!n›Ði–#]1


                                                        Try it online!



                                                        EI!IN-!n›Ði–#]1

                                                        E For loop with N from [1 ... input]
                                                        I! Push factorial of input
                                                        IN- Push input - N (x - n)
                                                        ! Factorial
                                                        n Square
                                                        › Push input! > (input - N)^2 or x! > (x - n)^2
                                                        Ð Triplicate, used for three upcoming operations (if, print, end)
                                                        i If, run code after if top of stack is 1 (found minimum number of candies)
                                                        – Print N if top of stack is 1
                                                        #] Ends for loop and program is top of stack is 1
                                                        1 Pushes 1 so that if the input is 1 and we leave the for loop without
                                                        printing anything 1 is printed


                                                        Uses the same approach as my Python submission. Very new to 05AB1E so any tips on code or explaination greatly appreciated.






                                                        share|improve this answer

























                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote










                                                          05AB1E, 15 bytes



                                                          EI!IN-!n›Ði–#]1


                                                          Try it online!



                                                          EI!IN-!n›Ði–#]1

                                                          E For loop with N from [1 ... input]
                                                          I! Push factorial of input
                                                          IN- Push input - N (x - n)
                                                          ! Factorial
                                                          n Square
                                                          › Push input! > (input - N)^2 or x! > (x - n)^2
                                                          Ð Triplicate, used for three upcoming operations (if, print, end)
                                                          i If, run code after if top of stack is 1 (found minimum number of candies)
                                                          – Print N if top of stack is 1
                                                          #] Ends for loop and program is top of stack is 1
                                                          1 Pushes 1 so that if the input is 1 and we leave the for loop without
                                                          printing anything 1 is printed


                                                          Uses the same approach as my Python submission. Very new to 05AB1E so any tips on code or explaination greatly appreciated.






                                                          share|improve this answer















                                                          05AB1E, 15 bytes



                                                          EI!IN-!n›Ði–#]1


                                                          Try it online!



                                                          EI!IN-!n›Ði–#]1

                                                          E For loop with N from [1 ... input]
                                                          I! Push factorial of input
                                                          IN- Push input - N (x - n)
                                                          ! Factorial
                                                          n Square
                                                          › Push input! > (input - N)^2 or x! > (x - n)^2
                                                          Ð Triplicate, used for three upcoming operations (if, print, end)
                                                          i If, run code after if top of stack is 1 (found minimum number of candies)
                                                          – Print N if top of stack is 1
                                                          #] Ends for loop and program is top of stack is 1
                                                          1 Pushes 1 so that if the input is 1 and we leave the for loop without
                                                          printing anything 1 is printed


                                                          Uses the same approach as my Python submission. Very new to 05AB1E so any tips on code or explaination greatly appreciated.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited 4 hours ago

























                                                          answered 5 hours ago









                                                          nedla2004

                                                          3211310




                                                          3211310






























                                                              draft saved

                                                              draft discarded




















































                                                              If this is an answer to a challenge…




                                                              • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                              • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                Explanations of your answer make it more interesting to read and are very much encouraged.


                                                              • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                              More generally…




                                                              • …Please make sure to answer the question and provide sufficient detail.


                                                              • …Avoid asking for help, clarification or responding to other answers (use comments instead).






                                                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                              Please pay close attention to the following guidance:


                                                              • 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.


                                                              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%2fcodegolf.stackexchange.com%2fquestions%2f177495%2fhow-much-candy-can-you-eat%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

                                                              What visual should I use to simply compare current year value vs last year in Power BI desktop

                                                              Alexandru Averescu

                                                              Trompette piccolo