Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Simple but thought-provoking programming tasks [OT]

by sfink (Deacon)
on Apr 16, 2007 at 23:48 UTC ( #610432=note: print w/ replies, xml ) Need Help??


in reply to Simple but thought-provoking programming tasks [OT]

Insult generation.

sub insult { my $r = rand(); if ($r < 0.3) { return "You are " . bad() . "."; } elsif ($r < 0.60) { return others() . " cannot believe how " . bad() . " you are."; } elsif ($r < 0.90) { return "If I had " . money() . " for every time you " . didsomethi +ngstupid() . ", I would be rich."; } else { return insult() . " " . insult(); } }
etc. There are a ton of ways of doing it, some more flexible than others, so you could probably explore a whole series of successive "improvements". The language you use doesn't matter all that much either. (Especially if you print everything out immediately instead of returning it.)


Comment on Re: Simple but thought-provoking programming tasks [OT]
Download Code
Re^2: Simple but thought-provoking programming tasks [OT]
by Moron (Curate) on Apr 17, 2007 at 10:16 UTC
    The missing subroutines all seem to want to pick random words from a dictionary file, as per Ode to a random number. The improvement I haven't yet figured out (without a lot of manual typing in) is to have a modified dictionary file with a part of speech field alongside the word. i.e. in your example you want your insult to call somone an adjective noun or an adverb adjective noun and the filtering should be data-driven rather than by using different subroutines.
    __________________________________________________________________________________

    ^M Free your mind!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://610432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-21 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls