• mina86.com

  • Categories
  • Code
  • Contact
  • A.I.

    Cleaning Tiny Applications Collection, I’ve dropped both artificial intelligence scripts. Not wanting to let them disappear completely, I’m posting them here for posterity. The first one is an eight line of code version that might be what Sid wrote as his first ever program:

    #!/usr/bin/perl -wWtT
    while (<>) {
    	if (/[aeiouyAEIOUY][^a-zA-Z]*$/) {
    		print "Yes.\n";
    	} elsif (!/^\s*$/) {
    		print "No.\n";
    	}
    }
    USER FRIENDLY by IlliadCopyright © 1999 by J.D. “Illiad” Frazer I remember the first program I ever wrote was an “A.I.” that could play 20 questions. You could ask it any question in an attempt to guess what thing it was thinking about and it would answer yes or no. And I did it with only eight lines of code. Did you say eight lines of code? Yep! My friends never did guess the right answer. They asked Is it blue?” and it answered Yes.” Then, “Is it bigger than a breadbox?” It answered “No. Is it smaller than a breadbox? It answered “No.” “Does it go wiki-wiki-wiki?” It answered “Yes. Uh… It was thinking about a blue breadbox that goes wiki-wiki-wiki? The trick was in the code. It answered “Yes” to any question that ended in a vowel.
    UserFriendlsy comic strip for 2000-10-14 in which Sid describes his eight-line AI program.

    The second is a six-line version akin to Pitr’s code:

    #!/usr/bin/perl -wWtTn
    if (/[aeiouyAEIOUY][^a-zA-Z]*$/) {
    	print "No!\n";
    } elsif (!/^\s*$/) {
    	print "Yes.\n";
    }
    USER FRIENDLY by IlliadCopyright © 1999 by J.D. “Illiad” Frazer Pitr. You’re going to be at this for ages. You do realize the complexities involved in coding an artificial intelligence? Am makink good headway already. A.I. can answer any “da or “nyet” question. You try, Mikhail. All right. Computer, is my name Mike Floyd? Yes. Okay. How did you do that with only six lines of code? Simple algorithm. If question endink in vowel, answer is “nyet,” else answer is “da. Very clever Pitr is, da? No! TAK TAKK TIK
    UserFriendlsy comic strip for 1999-06-02 in which Pitr describes his six-line AI program.

    Below is recreation of the scenes from the UserFriendly comic strips:

    $ ./ai-sid.pl
    Is it blue?
    Yes.
    Is it bigger than a breadbox?
    No.
    Is it smaller than a breadbox?
    No.
    Does it go wiki-wiki-wiki?
    Yes.
    ^D
    $ ./ai-pitr.pl
    Is my name Mike Floyd?
    Yes.
    Very clever Pitr is, Da?
    No!
    ^D

    Interestingly, each version give opposite responses to the same question. Joining their standard inputs with standard outputs (as to make them talk with each other) does not yield interesting results.