Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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.)

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2022-08-10 06:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found