aspose file tools*
The moose likes Programming Diversions and the fly likes The Snail and the Car Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "The Snail and the Car" Watch "The Snail and the Car" New topic
Author

The Snail and the Car

Piet Souris
Ranch Hand

Joined: Mar 08, 2009
Posts: 322
    
    2
Yesterday evening, many tv stations were broadcasting this 'Eurovision Song Contest'.
Now I don't like that, so I was reading some book when suddenly I remembered
two old puzzles I was confronted with many moons ago. The first one I'll present in this topic,
the other one in the next.

About 40 years ago, when I just had started working in some office and when computers
were never heard of, a collegue gave me this problem:

We have a car, a tree and a rubber band that is attached to both the car and the tree.
Needles to say that this rubber band can stretch forever without any problem!

The car is driving at a certain speed. Now, at a certain moment in time, a snail comes
creepin from the tree up to the rubber band and starts to creep towards the car.

The question is: will this snail ever reach the car?

Back then, when my maths were far less rusty than they are now, I was (after a long time
and with a lot of effort) able to solve it. As I said, we had no computers then, so yesterday
evening it appeared to me that I never tried to solve it numerically, on a computer.

So: write a program that answers the question: 'yes', 'no' or 'depends'.

Have fun!

Greetings,
Piet
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4244
    
    7



Seriously, though, that's a nice little problem. I don't think it's obvious what the result is going to be before you calculate it. But I was more interested in the mathematical solution, which I'll post later if anyone's interested (or, at least, I'll post what I think is the solution!).
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3450
    
  47

Doesn't the answer depend on the speed of the snake relative to the car, and - also - on the way the snake actually crawls on the rubber band?

In any case, I'd say the snake will die. Either the rubber band will get so thin that it will cut the snake into pieces, or it will - due to the curvature of the Earth - press the snake against the ground. Poor snake!
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4244
    
    7

Well, yes, subject to the usual caveats and assumptions (like an infinite straight road, an immovable tree, an infinitely stretchable elastic band - oh yes, and a car that can generate unlimited power to maintain a constant velocity as the tension increases). I also assumed the speed of the snail to be constant relative to the local velocity of the elastic band. Then, if my calculation is correct, the snail eventually catches up with the car regardless of how slowly it's moving as long as the speed is positive.

No idea about the snake, though .
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10923
    
  12

doesn't it somewhat depend on how exactly the band stretches under the snail?

Assume the snail was perfectly still, and was 10m from the tree. if the band is frictionless, inertia would keep the snail where he is relative to the ground, so the car would continue to pull away. If the car is travelling faster than the snail, he can never catch up.

However, if there is friction, then if the snail is 10m from the tree and 10m from the car, when the band is stretched to 40 meters, I assume the snail ends up at the 20m mark?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4244
    
    7

fred rosenberger wrote:However, if there is friction, then if the snail is 10m from the tree and 10m from the car, when the band is stretched to 40 metres , I assume the snail ends up at the 20m mark?

That's what I assumed. If there's no friction, I don't think the snail is going far!
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3450
    
  47

Matthew Brown wrote:Well, yes, subject to the usual caveats and assumptions...

If you add a point-like snail to the list of assumptions, I'd agree that the snail safely reaches the car

Just don't tell Zeno of Elea.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4244
    
    7

Martin Vajsar wrote:Just don't tell Zeno of Elea.

As a Terry Pratchett character says when faced with a similar argument (about an arrow never catching up with a tortoise), "I've got a stack of tortoise kebabs that says different".
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3450
    
  47

Matthew Brown wrote:No idea about the snake, though .

Easy. "Snake" and "snail" sound nearly the same to me. I've realized my mistake only now.

In any case, I've pondered whether the snail and the car could be an analogy to the light travelling in an expanding Universe, and then it dawned to me: the snail will reach the car, but it will be redshifted during its journey.
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 865
    
    5
Matthew Brown wrote:the mathematical solution


It leads a simple differential equation.
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 865
    
    5
Let us denote the initial length of the rope with s, the velocity with v and the position of the snail x(t), being a function of time.

The velocity of the snake stems from two components: one is its own speed "w" against the rope plus the speed gained from drifting on the rope.
At the position x(t) of the rope of the length (s+vt), the proportional speed of this position on the rope is v.x(t)/(s+vt)

So at the end we get this differential equation:

x'(t) = w + x(t).v / ( s + v.t)

Let us denote s/v=t0 so we have

x'(t) = w + x(t) / ( t + t0 )

Now let us consider the ratio x(t)/(t+t0). Its derivative will prove to be a known function!

(x(t)/(t+t0)) ' = [ x'(t)*(t+t0)-x(t) ] / (t + t0)^2 = [ x' - x/(t+t0) ] / (t+t0) = w / ( t + t0)

Given the fact x(0) = 0, we obtain as below (with ln = natural logarithm, whose derivative is ln'(t) = 1/t )

x(t)/(t+t0) = w. ln ( (t+t0) / t0 )


The snail reaches the other end of the rope at time t when

x(t) = s + vt = v ( t + t0)

that is when
w.ln( (t+t0)/t0 ) = x / ( t + t0) = v

ln( (t+t0)/t0 ) = v/w

exp(v/w) = (t+t0)/t0

t = t0 ( exp(v/w) - 1 )


A sidenote: the notation 'u' (instead of 'w') did not work. The forum software rejected it. It is told to be a silly English abbreviation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Snail and the Car
 
Similar Threads
How to output int array as string
Coderanch vs StackExchange (StackExchange = StackOverflow + Programmers + Careers, Workplace etc.)
Time complexity for my palindrome detection algorithm?
What do you mean by "Applied" patterns..
Why is modulo operator producing these results