CODE WARS ]I[ PROGRAMMING COMPETITION
Symbolic Artificial Intelligence (AI)
Problem 11 Division I 12 Points
Problem Statement
You have been given the job of writing a simple symbolic AI processor which must read some facts and correctly answer some questions. Fortunately, the facts and questions relate to specific individuals, who belong to groups which act on other groups. The grammar is very simple: there are two types of statements and one type of question, and all group nouns are always plural.
Program Input
Each line of PROG11.IN contains a statement or a question. The end of the input is indicated by a line whose first character is a #. Each line has one of the following forms:
  • A statement of the form "<noun1>s <verb> <noun2>s." This means members of group <noun1> do <verb> to members of group <noun2>.
  • A statement of the form "<id> is a <noun>." This means that the particular individual <id> belongs to group <noun>.
  • A question of the form "Does <id1> <verb> <id2>?" This asks whether <id1> does the action <verb> to <id2>.
  •      Lines are up to 80 characters long. Words are up to 40 characters long and may consist of upper and lower case letters, although searches should be case insensitive. There may be multiple spaces between words, but there are never spaces between words and the punctuation. Allow for up to 100 facts in the input.

    Dogs chase cats.
    Dogs like kids.
    Fido is a dog.
    Fluffles is a cat.
    Lydia is a kid.
    Does Fido chase Fluffles?
    Does Fluffles chase Fido?
    Does Fido like Lydia?
    #
    Program Output
    For each question, the program should (1) echo the question to PROG11.OUT, and (2) print 'Yes' if the "facts" imply that the question is true, and 'No.' otherwise.
    Does Fido chase Fluffles? Yes.
    Does Fluffles chase Fido? No.
    Does Fido like Lydia? Yes.

    source: 1995 ACS Australian Programming Competition.