# Programming Puzzle 22 - What do you Mean?

• 05-03-2012, 08:59 PM
Tom Cone Jr
Programming Puzzle 22 - What do you Mean?
After a long sabbatical another puzzle has emerged from the mists.

This puzzle has two parts.

a) Assume you purchase two bags of jelly beans at the store. One bag contain 100 jelly beans. The other only 50. Write an xbasic script that will compute and display the average number of jelly beans in the two packages. For extra credit dump your results to the trace window.

b) Assume you drive to a holiday resort at 60 mph. You're in a hurry to get there, right? After your holiday, you head back home traveling the same route, but you only drive at 30 mph. You're not in a big hurry to get back to work! Write an xbasic script that will compute and display your average speed. For extra credit dump your results to the trace window.

** this puzzle is based on a recent blog posting by Al Williams, one of Dr. Dobb's Bloggers. AFTER you've taken a crack at solving this puzzle feel free to check it out. Here's the link. But, please, no peeking ahead of time, ok?
• 05-04-2012, 10:54 AM
Tom Cone Jr
Re: Programming Puzzle 22 - What do you Mean?
Does this seem too easy?

The answer to part (A) of course is 75. However, the answer to part (B) is NOT 45. Maybe these hints will whet your curiosity?
• 05-07-2012, 04:44 PM
Tom Cone Jr
Re: Programming Puzzle 22 - What do you Mean?
No takers!

Ok, here's a solution for the first part of the puzzle. Import it into Alpha Five database and run it from the control panel.

-- tom
• 05-07-2012, 06:11 PM
Tom Cone Jr
Re: Programming Puzzle 22 - What do you Mean?
And here's the answer to part (B) ---> 40 MPH. Agree? Disagree?
• 05-18-2012, 07:51 PM
Tony Evans
Re: Programming Puzzle 22 - What do you Mean?
Quote:

And here's the answer to part (B) ---> 40 MPH. Agree? Disagree?
Yes, I agree.
The other correct answer is 45 MPH unless the admonition in the 8:54am post is part of the puzzle.

I was about to add that further discussion of this comment is off topic if this is about programming. A second later, I realized that this is central to efficient programming. A better response on my part would have been: "Yes, I agree."
Regardless of what I think is relevant about average speeds, it is clear from the way that you posed the answer, that what you were looking for was the average rate over time, rather than over distance. When we set out to write programs, it is easy to mistakenly think we understand the desired result. There is much that we can do to mitigate this peril, ... and that's the start of a long discussion.
• 05-23-2012, 08:09 AM
Tom Cone Jr
Re: Programming Puzzle 22 - What do you Mean?
Tony, that's precisely the point. When the customer says they want an "average", it pays to get specifics.

-- tom