From: Robert Klemme Date: 2012-11-30T02:37:28+09:00 Subject: Re: Getting the smallest Items of an Array On Thu, Nov 29, 2012 at 4:42 PM, Regis d'Aubarede 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/