in reply to Fun with words (Golf?)

75

s[\B([^\s]*)\B(?=\w)][join'',sort{.5>rand}split'',$1]ge,print while<DA +TA>;

72

s[\B(\S*)\B(?=\w)][join'',sort{.5>rand}split'',$1]ge,print while<DATA> +;

66

s[\B(\w+)\B][join'',sort{.5>rand}split'',$1]ge,print while<DATA>;
P:\test>junk Down taht path leis madenss. On the ohter hnad, the road to hlel is pe +avd with mnilteg slwalbnos. Augltohh the Prel Sloagn is Tehre's More Than One Way to Do It, I htsi +etae to mkae 10 wyas to do setmonihg. And don't tlel me there isn't one bit of drecfefine between null and s +pace, bsauece taht's etcaxly how much dreneciffe there is. Rdnaal siad it wluod be tguoh to do in sed. He didn't say he didn't ud +nerasntd sed. Rnaadl udnertsands sed qtuie well. Wchih is why he uess + Perl. As usual, I'm oitasrvetng the case to kcnok a few nnrueos loose, but t +he truth is ullasuy sreeomwhe in the mudlde, uh, mlddie. Of crouse, I rseerve the right to mkae wohlly siuptd changes to Prel i +f I tnhik they ivrompe the lgnuagae.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Fun with words (Golf?)
by Roy Johnson (Monsignor) on Nov 09, 2005 at 21:07 UTC
    ++ for realizing that a fair shuffle isn't necessary. You can trim a few chars by getting rid of the rand call entirely, and using non-paired delimiters, $&, and an alternative to split:
    s!\B\w+\B!join'',sort{1}$&=~/./g!eg

    Caution: Contents may have been coded under pressure.

      Come to that, why bother with the comparison block at all :)

      s!\B\w+\B!join'',sort$&=~/./g!eg P:\test>junk Down taht path leis madenss. On the oehtr hand, the raod to hell is pa +evd with meilntg sabllnows. Aghlotuh the Perl Saglon is Tehre's More Tahn One Way to Do It, I haei +stte to make 10 ways to do sehimnotg. And don't tell me tehre isn't one bit of dceeffinre beeetwn nlul and s +acpe, bacesue taht's eacltxy how mcuh dceeffinre tehre is. Raadnl said it wloud be tgouh to do in sed. He ddin't say he ddin't ua +dennrstd sed. Raadnl uaddennrsts sed qitue well. Wchih is why he uess + Perl. As uasul, I'm oaeinrsttvg the case to kcnok a few nenorus loose, but t +he trtuh is uallsuy seehmorwe in the mddlue, uh, mddile. Of corsue, I reersve the rghit to make whlloy siptud caeghns to Perl i +f I think tehy imoprve the laaggnue.

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: Fun with words (Golf?)
by blazar (Canon) on Nov 10, 2005 at 12:15 UTC
    66
    s[\B(\w+)\B][join'',sort{.5>rand}split'',$1]ge,print while<DATA>;
    Some common golfing micro-"optimizations":
    s|\B\w+\B|join'',sort{.5>rand}$&=~/./g|ge,print for<DATA>