File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programming Diversions and the fly likes [easy] Frogs and Burt Bacharach. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "[easy] Frogs and Burt Bacharach." Watch "[easy] Frogs and Burt Bacharach." New topic

[easy] Frogs and Burt Bacharach.

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Yes, I'm in a whimsical frame of mind. Stop me if you've heard this one:

(hopefully I have the numbers atleast plausible, I just made them up and ran a quick check)

There is a pond which has a radius of 1 meter. In the middle of the pond is a frog. It is not crazy. The frog can swim in the pond at 1 meter per second. It cannot move any faster due to any other effects.

Circling the pond trying to catch the frog is Burt Bacharach. Why? No idea. Burt can circle the pond at 2 meters per second.

It should be clear that if the frog heads for any point on the edge of the pond, Bert can get there first. If the frog can get to the edge first, Burt will sing "Raindrops Keep Falling on My Head". How does the frog win and get his song?
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1046
Umm... am I missing something? Can't the frog just swim for the shore directly opposite Burt? It should take the frog 1 sec to cover that 1m radius. Burt, on the other hand, has to cover PI * 1m at 2 m/sec, which would take him about 1.57 seconds.

Start singin', Burt.
[ November 29, 2005: Message edited by: Ryan McGuire ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Oops, there's the mistake. Assume Bert can travel twice that speed. I'll chck the math still holds later. Sorry, it was after a beer or two
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

It should work with the new numbers, the answer I get is about 0.03s
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
The frog chooses a value r such that

(1 - π/4) < r < 1/4

i.e. approximately

0.2146 < r < 0.25

The higher r is, the greater the safety margin he'll have (time difference between when he reaches shore band when Burt gets to the same spot) but the more time it will take to get to the shore. It's up to the frog how much time he wants to take. Anyway, pick a value of r. Move to a distance r from the center of the pond. Travel in an arc (centered on the center of the pond) until the center of the pond is directly between Burt and the frog. As long as r < .25, the frog can circle more quickly than Burt, so eventually he can be 180° opposite Burt. Once that is achieved, head straight for shore. As long as r > 1 - π/4, the frog can beat Burt.
[ November 30, 2005: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Sameer Jamal
Ranch Hand

Joined: Feb 16, 2001
Posts: 1870
Hope that frog can understand you Jim.
I agree. Here's the link:
subject: [easy] Frogs and Burt Bacharach.
It's not a secret anymore!