From: tamouse mailing lists Date: 2013-02-25T01:48:51+09:00 Subject: Re: How should I print only the last combination when using Array#combination(n) ? --f46d04426edad0033104d67b32e6 Content-Type: text/plain; charset=UTF-8 On Feb 24, 2013 10:21 AM, "Love U Ruby" wrote: > > see the below code : > > >> a = [1,2,3,4,5] > => [1, 2, 3, 4, 5] > >> a.combination(3){|arr| p arr} > [1, 2, 3] > [1, 2, 4] > [1, 2, 5] > [1, 3, 4] > [1, 3, 5] > [1, 4, 5] > [2, 3, 4] > [2, 3, 5] > [2, 4, 5] > [3, 4, 5] > => [1, 2, 3, 4, 5] > > Here,say I want to see the output only(without any fancy I write it > here,just to get to see the trick): > > [1, 3, 5] #~~ means 5th combination > [2, 3, 5] #~~ means 8th combination > > But yes only with block. Hope it is now clear to you @tamouse. My last > reply went to you by mistake without the output being written by me. I > tried to edit,but it passed then 15 mins,thus couldn't. > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > Is thissupposed to be a general algorithm, say out of any combination, you will want the n-th combination? Or is there some scheme you have in mind to choose which combinations you are seeking? Why does it have to be passed to a block from combination? Generally, what is the problem you are trying to solve with this? --f46d04426edad0033104d67b32e6 Content-Type: text/html; charset=UTF-8


On Feb 24, 2013 10:21 AM, "Love U Ruby" <lists@ruby-forum.com> wrote:
>
> see the below code :
>
> >> a = [1,2,3,4,5]
> => [1, 2, 3, 4, 5]
> >> a.combination(3){|arr| p arr}
> [1, 2, 3]
> [1, 2, 4]
> [1, 2, 5]
> [1, 3, 4]
> [1, 3, 5]
> [1, 4, 5]
> [2, 3, 4]
> [2, 3, 5]
> [2, 4, 5]
> [3, 4, 5]
> => [1, 2, 3, 4, 5]
>
> Here,say I want to see the output only(without any fancy I write it
> here,just to get to see the trick):
>
> [1, 3, 5] #~~ means 5th combination
> [2, 3, 5] #~~ means 8th combination
>
> But yes only with block. Hope it is now clear to you @tamouse. My last
> reply went to you by mistake without the output being written by me. I
> tried to edit,but it passed then 15 mins,thus couldn't.
>
> Thanks
>
> --
> Posted via http://www.ruby-forum.com/.
>

Is thissupposed to be a general algorithm, say out of any combination, you will want the n-th combination? Or is there some scheme you have in mind to choose which combinations you are seeking?

Why does it have to be passed to a block from combination?

Generally, what is the problem you are trying to solve with this?

--f46d04426edad0033104d67b32e6--