From: "蕭 文仁" Date: 2010-03-19T18:08:51+09:00 Subject: Re: Grouping elements of an array --_67cc553d-2549-4a9b-b42f-3c2a8b295f99_ Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: 8bit Hello, I am new to Ruby. Below is my solution: a=[0, 15, 35, 100, 205, 215, 300] b=[] c=[] d=a[0] a.each do |i| if i - d < 30 c << i else b << c c=[i] end d =i end if c.size > 0 b << c end p b --_67cc553d-2549-4a9b-b42f-3c2a8b295f99_--