Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!

# Puzzle anyone

Pranav Jaidka
Ranch Hand
Posts: 264
There are 2 ropes .
When one is lighted it burns out in 1 hour.
when the other is ligthed it burns out in half hour.
Measure 45 minutes using these ropes .
Ropes are uneven in density and do not burn out evenly.

[This message has been edited by Pranav Jaidka (edited May 30, 2001).]

Connie Boyd
Ranch Hand
Posts: 73
Okay, I attempted an answer, and then deleted it because I was pretty sure it was wrong, but I'll buck up and leave this one.
If you fold each rope in half, you should be able to measure out 30 minutes on one and 15 on the other.

Andrew Shafer
Ranch Hand
Posts: 338

At the end of 45 minutes, both ropes have been completely burned.

Pranav Jaidka
Ranch Hand
Posts: 264
Sorry guys ...MY MISTAKE...
I forgot to mention that the ropes are not even in density and they do not burn out UNIFORMLY .......makes it tougher but its possible.
.
.
.
You were close though
[This message has been edited by Pranav Jaidka (edited May 30, 2001).]
[This message has been edited by Pranav Jaidka (edited May 30, 2001).]

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Folding in half doesn't work if the ropes are uneven in density - you don't know that the midpoint of the rope necessarily represents the point where half the time has elapsed. But there is a way...
As a variation, try to measure a length of 37.5 minutes.

Randall Twede
Ranch Hand
Posts: 4467
3
if you light each rope one at a time at both ends it will take 45 minutes

Andrew Shafer
Ranch Hand
Posts: 338

How do you measure the 37.5?

Nanjangud Nanjundaiah
Ranch Hand
Posts: 186
Looks like Randall's got the answer. And to get 37.5, fold the second rope before lighting both ends

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Sorry NN, folding still doesn't work.
There's also a way to measure 7.5 minutes, though to do it exactly you technically need to perform an infinite number of steps. And I'm assuming it takes zero time to light something. If I also have a knife which can cut the cord in zero time, I can measure 10 minutes as well. And by combining these techniques and others like them, plenty of other times are achievable - 67.5, 3.75, 35... the list is endless, really. Categorizing all the possibilities would be a nifty programming problem in itself, I imagine...

Peter Lyons
Ranch Hand
Posts: 202
I think Randall does have it. The rope is not uniform density, so the length of rope consumed by the flame during any given interval is not predictable, but the average rate of linear burn is set to consume the entire length in a known length of time. Lighting each rope at both ends will consume each rope in half the time it would take if you had lit them at one end only.
Oh, and just for the record, that's the solution I came up with by myself before I peeked. (So I'm biased but right anyway)
Peter <--- patting himself on his back for being so smart

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
It reminds me another funny puzzle.
Distance between two towns is 600 km. A train goes from the town �A� to town �B� with a speed 120 km an hour. At the same time another train starts to move from town B to A with a speed 180 km. But these are not all bad news yet. Worse, that at the same time a fly starts from the train �A� (let�s call it so) ant takes a direction to the train �B�. When she meets the train �B�, she immediately turns back and flies to the train �A� again. And so on. Until the train meets. Question: What distance will the fly finally make if her speed is 200 km/hour? (Fly's final destiny can be disregarded )

Sorry for bad English and wrong measurement units.

[This message has been edited by Mapraputa Is (edited June 01, 2001).]

Sahir Shibley
Ranch Hand
Posts: 275
Map,
That is impossible. Since train A is faster than the fly, train A will meet train B before the fly does. Once the fly gets to train B it will never be able to catch up with train A before it gets to its destination.

[This message has been edited by Sahir Shibley (edited June 01, 2001).]

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
Oh, Ok. I forget all numbers, I guess. Was thinking which speed is reasonable for a fly... Ok, how about a fly with 200 km/hour speed? Is it better?
I changed my post above for not to confuse others.
[This message has been edited by Mapraputa Is (edited June 01, 2001).]

Pranav Jaidka
Ranch Hand
Posts: 264
Sahir thats not impossible .Here is how i figure it out.
1>Trains travel at a relative velocity of 120+180km per hour =300 Km per hour .(because they are traveling towards each other)
2)Since time = distance/velocity the time after which they meet is 600/300 = 2 hours.
3) 2 hours is the time the Fly needs to keep flying .
So the distance it will travel is velocity * time = 200*2 = 400 km .

Hows that Map ......hope thats what you are asking for.

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Pranav- it was impossible using the numbers Map originally posted. Map later changed her numbers to make the puzzle solvable. See the "edited by" line in her post? Also her later statment that she changed the values?
Map- see, you can't avoid causing confusion.

Pranav Jaidka
Ranch Hand
Posts: 264
Hmm ...that was definitely something i missed out.
However coming back to the Rope problem Randall is right about lighting both ends (That is all we can do for the time interval).I dont think cutting the rope would help in measuring any other time intervals because of the non uniform desity.
[This message has been edited by Pranav Jaidka (edited June 01, 2001).]
[This message has been edited by Pranav Jaidka (edited June 01, 2001).]

Junilu Lacar
Bartender
Posts: 7568
52
How do you measure the 37.5?
Start by lighting the 1-hr rope on one end and the 30-min rope at both ends at the same time.
When the 30 min rope burns out in 15 minutes, you'll have 45 minutes left on the 1-hr rope.
Light the other end of the now 45-minute rope (now both ends are lighted) and it burns out in 22.5 minutes.
Entire process takes 37.5 minutes
Junilu

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
LOL
Guys, you all are right: Sahir, Pranav, and Jim!
It is only Map who makes mistakes here!
I wonder how many people try to solve this by callculating sum of ... series? (series? Jim, is that how you, US citizens call it?) At least, I observed one with my own eyes!
There is also an anecdote about this puzzle. Once one famous mathematician was given this puzzle and after about 30 second of thinking he said an answer. �Impossible!� � replied the asker. �Most people I know tried to sum endless series!� �Why amazement?� � said our famous mathematician - �that�s what I did!�
Conclusion: if you cannot count fast enough, think!

Junilu Lacar
Bartender
Posts: 7568
52
Jim,
I don't see how you can measure out less than 15 minutes given just the two ropes. Are you assuming you have an infinite supply of 1-hr ropes and 30-minute ropes? If you only have the two ropes, the shortest period of time you could measure would be 15 minutes and the most would be 1.5 hrs. Am I missing something
Junilu

Junilu Lacar
Bartender
Posts: 7568
52
These problems are quite similar to this one: A monk starts climbing a mountain to a monastery at sunrise. He makes frequent stops along the way to rest and his rate of climb is not uniform. He reaches the monastery at sunset. The next day the monk goes down the mountain, again starting at sunrise taking the same path that he did going up. His rate of descent is again not uniform but he still makes it to the bottom at sunset. How can you prove (or disprove) that there is one point along the path that the monk will be at the same exact time on both days?
Junilu
[This message has been edited by JUNILU LACAR (edited June 01, 2001).]

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065

Let�s move our �tomorrow� monk one day back and imagine that we have two monks: one going up and one going down (the latter simply repeat �tomorrow�s� path). Then it is obvious

[This message has been edited by Mapraputa Is (edited June 01, 2001).]

Pranav Jaidka
Ranch Hand
Posts: 264
Is that the answer Map ...Frankly i have no clue if thats possible...unless he has a Rolex .
For me he can have any number of random locations for him to be present at any time of the day

Junilu Lacar
Bartender
Posts: 7568
52
A monk with a Rolex? I thought they make a vow of poverty...If that's poverty, I'd like to see what the vow of chastity is like...
Map got the answer. Now the problem is for you to figure out how to see it.
Junilu
Originally posted by Pranav Jaidka:
Is that the answer Map ...Frankly i have no clue if thats possible...unless he has a Rolex .
For me he can have any number of random locations for him to be present at any time of the day

Jim Yingst
Wanderer
Sheriff
Posts: 18671
What does having a Rolex have to do with it? Personally I've never had a Rolex - do they allow time travel, as Map's solution suggests? If so I'm going to have to consider getting one - but hiking on remote trails looking for monks isn't really one of the first uses I'd have for such an object.
Map- yes, the term is "series". The classic time to show someone this puzzle is when they have just been learning how to calculate infinite series like this one - they will of course interpret the problem that way and spend some effort getting the solution. Then you ask the same problem to a passing third-grader (OK, a smart third-grader) and watch the series-summer's reaction when the third-grader solves the problem the simple way.
Junilu- good solution for the 37.5, congratulations! For the other times, no, I'm only assuming one 30-min rope and one 60-min rope. I agree that 1.5 hours is the maximum time possible, but there is a trick (or group of tricks) which will allow times smaller than 15 min, such as 7.5, 10, 5, 3.75, and many more.
[This message has been edited by Jim Yingst (edited June 01, 2001).]

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
The classic time to show someone this puzzle is when they have just been learning how to calculate infinite series like this one - they will of course interpret the problem that way and spend some effort getting the solution. Then you ask the same problem to a passing third-grader (OK, a smart third-grader) and watch the series-summer's reaction when the third-grader solves the problem the simple way.
Jim, both your cases are extreme. Obviously, even smart third-grader cannot sum series, and obviously, math students studying series have certain pattern in mind. Pattern is a key word here. My interest is to figure out how people think in situations, when there is a choice of patterns. Why some people think �better� than others? One thing, they seem do not look over all possible (including wrong) solutions, they �feel� good ones. The question is simple: how do they feel them? Perhaps they have better �superpatterns�, allowing them to choose �rigth� solving patterns and thus reduce solution space. Jim, are still listening? You can continue from this place

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
For example, the guy whose attempts to solve �railroad fly� problem by calculating series I once observed, was not dumb at all. I would say he has rather systematic kind of mind, normally thinks in very methodic way and never have details mixed up (unlike Mapraputa ). He, by the way, could solve some problems, I couldn�t. But he apparently was not very good at seeing �the whole picture�; at least, in this particular case.
[This message has been edited by Mapraputa Is (edited June 01, 2001).]

Sahir Shibley
Ranch Hand
Posts: 275

I must admit I made the same mistake. I got the answer 399.93074792243766. Taking the sigma route isnt that difficult if you have a few dirty tricks up your sleeve.
<pre>
public class Fly{
private double accum = 0;
boolean flipflop = true;
private double fSpeed = 0, aSpeed = 0, bSpeed = 0;
public Fly(double distance, double aVelocity , double bVelocity , double fVelocity){
aSpeed = aVelocity;
bSpeed = bVelocity;
fSpeed = fVelocity;
while(true){
distance = iterate(distance);
if(distance < 1) break ;
}
}
public double getDist(){
return accum;
}
private double iterate(double distance){
double result = 0;
if(flipflop){
flipflop = false;
result = (distance * fSpeed) / (fSpeed + bSpeed);
accum = accum + result;
result = result - ((result * aSpeed) / fSpeed);
}
else {
flipflop = true;
result = (distance * fSpeed) / (fSpeed + aSpeed);
accum = accum + result;
result = result - ( (result * bSpeed) / fSpeed);
}
return result;
}
public static void main(String[] args) {
Fly f = new Fly(600 , 120 ,180 ,200);
System.out.println(f.getDist());
}
}

</pre>
Well The difference between my answer and 400 is only 0.06925207756234,
which gives me an error factor of 0.017313019390585% . Perhaps if I had written this in Visual Basic I may have got 400 (Dont take that seriously. Just trying to provoke you guys)
PS. If I have breached protocol by posting code in "Meaningless Drivel" , my sincerest apologies.
PPS. I have replaced the "quick and dirty" fly with an extensible and reusable, object oriented fly for Thomas Paul.
[This message has been edited by Sahir Shibley (edited June 02, 2001).]

Junilu Lacar
Bartender
Posts: 7568
52
I just realized something about the monk problem. If the problem said the monk started at 6:00am and finished at 6:00pm on both days, it is possible to know exactly what time the monk will be at the same exact spot on the path on both days.
Junilu

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
Sahir... You are a hero of the day! You are the best Object Oriented Programmer of Meningless Drivel!
�An extensible and reusable, object oriented railroad fly� was ingenious! And such an outstanding exactness! Thomas Paul can be proud of you.
Junilu, �at sunrise� is a monastic equivalent to our �at 6:00pm�

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Sahir- the accuracy of your result will improve substantially if you replace
<code><pre> if(distance < 1) break ;</pre></code>
with
<code><pre> if(distance <= 0) break ;</pre></code>
Or are 1 and 0 considered equivalent in VB?
Junilu- I really don't think it's possible to determine the time that the positions are the same. I am assuming that the monk's speeds on the second day are independant of the speeds on the first day; the only constraint is that the toatl time and total distance are the same. I can make up all sorts of combinations of numbers which yield different answers to the questions of where or when the positions would be the same. Perhaps you're using some other assumptions?
For the rope-burning problems, a hint: to get a time of 7.5 minutes, you only need the 30-min rope. Forget about the other rope.

Junilu Lacar
Bartender
Posts: 7568
52
Originally posted by Jim Yingst:
Junilu- I really don't think it's possible to determine the time that the positions are the same. I am assuming that the monk's speeds on the second day are independant of the speeds on the first day; the only constraint is that the toatl time and total distance are the same. I can make up all sorts of combinations of numbers which yield different answers to the questions of where or when the positions would be the same. Perhaps you're using some other assumptions?
For the rope-burning problems, a hint: to get a time of 7.5 minutes, you only need the 30-min rope. Forget about the other rope.

Jim, you're right: there is no way you can determine the time the monk will be at the same spot on both days. I realize now there is a slight difference between the monk problem and the rope-burning problem.
As for the trick you hint at with the instantaneous cutting and lighting: theoretically, it's possible. I know where you are coming from now. For all practical purposes though, 15 minutes is the least amount of time you could measure. It would be fun to watch somebody actually measure out 3.75 minutes or less with that method though. It'd be like the JuggleMaster simulation of a "only God could do it" pattern with 25 balls.
Junilu

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
To elaborate on the rope problem:

we divide 30-minute rape in two parts and light them from both ends. They are supposed to burn in 30/4 = 7.5 sec. Now our challenge is to keep all four fires running. So we wait when the first of ropes is burnt, then immediately cut the other one in two pieces and burn them from all two ends again...

Junilu, it is possible - I tried. Of course, now my house is burnt too, but it is not important, as long as we can find a solution

[This message has been edited by Mapraputa Is (edited June 02, 2001).]

Junilu Lacar
Bartender
Posts: 7568
52
Originally posted by Mapraputa Is:
Junilu, it is possible - I tried. Of course, now my house is burnt too, but it is not important, as long as we can find a solution

Yes, I suppose it is possible in the sense that there comes a point where it won't make a difference to keep cutting and re-lighting ropes anymore (although you have to keep just 4 ends lighted at the same time to measure 7.5 minutes).
A lot like the problem that asks "Given points A and B, if you start from A and travel half the distance AB in one step, then half the remaining distance on the next step, and half the remaining distance on the next and so on, how many steps will it take for you to get to B?" Theoretically, the number of steps are infinite but I would consider myself practically at B after just a few steps.
Don't you folks have anything better to do on a Saturday afternoon though? My excuse is that my wife and kids are napping and its cold and raining outside.
Junilu

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Well, when I first mentioned the 7.5 minute possibility, I did say it would take an infinite number of steps to make it exact. And I further specified that I was assuming you could light and cut things in zero time. Because it's true that there are some definite problems with implementing this solution in the real world - but you can get an arbitrarily close approximation to 7.5 minutes before you tire of relighting things, and decide that you're close enough.
Incidentally, you don't actually need to do any cutting for this solution. Just light each rope in what you think is the middle, and it should start burning in both directions. You only need a knife if you want to light an odd number of firses - e.g. for 10 minutes, chop the 30-min in two, and light 3 out of four ends. Make sure there are always three fires burning at any time. Whenever one fire goes out by itself, if there are no other ends currently unlit, find an unused sction of rope, chop it in two, and light one end. If two fires meet and extinguish each other, then just start a new fire somewhere in the middle of still-unburnt segment.
> Don't you folks have anything better to do on a Saturday
> afternoon though? My excuse is that my wife and kids are
> napping and its cold and raining outside.
I'll have you know that I was out finding a new apartment today, thank you. Actually I found two - still need to decide. It's much easier than it would hav been at the beginning of the year or earlier - for some reason, there are a lot more vacancies in Silicon Valley recently. Map, if you need to relocate after burning down your place, give me a call - I'm sure we can set you up.
Junilu- love the Jugglemaster applet. Very cool; thanks for the link. By the way, I gather you're Filipino? Is the "J" in your name pronounced as "H", like in Spanish? Just curious - I like to imagine that I know how to pronounce people's names at least somewhat correctly, even if I never meet them in person. Of course in Map's case, the mispronunciation has taken on a life of its own, but that's another story...

