On Thu, Mar 18, 2010 at 9:29 PM, Urabe Shyouhei <shyouhei / ruby-lang.org>wrote:

> Roger Braun wrote:
> > How about this:
>
> You should really know about Enumerable#group_by.
>
> irb(main):001:0> [0,15,35,100,205,300].group_by {|i| i/100 }
> => {0=>[0, 15, 35], 1=>[100], 2=>[205], 3=>[300]}
>
>
>
Your results are correct only because of a happenstance of the data. Add 99
in there, it should group with 100, but it groups with the 0...100
congruence class

ruby-1.9.1-p378 >   [0,15,35,99,100,205,300].group_by {|i| i/100 }
 => {0=>[0, 15, 35, 99], 1=>[100], 2=>[205], 3=>[300]}

Because these groups are relative to each other, I think you must do
something like Roger or I did, where you iterate through the list and
compare it to the groups.