I was looking at one of those "Shakespearian Insult Kits" that has three rows of words which you can randomly slap together and add "Thou" to the beginning to make a quick insult. The end result is usually pretty funny, but got sort of boring after a while. That got me thinking about using something like a genetic algorithm to come up with better ones using peoples ratings of previous ones. So what this script does is present the visitor to the website with a insult generated by taking words from three files and adding "Thou" to the beginning. Then they can rate the insult good,okay, or bad. If they rate it good the words used in the insult will become more likely to show up next-time. If they rate it bad, the words used will be less likely to show up. If they rate it okay, the words remain just as likely to show up as before. Theoretically this should lead to the perfect Shakespearian insult accoording to the combined opinions of the visitors. It can also deliver an insult to your palm, using avantgo, so you can try it out on people during the day and then rate it from your palm. You can get the avantgo channel here. If you'd like to check it out with the normal web interface and rate a couple go here. The code that runs it is:
#!/usr/bin/perl use CGI qw(:standard); #Shakespear Lives! my $mode = param("mode"); if ($mode eq "palm") { print header; open(ONE,"/home/perlmonk/public_html/shakespear/one"); open(TWO,"/home/perlmonk/public_html/shakespear/two"); open(THREE,"/home/perlmonk/public_html/shakespear/three"); chomp(my @one = <ONE>); chomp(my @two = <TWO>); chomp(my @three = <THREE>); print "<HTML>\n"; print "Thou "; my $one = $one[rand @one]; print $one; print " "; my $two = $two[rand @two]; print $two; print " "; my $three = $three[rand @three]; print $three; print <<ENDFORM; <BR> <BR> <form action="http://www.takiweb.com/~perlmonk/shakespear/insult.cgi" +method="get" name="thingymabob"> <input type="hidden" name="mode" value="eval"> <input type="radio" name="rating" value="good" checked><b>Good</b><br> <input type="radio" name="rating" value="okay"><b>Okay</b><br> <input type="radio" name="rating" value="bad"><b>Bad</b><br> ENDFORM print "<input type=\"hidden\" name=\"one\" value=\"$one\">"; print "<input type=\"hidden\" name=\"two\" value=\"$two\">"; print "<input type=\"hidden\" name=\"three\" value=\"$three\">"; print <<FINALE; <input type="Submit" value="Rate it!" align="MIDDLE"> </form> FINALE print "</HTML>"; } if ($mode eq "gen") { open(ONE,"/home/perlmonk/public_html/shakespear/one"); open(TWO,"/home/perlmonk/public_html/shakespear/two"); open(THREE,"/home/perlmonk/public_html/shakespear/three"); chomp(my @one = <ONE>); chomp(my @two = <TWO>); chomp(my @three = <THREE>); print header; print <<EOT; <HTML> <BODY BGCOLOR=#000000 TEXT=#FF9900 LINK=#FF9900 VLINK=#FF9900> <CENTER><IMG SRC="shakespear.gif" ALT="Shakespear the talking head!">< +/CENTER> <CENTER><H3> EOT print "Thou "; my $one = $one[rand @one]; print $one; print " "; my $two = $two[rand @two]; print $two; print " "; my $three = $three[rand @three]; print $three; print "</H3>"; print "<BR>"; print "<BR>"; print "<H4>So was that,"; my $option; foreach $option("good","okay","bad") { print "<A HREF=\"insult.cgi?mode=eval&one=$one&two=$two&three=$three&r +ating=$option\">$option</A>"; print ","; } print "or are you paralyzed by its brilliance so much that you can't c +lick</H4>"; print <<END; </H4> </BODY> </HTML> END } if ($mode eq "eval") { my $one = param("one"); $one =~ s/\0//g; my $two = param("two"); $two =~ s/\0//g; my $three = param("three"); $three =~ s/\0//g; my $rating = param("rating"); if ($rating eq "good") { $/ = undef; open(ONE,"/home/perlmonk/public_html/shakespear/one"); my $checkone = <ONE>; if ($checkone =~ /$one\n/) { close(ONE); open(ONE,">>/home/perlmonk/public_html/shakespear/one"); print ONE "$one\n"; } open(TWO,"/home/perlmonk/public_html/shakespear/two"); my $checktwo = <TWO>; if ($checktwo =~ /$two\n/) { close(TWO); open(TWO,">>/home/perlmonk/public_html/shakespear/two"); print TWO "$two\n"; } open(THREE,"/home/perlmonk/public_html/shakespear/three"); my $checkthree = <THREE>; if ($checkthree =~ /$three\n/) { close(THREE); open(THREE,">>/home/perlmonk/public_html/shakespear/three"); print THREE "$three\n"; } } if ($rating eq "bad") { $/ = undef; open(ONE,"/home/perlmonk/public_html/shakespear/one"); open(TWO,"/home/perlmonk/public_html/shakespear/two"); open(THREE,"/home/perlmonk/public_html/shakespear/three"); my $listone = <ONE>; my $listtwo = <TWO>; my $listthree = <THREE>; close ONE; $listone =~ s/$one\n//; open (ONE,">/home/perlmonk/public_html/shakespear/one"); print ONE "$listone"; close TWO; $listtwo =~ s/$two\n//; open (TWO,">/home/perlmonk/public_html/shakespear/two"); print TWO "$listtwo"; close THREE; $listthree =~ s/$three\n//; open (THREE,">/home/perlmonk/public_html/shakespear/three"); print THREE "$listthree"; } print header; print"<HTML>\n<BODY BGCOLOR=#000000 TEXT=#FF9900 LINK=#FF9900 VLINK=#F +F9900>"; print "<H3>So that was $rating, eh?"; print '<A HREF="insult.cgi?mode=gen">rate another</A> </BODY></HTML>'; print "</H3>\n</BODY>\n</HTML>"; }


"Sanity is the playground of the unimaginative" -Unknown

Edit Petruchio Tue Dec 25 17:05:08 UTC 2001 - Added READMORE tag, changed links to square-bracket notation.


In reply to Breeding Shakesperian Insults by beretboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.