From: Lyndon Samson Date: 2005-10-18T08:16:10+09:00 Subject: Re: How to get non-unique elements from an array? ------=_Part_3515_23621305.1129590967768 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline user system total real index 1.344000 0.000000 1.344000 ( 1.437000) grep 3.875000 0.000000 3.875000 ( 4.266000) scan 2.703000 0.000000 2.703000 ( 3.188000) inject 1.625000 0.000000 1.625000 ( 1.812000) gsub 3.078000 0.000000 3.078000 ( 3.547000) bits 0.969000 0.000000 0.969000 ( 1.062000) include 1.250000 0.000000 1.250000 ( 1.469000) BMN =3D 50000 bm(5) do |bx| bx.report('index ') { BMN.times { a.select{|e| a.index(e) !=3Da.rindex(e)}.= uniq } } bx.report('grep ') { BMN.times { a.select{|e| a.grep(e).length > 1}.uniq } = } bx.report('scan ') { BMN.times { a.sort.join('').to_s.scan(/(\d+)\s(\1)+/).flatten.uniq } } bx.report('inject') { BMN.times { a.uniq.inject(a.dup) { |b,i|b.delete_at( b.index(i)) ; b } } } bx.report('gsub ') { BMN.times {a.to_s.gsub(/(.)(?!.*\1)/,'').split('').map{|i|i.to_i} } } bx.report('bits ') { BMN.times { bn =3D bn2 =3D 0 a.each {|el|(bn2 |=3D (1<