Geometry puzzle: string cutting game

This is a great problem I came across, and I’d love to see it used as a consulting or technical interview question.

Here is the setup.

An interviewer gives you a string that measures 4 meters in length. The string is to be cut into two pieces. One piece is made into the shape of a square, and the other into a circle. (picture of this below)

Your job is to make the total enclosed area as large as possible.

The interviewer hands you a piece of paper and a pencil so you can do the math (you only get one chance to cut the string so you want to be sure your first attempt is correct).

How should you cut the string?

If you are able to figure out the answer, the interviewer has a couple follow-up questions to test your skills.

–How should you cut the string if you want to minimize the enclosed area?

–Imagine the string is cut randomly. What is the average value of the enclosed area? (When you cut the string, there is one piece to the left of the cut and another to the right. Suppose the left piece is always made into a circle and the right into a square)

Can you figure it out?

As usual, I will post an answer on Wednesday.

If you are an RSS reader or get my articles by email, then you will see a link to the solution in the Wednesday article.

Give it a try and leave a comment if you solved the puzzle (though please don’t spoil the answers for others).



Share this post:

| More

Previous post:

Next post:



  • Sebastian

    I solved it generally for any string length x:
    a..length of square circumference
    x-a..length of circle circumference
    A(square)=(a/4)^2
    A(circle)=((x-a)^2)/4
    -> A(a)= (a^2)/16+(x^2)/(4*PI)-a*x/(2*PI)+(a^2)/(4*PI)
    Derrivative w.r.t. a … a*= (4*x)/(PI+4)
    i.e. for x=2 a*= 8/(4+PI)=1.12 and A(a*)=0.14
    By second derrivative this is a Minimum.
    Since the function was of order 2, the Maximum must occur at the boundary of the interval [0,2].
    A(0)= (x^2)/(4*PI)
    A(x)= (x^2)^(16) A(0)>A(x) for any x. So the max enclosed area for x=2 is A(0)=1/PI=0.32 (This makes sense, since a circle covers the biggest area out of all shapes for given circumference).
    For the random cut: the average cut happens in the middle at x/2, so A(x/2)=(x^2)*((Pi+4)/(64*PI)), which for x=2, makes A(1)=0.14
    Sorry for any possible errors.
    Thanks for this cool problem. Hope I’ll get this one in my next interview. :) Presh, I’ll send you another problem, that I once got asked but couldnt solve. Maybe the other readers can solve it.
    Best,
    Sebastian

  • Eyal

    Sebastian had some typos (equation for circle is missing factor of 1/pi) but he got the answers right except the last one. If the minimum is 0.14, how is that also the average?

    My answer for part three came to 0.189. (I don’t consider this a spoiler because the technique is the goal, not the number!)

  • Dan

    There is an error in the example. The area of a circle with 2m circumference in 0.32m2. For a 1m circ as the example shows, the area is 0.08m2. Ditto for the square 0.25m2 should be 0.06m2.

    The max area is with the circle having all the string.
    The min area is with the circle having ~0.88m of the string and total area (circle + square) of 0.14m2. I also calculated 0.189m2 as the average.

    Yes, you can solve this with paper/pencil. In my opinion, it is much faster with Excel.

  • http://www.mindyourdecisions.com/blog/ Presh Talwalkar

    Thanks for pointing out the typo Dan. I will change the text as I meant for the string to be 4 meters (not that it really matters, but it is easier to modify text in a post than to make and upload another image).

  • Paul

    I think it’s possible to answer the first question without pencil and paper (no need to explicitly compute the value c of the circumference that minimizes the area). Here’s how:

    It is well known that a circle is the shape which maximizes the area for a given perimeter. So we know that A(4) > A(0) (This is independent of Presh’s correction). Area formulas are generally quadratic, so the graph of A(c) is a parabola. We need to figure out the general shape of the parabola with respect to those two points. The first thing is to figure out if it opens upward or opens downward.

    To see that it opens upward, let the total area equal the area of the circle plus the area of the square: A = AC + AS. The formula for AC will increase as the circumference, c, tends to infinity. It’s not too hard to see that AS = ((2-c)/4)^2 which gives a positive c-term in the formula. So AS also increases as c goes to infinity. (OK, this part might be easier if you actually use the pencil to write down the formulas for AC and AS, but it’s not strictly necessary.)

    Now that we know it opens upward (i.e. it has no local maximum), we follow Sebastian’s reasoning and conclude the maximum occurs on the boundary of the interval. But remember, we started by noting that A(4) > A(0), so the maximum happens at c = 4.

    I like this solution because it focuses more on the big picture than on the irrelevant details. That being said, my instinct was also to start cranking through the calculus.

    As for the other two questions, I don’t see a similarly big picture answer. I would love to hear it if you have simple solutions.

    Minimizing the area would be easy if you could easily determine that the formula for the total area had a minimum at c < 0. It turns out that is not the case, but I don't see a way of concluding that easily.

    The average is also harder. Since the formula is not linear, you cannot simply take the value at the midpoint. I believe you would need to use The Mean Value Theorem and perform an integral.

  • http://vpsgraphics.com V Paul Smith Jr

    Max = Full Circle = 1.2732
    Min = Cut at 1.7596 = .5601
    Average = 1.5155

  • http://vpsgraphics.com V Paul Smith Jr

    Ha! Scratch the average, for obvious reasons. Will rework that one.

  • http://vpsgraphics.com V Paul Smith Jr

    Average = (4+pi)/3pi = .7577…
    That sounds more reasonable than before.

  • Sebastian

    Thank you for correcting my typos and my wrong #3!
    I’m getting (4+Pi)/(12Pi)= 0.189 just like Eyal now.
    Paul gives the hint in his last paragraph.

  • Michael

    I took the calculus approach, but the result suggests to me that the interviewer is asking a trick question (at least for the first part).

    The solution requires that “The string is to be cut into two pieces.” The maximum area is obtained when the string is not cut at all, but since we are required to cut the string we cannot form a maximum area, because for any cut there is a larger area that could be formed if we just could cut the short string just a tiny amount shorter.

  • http://www.mindyourdecisions.com/blog/ Presh Talwalkar

    Thanks all for the comments. Here is my solution.

    1. How should you cut the string to maximize the area?

    This is something of a trick question. For a given length, the circle is the shape that encloses the largest area. So you want to make the whole string be the circle. (This is known as the isoperimetric inequality and it is not a trivial thing to prove!)

    As you must cut it into two pieces, you should try to cut as close to one end as possible to make the rectangle small.

    2. How should you cut the string if you want to minimize the enclosed area?

    This can be solved using calculus. If you let one side of the string be called x for the circle and the other side be called 4 – x, then you can find a formula for the area of the two shapes as follows:

    Area = x^2/(4*pi) + (1 – x/4)^2

    The first term is the area of the circle, and the second the square.

    The formula is for a parabola.

    Using calculus or WolframAlpha we can find the minimum happens at (4*pi)/(4 + pi).

    3. Imagine the string is cut randomly. What is the average value of the enclosed area?

    As stated in step 2, the area function is described by the equation:

    f(x) = x^2/(4*pi) + (1 – x/4)^2

    We can take the average value by calculating an integral: you integrate the function from 0 to 4 (which gives the area under the curve) and then you divide by the length of the interval (4) to arrive at the average value:

    Average value = 0.25 integral (f(x), x, 0, 4)

    Using WolframAlpha this is computed as 0.758

  • Sebastian

    getting the same results as Presh for the new boundaries [0,4].

  • Michael

    Obviously the answer is to split the string down the middle, thus enjoying maximum circle and square area. :)

    Minimum:





Previous post:

Next post:

Other posts you may enjoy reading: