Boost logo

Boost Users :

Subject: Re: [Boost-users] generate structs with all combinations of members from a given struct
From: Diederick C. Niehorster (dcnieho_at_[hidden])
Date: 2010-02-01 21:31:58


Potentially off-topic as I haven't followed this thread, but you can
get that sequence as well by taking the binary representation of 0
till 31. The order of the elements would be different, but if that
matters, you can simply flip the array from left to right, over the
column dimension.

MATLAB:
b=dec2bin([0:31].') =

00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
01010
01011
01100
01101
01110
01111
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11101
11110
11111

fliplr(b) =

00000
10000
01000
11000
00100
10100
01100
11100
00010
10010
01010
11010
00110
10110
01110
11110
00001
10001
01001
11001
00101
10101
01101
11101
00011
10011
01011
11011
00111
10111
01111
11111

Best,
Dee

On Tue, Feb 2, 2010 at 9:51 AM, Hicham Mouline <hicham_at_[hidden]> wrote:
>
> ----- Original Message ----- From: "Larry Evans" <cppljevans_at_[hidden]>
> To: <boost-users_at_[hidden]>
> Sent: Tuesday, February 02, 2010 2:35 AM
> Subject: Re: [Boost-users] generate structs with all combinations of members
> from a given struct
>
>
>> On 02/01/10 03:08, Hicham Mouline wrote:
>>>
>>>  ----- Original Message -----
>>>    *From:* Hicham Mouline <mailto:hicham_at_[hidden]>
>>>    *To:* boost-users_at_[hidden] <mailto:boost-users_at_[hidden]>
>>>    *Sent:* Monday, February 01, 2010 12:09 PM
>>>    *Subject:* Re: [Boost-users] generate structs with all combinations
>>>    of members from a given struct
>>>     My previous runtime solution was wrong.
>>> I just fixed it now.
>>
>> I had a hard time understanding how it worked.
>> A simpler solution would be to just generate the
>> characteristic functions for sets of a given size.
>> The characteristic function could then be used
>> to select elements from the set:
>>
>> http://en.wikipedia.org/wiki/Characteristic_function
>>
>> The structure of such a program is very similar to yours
>> in that it has a recursive call and a for loop.  However, with
>> this method, the for loop just has size 2.  The depth of
>> recursion is n, where n is size of the set.  I think your
>> method had recursion depth of n-1.
>>
>> The attached illustrates the method.
>> Output is:
>>
>> size=32
>>  0 0 0 0 0
>>  1 0 0 0 0
>>  0 1 0 0 0
>>  1 1 0 0 0
>>  0 0 1 0 0
>>  1 0 1 0 0
>>  0 1 1 0 0
>>  1 1 1 0 0
>>  0 0 0 1 0
>>  1 0 0 1 0
>>  0 1 0 1 0
>>  1 1 0 1 0
>>  0 0 1 1 0
>>  1 0 1 1 0
>>  0 1 1 1 0
>>  1 1 1 1 0
>>  0 0 0 0 1
>>  1 0 0 0 1
>>  0 1 0 0 1
>>  1 1 0 0 1
>>  0 0 1 0 1
>>  1 0 1 0 1
>>  0 1 1 0 1
>>  1 1 1 0 1
>>  0 0 0 1 1
>>  1 0 0 1 1
>>  0 1 0 1 1
>>  1 1 0 1 1
>>  0 0 1 1 1
>>  1 0 1 1 1
>>  0 1 1 1 1
>>  1 1 1 1 1
>>
>> -regards,
>> Larry
>
> Yes, all this just became clear to me last night in a dream:-)
>
> Thanks,
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net