------art_3092_16783873.1202594673915
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Adam,

1) Here it is is with uniq,map and select
pullmonkey:~$ irb
irb(main):001:0> a  1,2,1,3,2,1,3,2]
[1, 2, 1, 3, 2, 1, 3, 2]
irb(main):002:0> a.uniq.map{|x| a.select{|y| y x}}
[[1, 1, 1], [2, 2, 2], [3, 3]]

2) And for a hash of element frequency using uniq,map and select
irb(main):004:0> a.uniq.map{|x| {x a.select{|y| y x}.size}}
[{1}, {2}, {3}]

Charlie


On Feb 9, 2008 2:49 PM, Christopher Dicely <cmdicely / gmail.com> wrote:

> On Feb 9, 2008 12:50 PM, Adam Akhtar <adamtemporary / gmail.com> wrote:
> > a few people have mentioned some pretty concise solutions involving
> > map/collect selete find_all etc
> >
> > can someone give me an example of such a solution using the above.
> >
> > thanks
> >
> >
> >
> > --
> > Posted via http://www.ruby-forum.com/.
>
> irb(main):067:0> def subpack(list)
> irb(main):068:1>   list.uniq.map { |item| [item] * list.find_all {
> |val| val item}.size }
> irb(main):069:1> end
> nil
> irb(main):070:0> subpack [1,2,3,1,2,2,4,3,2,1]
> [[1, 1, 1], [2, 2, 2, 2], [3, 3], [4]]
>
>

------art_3092_16783873.1202594673915--