Re: Semcarlbd letrtes sepur! (Scrambled letters super!)

Kripa Sundar <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
Bart writes:

=> Especially the idea of using the /\B/ anchor appeals to me.
=>  Hmm... let's try it:
=> 
=> : perl -pe 'sub r{join"",map chop,sort map{rand.$_}shift=~/(.)/g};s/\B(\w+)\B/r$1/eg' 

Thanks to Etienne for the "map chop,sort map".  That was
neat.  At long last, we are having some FWP on this list.  :-)

Bart's "\B" is great, too.

Now we can inline &r, and save some chars.

  || perl -pe 's/\B(\w+)\B/join"",map chop,sort map{rand().$_}split"",$1/eg'

I have brought back Etienne's parens for rand(), to avoid
the warning.  I've also replaced the /(.)/g in &r with a
split().  It is just as long, and is aesthetically pleasing
(to me), because I don't have a m// in the RHS of an s///.


The only trouble with "map chop,sort map" is that it doesn't
*guarantee* that the new string is different from the old.

The following does guarantee re-ordering., but it is much
less elegant.  It is just two chars more than Bart's
solution, but it is 14 chars longer than inlining &r unchanged
(as above).

  || perl -pe 's/\B(\w*)(\w)(\w)\B/$3.$2.join"",map chop,sort map{rand().$_}split"",$1/eg'

peace,                          || Rescuing good ideas: Micro venture capital:
--{kr.pA}                       || http://tinyurl.com/gjpd
-- 
"I promise you I will listen to what has been said here, even though \
    I wasn't here." -- George W. Bush [http://slate.msn.com/?id=76886]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.