http://www.perlmonks.org?node_id=140734

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... #
[download]```
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