From: Robert Dober Date: 2008-09-05T17:01:43+09:00 Subject: Re: Need a 40 LOC (ignoring comments) to be shorter -- suggestions wanted On Fri, Sep 5, 2008 at 9:29 AM, Lars Christensen wrote: > On Sep 5, 7:34 am, "Eric I." wrote: >> On Sep 4, 9:40 pm, RichardOnRails >> > Any ideas/suggestions? >> >> Here's one solution that requires the 'permutation' gem: > > Ruby 1.8.7 and 1.9 has Array#permutation: > > (3..7).to_a.permutation.sort_by { |a| a[0..2].to_s.to_i * > a[3..4].to_s.to_i }.first > > Golf anyone? :-) (i) A trivial trick is to replace (3..7).to_a with [*3..7] (ii) sort_by( &blk ).first can be replaced with min_by( &blk ) R -- C'est véritablement utile puisque c'est joli. Antoine de Saint Exupéry