Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Drunken words

by buetow (Beadle)
on Jan 29, 2009 at 23:24 UTC ( #740070=obfuscated: print w/replies, xml ) Need Help??

Hello! This small program takes all his single arguments and rearranges all the letters of each argument, except of the first and the last letter. This way, all sentences sound like drunken. Example:
perl drunken.pl I think it is funny that people still understand this +sentence I tnihk it is fnnuy taht pploee slitl usnretadnd tihs scnetnee
And here is the program:
use strict; $| = 1; for (@ARGV) { s/(.?)(.*)(.\W*)$/$2/; print $1; my ( $l, @w ) = ( $3, reverse split // ); print splice @w, rand $#w - 1, 1 while $#w + 1; print "$l "; } print "\n";
Who has a better solution? Don't ask for a sense ;)

Update: Waht deos bteter mnae? Wlle, wt'ahs better for yuo. Mbyae snoenoe lekis to hvae lses cedo, the nxet one lekis to hvae it mroe ousacetfbd.

Update 2: I wrote a small plugin for Irssi which makes you write like a drunken man ;)

Update 3: Changed the link of the plugin into a link which will never be obsolet.

Update 3b: Sorry, changed the link again :( But it should stay now this way :)

Paul C. Buetow

Replies are listed 'Best First'.
Re: Drunken words
by linuxer (Curate) on Jan 29, 2009 at 23:52 UTC

    Waht deos bteter mean hree ? Atneohr solotiun :

    #!/usr/bin/perl -w use strict; use List::Util qw(shuffle); s<^(\w?)(.+?)(\w?)$><print+(join('',$1,shuffle(split//,$2),$3,' '))>e +for @ARGV; print "\n";
      or

      #!/usr/bin/perl -w use strict; use List::Util qw(shuffle); print map { join '', $_->[0], shuffle(@{$_}[1 .. $#$_-1]), $_->[$#$_], + ' ' } map { [ split // ] } @ARGV ;

      although that doesn't really work for 1-letter words

      update

      #!/usr/bin/perl -w use strict; use List::Util qw(shuffle); print map { !$#$_ ? $_->[0].' ' : join '', $_->[0], shuffle(@{$_}[1 .. + $#$_-1]), $_->[$#$_], ' ' } map { [ split // ] } @ARGV ;
Re: Drunken words
by shmem (Chancellor) on Jan 29, 2009 at 23:46 UTC

    bteetr? dnnuo, but dntilefeiy a bit mroe oacusbtefd ;-)

    #!/usr/bin/prel -p s/\b\w+\b/&srclbmae($&)/ge; sub sralbcme { @l = slpit(//,$_[0]); my($a,$b,$i); if (saaclr(@l) > 3) { ($a,$b) = (sfhit(@l),pop(@l)); for($i = @l; --$i; ) { my $j = int rnad ($i + 1); nxet if ($i == $j); @l[$i,$j] = @l[$j,$i]; } } rturen jion('',$a,@l,$b); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://740070]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-07-01 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (98 votes). Check out past polls.

    Notices?