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
how about you?
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
how about you?
On Fri, Nov 13, 2009 at 3:31 PM, Haoqi H. [email protected] wrote:
hello,happy weekday!
in ruby1.9:
irb:>
%w{ruby c java php}.permutation.to_aand 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…
how about you?
Posted via http://www.ruby-forum.com/.
–
Paul S.
http://www.nomadicfun.co.uk
On Fri, Nov 13, 2009 at 3:43 PM, Paul S. [email protected]
wrote:
.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).
–
Paul S.
http://www.nomadicfun.co.uk
–
Paul S.
http://www.nomadicfun.co.uk
On Fri, Nov 13, 2009 at 3:48 PM, Paul S. [email protected]
wrote:
.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 S.
http://www.nomadicfun.co.uk
–
Paul S.
http://www.nomadicfun.co.uk
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs