From: "Kurt M. Dresner" Date: 2003-09-17T03:07:08+09:00 Subject: Re: scrambler one-liner This is hilarious, because a friend and I just had (over lunch) a race to see who could code it up first. I used Ruby and he used Perl. Mine worked first, but then I reworked it a bit to make it neater. His was impossible to read, but I totally have to send him this one-liner. Man, sort_by{rand} is so awesome! I can't believe I didn't think of that! -Kurt On Tue, Sep 16, 2003 at 11:28:01PM +0900, Xavier Noria wrote: > I just came across this interesting article at Slashdot that explains that > according to some English university the order of letters in words are not > really relevant for reading as long as the first and the last are at the > right place. (It seems that do not hold in Spanish). > > There is a link to a Perl filter[*] that munges a given text that way and I > wanted to write a mock-up as a one-liner, but in Ruby this time. This is > what I have for now: > > -pe 'gsub!(/\w+/){|w|r=1..w.size-1;w[r]=w[r].split(//).sort_by{rand}.to_s;w}' > > The cool Array.sort_by { rand } trick is a shuffle I saw in Freenode#ruby-lang > last week, I would like very much to remember the nick of who showed it but I > can't remember. > > It seems one-liners are not at the heart of the Ruby community, but hey, > that's funny in the end. Can you shorten it? > > -- fxn > > [*] http://www.jwz.org/hacks/scrmable.pl > > >======= End of Original Message =======<