Junilu Lacar
Bartender
Posts: 7568
52
Yep, I'm a Pinoy from Iligan City, Philippines. Looking to make Columbus, OH my home for a while though.
And it's "J" as in "Junior," which I am, as are a lot of other Filipinos. Only my dad (Luis) decided to be creative and melded his name with "Junior". Thanks for asking though.
I never realized this particular forum could be so much fun. Glad I decided to check it out.

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
I would not blame Jim for unractical solution. He did his best with impossible rope. Think again: we have a rope with inconstant speed of burning. So how you can cut a piece of such rope and guarantee it will be burnt in 30 or 60 minutes if not by prior burning?
Actually, that may be possible by measuring other parameters... And if it is possible, we do not need infinite lightenings for measuring 7.5 or 10 or whatever minutes.

Sahir Shibley
Ranch Hand
Posts: 275
Originally posted by Jim Yingst:
[B]Sahir- the accuracy of your result will improve substantially if you replace
<code><pre> if(distance < 1) break ;</pre></code>
with
<code><pre> if(distance <= 0) break ;</pre></code>
Or are 1 and 0 considered equivalent in VB?
[B]

Yes I see your point. I forgot that the value being tested isn't an integer. Even VB programmers make mistakes
So, after the bugfix, I have an error factor of 0.0000000000001%
Regarding the rope problem. There is a roundabout way to measure 7.5 minutes. Slice the ropes into two sections (provided the reduced thickness doesnt afffect the burn rate. Ideally this can be done with two half hour ropes). Lets call them rope A and B.
1. Burn A at both ends.
2. Burn B at one end
3. When rope A has finished burning rope B has 15 minutes left.
4. Now light the other end of rope B. The remaining part of rope B will finish in 7.5 minutes.

[This message has been edited by Sahir Shibley (edited June 04, 2001).]

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
Originally posted by Mapraputa Is:
�An extensible and reusable, object oriented railroad fly� was ingenious! And such an outstanding exactness! Thomas Paul can be proud of you.
Sorry I didn't see this sooner. As javaRanch Guru of OO I am required to spend my weekends on top of a mountain answering questions.

Anonymous
Ranch Hand
Posts: 18944
if you think of his paths as two overlaid graphs, that show y=altitude and x=time travelled, you will get two continuous slopes, one going up, the other down, over the same x-range, with a same y-range. it is therefore mathematically impossible for the two slopes -not- to cross, even if the two slopes aren't exactly straight (they can even be pretty messy!) you will always know that at some point during their trip, they were at the same altitude. furthermore, since both x and y will match, time of day since departure will be the same, so it will be the same time of day during each trip. therefore, you know that, at some point during the day, each way, the monk was at the exact same spot along the mountainside.
btw - microsoft uses the rope puzzle during interview =) and this monk thing was used by a philosophy prof. at my school as extra credit on a test (drivel!)

Rui Pinheiro
Greenhorn
Posts: 2
Hello!
Sorry if that thread was put in the ancient forum history and no one is interested on it, but if there are some people that can help me, I will be very pelasured
I had that 2-rope problem in a job interview last month, with a small variation: each rope burns in 1 hour and I have to find out how to measure 15 min. I discovered it with exactly the same procedure you described here: first I burn 3 points of the 2 ropes, when the 2-points burning rope met I start counting the time and burn the remaining point. When these last points met, I stop counting time and the clock marks 15 min.
So I got the job eheh - but I became curious with that problem because I have a feel I can do it with only ONE rope! But I could not find an "acceptable" answer.
The better I could do was using Einstein's Theory of Relativity, placing me in a referential moving fast in the direction of the rope, making the perception of the time (from my point of view) to reduce to half. So I see the only one rope burning out in 15 min (when both points met) and not 30 min (as measured in the rope referential).
But that need some profound physic knowledge and I would like to find a solution that doesn't need more knowledge than a normal people has.
Do you have any ideas? I read all these posts and I could not find some useful help.
Thank you!
Rui Pinheiro