A.I.

Posted by Michał ‘mina86’ Nazarewicz on 22nd of September 2013

While cleaning Tiny Applications Collection a little I’ve dropped both artificial intelligence scripts. However, not wanting to let them disappear, I’ve decided to post them here for posterity.

The first one is an eight line of code version that might be what Sid wrote as his first program ever:

#!/usr/bin/perl -wWtT
while (<>) {
	if (/[aeiouyAEIOUY][^a-zA-Z]*$/) {
		print "Yes.\n";
	} elsif (!/^\s*$/) {
		print "No.\n";
	}
}

The second one is an ‘improved’ 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";
}

Below is recreation of the scenes from 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, both versions 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.