Merry Christmas everyone! Sadly, the lights you've had on your tree for so many years burned out, and it's time to get a new set. Being a skilled (and cheap!) mathematician, you realize that you can estimate the total length of the strings of lights you'll need for your tree with two simple parameters:
The rows of lights are equally spaced vertically around the tree. Given these two variables, calculate how long your string of lights has to be in order to wrap around your tree. You want to buy the minimum possible length of lights, because NOBODY likes having to untangle any more lights than they have to!
Helpful hints - The answers calculated below model the lights on your tree as a two-dimensional Spiral of Archimedes, so the number of rows of lights is equal to the number of times your spiral makes a full 360-degree loop. The final Cartesian coordinate of your spiral should be (width, 0). If someone far smarter than I am wants to make the full three-dimensional version of this problem, knock yourself out!
If the answer to this problem is L=F(w,n), the answer for a tree of height h is L=F(d,n*w/d), where d=sqrt(h^2+w^2).
It seems that the reference answer to the arc length given in the test suite is doubled. This is possibly due to the confusion on the parameter w ("the Width of the base of the tree", which literally means the diameter of the base). But the test suite seems to use w as the radius of the base; thus doubling the final answer. Am I missing something here?
Peng, you're correct. I'll blame that oversight on a bit too much Egg Nog, and change the problem description.
Tim, does the fact that the spiral is also travelling in the Z-direction change the length? Is there a distortion due to the 3-D nature of the spiral? I honestly don't know, which is why I added the helpful hint; in case someone could answer that, did the full 3-D calculation, and came up with a more correct answer. If the length of the 2-D spiral is equal to the 3-D one, then your equation is correct; that's actually how I calculated it originally before realizing that I could just use the base of the tree as a variable instead of both the height and base. Does anyone who can actually do this sort of calculation want to chime in here?
Yes, the height does increase the length. For example, w=4 n=5 h=0 gives L=63.1273, while w=4 n=5 h=8 gives L=64.0530. The formulas I used were r=w*t/(2*n*pi), x=r*cos(t), y=r*sin(t), and z=h*(1-t/(2*n*pi)), and then L is the integral of sqrt(dxdt^2+dydt^2+dzdt^2)*dt from 0 to 2*n*pi.
Got the same results as Tim. My tree was upside down: γ=2∙π∙n, x(θ)=w/γ∙θ∙cos(θ), y(θ)=w/γ∙θ∙sin(θ), z(θ)=h/γ∙θ, L=∫̥ᵞ √(x’²+y’²+z’²)dθ. Anyway, h→∞≡L→∞, proves that h matters.
I wasn't really sure how to model the z-coordinate as a function of height. I had a hunch it would be the case, but I couldn't actually figure out how to do it. Thanks to the smart people in the thread for coming up with the equations for it!
731 Solvers
187 Solvers
Given a window, how many subsets of a vector sum positive
648 Solvers
Calculate the Hamming distance between two strings
134 Solvers
137 Solvers