?

Log in

No account? Create an account

Logic puzzle - John C. Kirk

Apr. 25th, 2009

11:42 am - Logic puzzle

Previous Entry Share Next Entry

Over at the Microsoft Press blog, they've been promoting Inside Microsoft SQL Server 2008: T-SQL Querying. As well as the blurb about the book itself, they have a logic puzzle:

Two trains race toward each other on a railway segment that’s 100 miles long. The trains are traveling at 100 mph. A mosquito flying at 200 mph flies from one train toward the other, and as soon as it arrives at the other train, it flips its direction and flies back toward the first train. The mosquito continues bouncing back and forth between the trains until the trains crash. What’s the total distance that the mosquito covers until the moment of the crash?


This is taken from the book, which implies that it could be solved by using a SQL query. I'd be more inclined to do something in Excel, i.e. calculating the relative positions of the trains and the mosquito after each minute has passed, then adding up the total distance travelled. Still, either approach is inelegant, and I think I've now found a neater solution.

Basically, I think it's a bit of a trick question. If the trains start out 100 miles apart, and they each travel at 100mph, it will take them 30 minutes to travel 50 miles, then they'll crash. If the mosquito is flying back and forth continuously for that 30 minutes, at 200mph, it will travel 100 miles. We don't need to know the exact positions of the trains each time it "bounces".

Tags:

Comments:

[User Picture]
From:bazzalisk
Date:April 25th, 2009 12:57 pm (UTC)
(Link)
Can't fault your logic on that one.
(Reply) (Thread)
[User Picture]
From:gaspodog
Date:April 25th, 2009 03:30 pm (UTC)
(Link)
One of those questions that tries to trick you into thinking it's harder than it is ;)

Why on earth you'd want to solve it using an SQL query I don't know...

(Reply) (Thread)
[User Picture]
From:pozorvlak
Date:April 26th, 2009 10:45 am (UTC)
(Link)
Yep. That's exactly the cunning trick that the problem requires.

I'm really struggling to see how an SQL query would help...
(Reply) (Thread)
[User Picture]
From:johnckirk
Date:April 26th, 2009 01:30 pm (UTC)
(Link)
In fairness, I'm only guessing at the reason it was included in the book; it might be for some other reason completely. They said on the blog that they'd reveal the answer next week, so hopefully that will clarify things.
(Reply) (Parent) (Thread)
[User Picture]
From:sammoore
Date:April 27th, 2009 08:12 am (UTC)
(Link)
This is a well known "lateral thinking" problem, I think first presented by Edward de Bono in the 60s.

If you are interesting the the sort of puzzles/tricks/techniques that Microsoft use for recruiting I can recommend this book.

How Would You Move Mount Fuji
(Reply) (Parent) (Thread)