From: Paul Smith Date: 2009-11-14T00:50:57+09:00 Subject: Re: just for fun: oneline code for 4 language permutation On Fri, Nov 13, 2009 at 3:48 PM, Paul Smith wrote: > On Fri, Nov 13, 2009 at 3:43 PM, Paul Smith wrote: >> On Fri, Nov 13, 2009 at 3:31 PM, Haoqi Haoqi wrote: >>> hello,happy weekday! >>> in ruby1.9: >>> irb:> >>> %w{ruby c java php}.permutation.to_a >>> >>> and my code is(all ruby): >>> irb:> >>> (1..1000).inject([]){|p,_|p<<%w{ruby c java php}.sort_by{rand}}.uniq >> >> .shuffle! is shorter than .sort_by{rand} by 5 characters. >> >> I hate that your method is nondeterministic, but I've got it spinning >> in a while loop and having broken it yet... > > And it just did. > > FWIW, your method only gives the correct result with probablity 1 - > ((23/24)^999) so it should fail once every 2.9 trillion runs > (3x10^18). Actually 1 - ((23/24)^977) is a better lower bound. I'll shut up now. > >> -- >> Paul Smith >> http://www.nomadicfun.co.uk >> >> paul@pollyandpaul.co.uk >> > > > > -- > Paul Smith > http://www.nomadicfun.co.uk > > paul@pollyandpaul.co.uk > > -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk