One of the earlier games that came out of the first computers was the so-called Animal game. The game would be to have the computer try to guess what animal the person was thinking of by asking a series of yes or no questions. If the animal was not identified, then the computer would ask the user to type in some question that would identify the user's animal from any other animal that would be classified in the current line of questioning. For example, a run of the program might go like (C == computer, U == user):

C> Is your animal smaller than a breadbox?
U> n
C> Is your animal a cat?
U> n
C> What is your animal?
U> sparrow
C> Please enter a question that would be true for a bird, but false fo+r a cat:
U> Does your animal have wings?
# Next iter #
C> Is your animal smaller than a breadbox?
U> n
C> Does your animal have wings?
U> Y
C> Is your animal a sparrow?
U> n
C> What is your animal?
U> chicken
C> Please enter a question that would be true for a chicken, but false+ for a sparrow:
U> Can your animal fly?
# ETC... #

In other words, the computer would become more intelligent as more replies were added. Of course, this assumes that the user was faithful in entering replies and had a sufficiently good set of distinguising questions to separate out one type of animal from another.

Now, for the golf: Write an engine that does the above in as few characters as possible. Of course, to help, you've got 4 'free' functions that you can use:

a($question) asks the user the passed $question, and returns either true if the user replied yes to it, or false otherwise.

g($animal) asks the user if their animal is $animal. Returns true if so, false otherwise. THIS IS NEW IN UPDATE

t() asks the user what their animal is, and returns the answer the user gives

i($guessed, $user) asks the user to identify a question that is true for $user but false for $guessed (where $guesses should be what the computer guessed).

w() asks the user if they want to continue; true if so, false otherwise (and should end the program).

You may also preinitialize any data structure for 'free' with a single question and the y/n answers for it. (Such as "Is your animal larger than a breadbox?" with 'giraffe' for true, 'housecat' for false).

Everything else inside the code block that does this will count as strokes to the golf score. You can use any data structure that you like. No extra modules, however, but the program need not be strict or -w compliant.

Update As tilly's solution indicates, I missed one 'free' function, the g() function which does the final guess (as described in the problem statement). Also, indirectly replying to tilly, assume the free functions return 0 or 1 for false or thuth, respectively. (I'm figuring the 0 value is more useful for further golfing). Also, don't worry about 'a' vs 'an'. Assume that you can decide which is appropriate in the free functions, and doesn't need to be handled by your golf sub.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"It's not what you know, but knowing how to find it if you don't know that's important

The main caveat is that I can add or lose characters depending on exact behaviour of these additional functions. (Particularly important is the behaviour of "a". I assumed that it returned 0,1 and added returns on prints but not a ?.) Here are the exact functions as I used them for my solution:

Nice solution, but it really gets thrown out if you
pick the same two animals in alternation.

Starting a new game.
does your animal have feathers?
y
Is your animal a chicken?
n
What is your animal?
sparrow
Please enter a question that would be true for a sparrow, but false fo+r a chicken:
is your animal smaller than your fist?
Do you want to continue?
y
Starting a new game.
is your animal smaller than your fist?
n
Is your animal a chicken?
y
Do you want to continue?
y
Starting a new game.
Is your animal a chicken?
n
What is your animal?
sparrow
Please enter a question that would be true for a sparrow, but false fo+r a chicken:
is your animal smaller than your fist?
Do you want to continue?
y

This is my second attempt at Perl Golf. Although my score (281) sucks, I wanted to post my code because I had a hard enough time just getting it to work at all. :-) I know I could make my code more concise, but I've run out of time! I've got to actually get some work done today!

Here is my entry in the Golf game, but with some additions
that may throw me off the tour.
I made two data structures @a for animals and @q for
questions. I then update these inside of the allowed
subs that are/were outlined in the rules. With that said
I am at ~111 characters in my do_it sub.