Painter puzzle - estimation

后端 未结 2 1875
灰色年华
灰色年华 2020-12-07 06:32

This problem is based on a puzzle by Joel Spolsky from 2001.

A guy \"gets a job as a street painter, painting the dotted lines down the middle of the road.\"

相关标签:
2条回答
  • 2020-12-07 06:41

    considering four assumptions :-

    painting speed = infinity
    
    walking speed = x
    
    he can paint only infinitly small in one brush stroke.
    
    he leaves his can at starting point.
    
    
    
    The distance he walks for painting dy road at y distance = 2y
    
    Total distance he walks = intgeration of 2y*dy = y^2 = y^2
    
    Total time he can paint y distance = y^2/x
    
    Time taken to paint 300 yards = 1 day
    
    (300)^2/x = 1
    
    x = 90000 yards/day
    
    Total time he can paint distance y = y^2/90000
    
    
    (y/300)^2 = 2      after second day
    
    y = 300*2^(1/2) = 424
    
    Day 1 = 300
    Day 2 = 424-300 = 124
    Day 3 = 300*3^(1/2)-424 = 520 - 424 = 96
    
    Ans : 300/124/96  assuming the first day its 300 
    
    0 讨论(0)
  • 2020-12-07 06:56

    There are a lot of unknowns here - his walking speed, his painting speed, for how long does the paint in the brush last...

    But clearly there are two processes going on here. One is quadratic - it's the walking to and fro between the paint can and the painting point. The other is linear - it's the process of painting, itself.

    Thinking about the 10th or even the 100th day, it is clear that the linear component becomes negligible, and the process becomes very nearly quadratic - the walking takes almost all the time. During the first few minutes of the first day, on the contrary, it is close to being linear.

    We can thus say that the time t as a function of the distance s follows a power law t ~ s^a with a changing coefficient a = 1.0 ... 2.0. This also means that s ~ t^b, b = 1/a.

    Applying the empirical orders of growth analysis:

    The b coefficient between day 1 and day 2 is approximated as

    b(1,2) = log (450/300) / log 2 = 0.585        a(1,2) = 1/0.585 = 1.71
    

    Just as expected, the coefficient is below 2. Going for the time period between day 2 and day 3, we can set it approximately to the middle value between 1.71 and 2.0,

    a(2,3) = 1.85        b(2,3) = 0.54          450*(3/2)**0.54 = 560 yards
    

    Thus the distance covered in the third day can be estimated as 560 - 450 = 110 yards.

    What if the a coefficient had the maximum possible value, 2.0, already (which is impossible)? Then, 450*(3/2)**0.5 = 551 yards. And for the other extreme, if it were the same 1.71 (which it clearly can't be, either), 450*(3/2)**0.585 = 570.

    This means that the estimate of 110 yards is plausible, with an error of less than 10 yards on either side.

    0 讨论(0)
提交回复
热议问题