Perl 'Expert' Quiz-of-the-Week #10

Mark Jason Dominus <[email protected]> Tue, 28 Jan 2003 15:37:22 -0500
Newsgroups gmane.comp.lang.perl.qotw.quiz-of-the-week
Organization Plover Systems
Message-ID <[email protected]>
IMPORTANT: Please do not post solutions, hints, or other spoilers
        until at least 60 hours after the date of this message.
        Thanks.

IMPORTANTE: Por favor, no enviéis soluciones, pistas, o cualquier otra
        cosa que pueda echar a perder la resolución del problema hasta
        que hayan pasado por lo menos 60 horas desde el envío de este
        mensaje. Gracias.

IMPORTANT: S'il vous plaît, attendez au minimum 60 heures après la
        date de ce message avant de poster solutions, indices ou autres
        révélations. Merci.

WICHTIG: Bitte schicken Sie keine Lösungen, Tipps oder Hinweise für
        diese Aufgabe vor Ablauf von 60 Stunden nach dem Datum dieser
        Mail. Danke.

BELANGRIJK: Stuur aub geen oplossingen, hints of andere tips in de
        eerste 60 uur na het verzendingstijdstip van dit
        bericht. Waarvoor dank.

VNIMANIE: Pozhalujsta ne shlite reshenija, nameki na reshenija, i
        voobshe lyubye podskazki v techenie po krajnej mere 60 chasov
        ot daty etogo soobshenija.  Spasibo.

Qing3 Zhu4Yi4: Qing3 Ning2 Deng3Dao4 Jie1Dao4 Ben3 Xin4Xi2 Zhi1Hou4 60
        Xiao3Shi2, Zai4 Fa1Biao3 Jie3Da2, Ti2Shi4, Huo4 Qi2Ta1 Hui4
        Xie4Lou4 Da2An4 De5 Jian4Yi4.  Xie4Xie4.

----------------------------------------------------------------

Here's something I've wondered about for several years, but never
finished looking into.  Consider the 'guess-the-animal' program of
regular QOTW #10.  Suppose the question tree looks like this:

                Does it fly?
                     /\
                yes /  \ no
                   /    \
          Does it have   salmon
              feathers?
                 /\
            yes /  \ no
               /    \
            carrot  fruit
                     bat

For some reason, the database records the 'fact' that carrots fly and
have feathers.  Back around 1994, I had a CGI guess-the-animal
program, and people put in all sorts of nonsense like this.  

If the user is thinking of a sparrow, then the carrot is a little
silly, because the game will go like this:

        COMPUTER                HUMAN

        Does it fly?            yes

        Does it have feathers?  yes

        Is it a carrot?         (huh? whatever...)  no

        I give up.  What animal
          were you thinking of? sparrow

        What is a question that  Is it orange?
          would distinguish a 
          carrot from a sparrow?

        For a sparrow the answer
          would be?               no


And now the tree looks like this:

                Does it fly?
                     /\
                yes /  \ no
                   /    \
          Does it have   salmon
              feathers?
                 /\
            yes /  \ no
               /    \
            Is is   fruit
           orange?   bat
             /\
        yes /  \ no
           /    \
        carrot sparrow


But now suppose someone comes along who knows a little bit more about
carrots:

        COMPUTER                    HUMAN

        Does it fly?                no

        Is it a salmon?             no

        I give up.  What animal     carrot
          were you thinking of?

        What is a question that     ...
          would distinguish a 
          carrot from a salmon?

        ...                         ...

Now there will be two carrots in the tree.

What I'd like to see is for the computer to recognize that it now has
contradictory information about carrots:

        
        I give up.  What animal         carrot
          were you thinking of?

        Someone told me before that     yes
        carrots do fly, but you said 
        they didn't.  Are you sure?

And then the program should amend the database as appropriate, perhaps
resulting in:

                Does it fly?
                     /\
                yes /  \ no
                   /    \
          Does it have   Is it crunchy?
              feathers?          /\
                 /\         yes /  \ no
            yes /  \ no        /    \
               /    \       carrot  salmon
           sparrow  fruit
                     bat