#!/usr/bin/perl 'As I was going to St. Ives', 'I met a man with seven wives', 'Each wife had seven sacks', 'Each sack had seven cats', 'Each cat had seven kits', 'Kits, cats, sacks, and wives', 'How many were going to St. Ives'? how_many: do { $wives = 7; $how_many = $wives; $sacks = 7; $how_many += $wives * $sacks; $cats = 7; $how_many += $wives * $sacks * $cats; $kits = 7; $how_many += $wives * $sacks * $cats * $kits; }; print int $how_many;

Update: for those interested in declaring the answer is 0, 1, 2800, or "who knows", here's a link discussing the relative merits of this riddle and some possible answers.

Replies are listed 'Best First'.
Re: St. Ives
by cLive ;-) (Prior) on Dec 22, 2003 at 16:58 UTC
    Except they're leaving St Ives, as the story goes. You're the only one going to St Ives. That's how you meet them on the way. Perhaps change the last line to:
    print $how_many > 0;
    and make it a little obfu for the half asleep :)

    .02

    cLive ;-)

    Update: LoL - no, but it's still should be one and not zero (IMHO :)

    print $how_many >= 0;
      Now I have to ask you the question I am expecting in response to my comment ... Did you actually execute the code? :-)
Re: St. Ives
by duff (Parson) on Dec 22, 2003 at 17:04 UTC

    Interesting, but unfortunately it gives the wrong answer.

      I disagree. There is debate over whether or not the answer is supposed to include the traveler, or only the wives, sacks, cats and kits.

      This code answers the question assuming the traveler should not be counted.

        How strange that there would be any debate at all. The point of the riddle is to obfuscate by adding irrelevant information. The ultimate question is "how many were going to St. Ives" to which there is only one answer deducible from the text. The answer your program gives defies "common sense" logic.

        What are the arguments that the traveller should not be counted? Because the question seemingly restricts the set of things to be counted? That's just part of the obfuscation. I guess debate is what happens when "learned" people mess with a good riddle ;-)

        In any case, good use of punctuation! :-)