This week's book giveaways are in the Refactoring and Agile forums.We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

# Simple - Hourglass

Eric Pascarello
author
Rancher
Posts: 15385
6
You have three hour glasses 9, 11 and 14 minutes. You need to measure 7 minutes. How do you get 7 minutes in the shortest elapsed time and the longest elapsed time?

Eric

Nick George
Ranch Hand
Posts: 815
Easy first answer, not sure if it's the shortest:
Fire up the 9 and the 11. When the 9 finishes, restart it. When the 11 finishes, fire up the 14. When the second 9 finishes, you have 7 minutes before the 14 ends.

Jim Yingst
Wanderer
Sheriff
Posts: 18671
It's possible to measure 7 minutes in 16 minutes elapsed time, starting with all hourglasses drained. I think that's the shortest possible.

I don't think there is any "longest elapsed time" - you can extend the process indefinitely.

Nick, in your solution you don't need the 14 at all. There were 7 minutes between the end of the 11 and the end of the second 9. 18 minutes elapsed. (Rather than 25 using the 14.)

Nick George
Ranch Hand
Posts: 815
Well, I'll be damned. It would seem that 11-9=2, not 3.

Eric Pascarello
author
Rancher
Posts: 15385
6
Ah, I messed up the question, I typed one while preparing another one.

You have three hour glasses 9, 11 and 14 minutes. You need to measure 7 minutes. How do you get 7 minutes in the shortest elapsed time using all three and the shortest elapsed time using only 2 of the three timers. Your choice with two of them.

Eric

Joyce Lee
Ranch Hand
Posts: 1392
You have three hour glasses 9, 11 and 14 minutes. You need to measure 7 minutes. How do you get 7 minutes in the shortest elapsed time using all three and the shortest elapsed time using only 2 of the three timers. Your choice with two of them.

Are we allowed to stop an hourglass halfway? If allowed, I think the shortest elapsed time using all three hourglasses is 16.

The shortest elapsed time for two hourglasses is 18. I chose 9 and 11. Start both hourglasses. Restart the 9 mins hour glass when it ends. When the 11 mins hourglass ends, the 9 mins hour glass left 7 minutes.

Eric Pascarello
author
Rancher
Posts: 15385
6
How would you know that it was exactly halfway?

Jim Yingst
Wanderer
Sheriff
Posts: 18671
I think Joyce means, are we allowed to set an hourglass on its side while it's running, thereby stopping it (presumably to be restarted later). That's what I did to get 16 too. I also agree that 18 minutes using the 9 and 11 seems to be the best possible solution for two hourglasses. Note that this solution was also present in Nick's earlier answer.

Joyce Lee
Ranch Hand
Posts: 1392
Originally posted by Eric Pascarello:
How would you know that it was exactly halfway?

Okay, not halfway. Start three hourglasses. When the 9 mins hourglass ends, stops the 14 mins hourglass (left 5 mins). The 11 mins hourglass left two minutes and when this ends, the 14 mins hourglass can be continued for the next 5 mins.