From: "pauldacus@..." Date: 2005-10-19T08:36:58+09:00 Subject: Re: How to get non-unique elements from an array? For those still the slightest bit interested... I found two slightly faster approaches. I stood on the shoulders of giants.... :-) paul2: one={};two={};a.each{|i| one[i] ? two[i]=1 : one[i]=1;two.keys paul2a: one={};two={};a.each{|i| (one[i] && two[i]=1) || one[i]=1;two.keys These two scripts are exactly the same concept, the second just uses && and || shortcut evaluation... which proved infintesimally faster.... actually scored a 'zero' on the large array. user system total real david 35.150000 0.000000 35.150000 ( 35.150000) jeff 9.720000 0.000000 9.720000 ( 9.720000) jegII 9.830000 0.000000 9.830000 ( 9.830000) markvh 8.130000 0.000000 8.130000 ( 8.130000) martin 8.680000 0.000000 8.680000 ( 8.680000) paolo 18.350000 0.000000 18.350000 ( 18.350000) park 11.310000 0.000000 11.310000 ( 11.310000) paul 19.390000 0.000000 19.390000 ( 19.390000) robert 22.570000 0.000000 22.570000 ( 22.570000) samk1 12.740000 0.000000 12.740000 ( 12.740000) samk2 29.000000 0.000000 29.000000 ( 29.000000) simonk 8.190000 0.000000 8.190000 ( 8.190000) simons 13.670000 0.000000 13.670000 ( 13.670000) zach 1.540000 0.000000 1.540000 ( 1.540000) paul2 1.760000 0.000000 1.760000 ( 1.760000) paul2a 1.760000 0.000000 1.760000 ( 1.760000) user system total real david 206.850000 0.000000 206.850000 (206.850000) jeff 0.770000 0.000000 0.770000 ( 0.770000) jegII 0.110000 0.000000 0.110000 ( 0.110000) markvh 10.820000 0.000000 10.820000 ( 10.820000) martin 0.050000 0.000000 0.050000 ( 0.050000) paolo 0.170000 0.000000 0.170000 ( 0.170000) park 0.110000 0.000000 0.110000 ( 0.110000) paul 0.220000 0.000000 0.220000 ( 0.220000) robert 0.220000 0.000000 0.220000 ( 0.220000) samk1 0.110000 0.000000 0.110000 ( 0.110000) samk2 79.210000 0.000000 79.210000 ( 79.210000) simonk 22.850000 0.000000 22.850000 ( 22.850000) simons 11.370000 0.000000 11.370000 ( 11.370000) zach 11.750000 0.000000 11.750000 ( 11.750000) paul2 0.050000 0.000000 0.050000 ( 0.050000) paul2a 0.000000 0.000000 0.000000 ( 0.000000) A combined score shows them to be prettty good, shortcut evaluation winning by a nose: 1.76 paul2a 1.81 paul2 8.73 martin 9.94 jegII 10.49 jeff 11.42 park 12.85 samk1 13.29 zach 18.52 paolo 18.95 markvh 19.61 paul 22.79 robert 25.04 simons 31.04 simonk 108.21 samk2 242.00 david