Alpha DevCon 2018
Results 1 to 6 of 6

Thread: Programming Puzzle 22 - What do you Mean?

  1. #1
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default 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?

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default 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?
    Last edited by Tom Cone Jr; 05-07-2012 at 03:48 PM.

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default 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

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default Re: Programming Puzzle 22 - What do you Mean?

    And here's the answer to part (B) ---> 40 MPH. Agree? Disagree?

  5. #5
    Member
    Real Name
    Tony Evans
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    46

    Default Re: Programming Puzzle 22 - What do you Mean?

    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.

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default 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

Similar Threads

  1. Programming Puzzle 3 - Fractions, anyone?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 11-08-2011, 05:40 AM
  2. Programming Puzzle 21 - Got ini ?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 5
    Last Post: 09-08-2011, 09:19 PM
  3. Programming Puzzle 11 - More Loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 11
    Last Post: 08-20-2011, 04:50 PM
  4. Programming Puzzle 13 - Paycheck Amount?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 3
    Last Post: 08-12-2011, 02:27 PM
  5. Programming Puzzle 6 - Another nested loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 6
    Last Post: 08-08-2011, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •