On Thu, Nov 29, 2012 at 4:42 PM, Regis d'Aubarede <[email protected]> wrote: >> def n_min(l,n) (1..n).map {a=l.min ; l=l-[a]; a } end >> >> array.sort[0, n] >> n_min array, n > > > You compar ruby implementation for n_min() with c implementation for > sort...
Is that forbidden? You are making use of C implementation as well. With that argumentation of yours you would also need to reimplement methods you use inside n_min in Ruby (notably l.min and l-[a]). Fact remains that your algorithm will visit most of the elements of a 2*n times. I find that inelegant but YMMV of course. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
