[Jprogramming] All subset keys
Mike Day
mike_liz.day at tiscali.co.uk
Fri Jan 27 21:47:18 HKT 2006
This is a tacit version and I'm adding the missing linefeed
to my earlier msg.
allsskeys =: ~.@((i.~ ~.)"1@((#: i.@(*/))@(>:@i.)))
The following variant omits the 1st ~. in not reducing terms
to lowest possible key, eg the term 0 0 0 3 is not reduced to
0 0 0 1, with some time saving:
allsskeys1 =: ~.@((i.~)"1@((#: i.@(*/))@(>:@i.)))
ts'allsskeys 8'
0.086195 4.71981e6
ts'allsskeys1 8'
0.0199724 4.71981e6
NB. no change to the list of subsets
key =: (allsskeys1 </."1 i.)
key1 =: (allsskeys1 </."1 i.)
(key -: key1) 8
1
|: key 3
+-----+---+---+---+-+
|0 1 2|0 1|0 2|0 |0|
+-----+---+---+---+-+
| |2 |1 |1 2|1|
+-----+---+---+---+-+
| | | | |2|
+-----+---+---+---+-+
Mike
Mike Day wrote:
> This generates the key array/s:
> allsskeys =: 13 : '~.(i.~~.)"1 r#: i.*/ r =. >:i.y.'
>
> I don't see the point of (say) allsskeys 3 for sets
> of size 4 but here goes:
> NB. |: only to save display lines here ....
> |:each allsskeys each 1 2 3 4
> +-+---+---------+-----------------------------+
> |0|0 0|0 0 0 0 0|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0|
> | |0 1|0 0 1 1 1|0 0 0 0 0 1 1 1 1 1 1 1 1 1 1|
> | | |0 1 0 1 2|0 0 1 1 1 0 0 0 1 1 1 2 2 2 2|
> | | | |0 1 0 1 2 0 1 2 0 1 2 0 1 2 3|
> +-+---+---------+-----------------------------+
> |:(allsskeys 4)</. "1 'abcd'
> +----+---+---+--+--+---+--+--+--+---+--+--+--+--+-+
> |abcd|abc|abd|ab|ab|acd|ac|ac|ad|a |a |ad|a |a |a|
> +----+---+---+--+--+---+--+--+--+---+--+--+--+--+-+
> | |d |c |cd|c |b |bd|b |bc|bcd|bc|b |bd|b |b|
> +----+---+---+--+--+---+--+--+--+---+--+--+--+--+-+
> | | | | |d | | |d | | |d |c |c |cd|c|
> +----+---+---+--+--+---+--+--+--+---+--+--+--+--+-+
> | | | | | | | | | | | | | | |d|
> +----+---+---+--+--+---+--+--+--+---+--+--+--+--+-+
>
> I think there's a more efficient way, avoiding the
> redundancy removed by the ~. but this gets the ball
> rolling!
>
> Mike
>
>
> Oleg Kobchenko wrote:
>
>> Here is another puzzle (Not sure if the chosen
>> name is appropriate).
>>
>> For a given set magnitude N find list of all subset keys:
>>
>> <@allss"0 i.5
>> ++-+---+-----+-------+
>> ||0|0 0|0 0 0|0 0 0 0|
>> || |0 1|0 0 1|0 0 0 1|
>> || | |0 1 0|0 0 1 0|
>> || | |0 1 1|0 0 1 1|
>> || | |0 1 2|0 0 1 2|
>> || | | |0 1 0 0|
>> || | | |0 1 0 1|
>> || | | |0 1 0 2|
>> || | | |0 1 1 0|
>> || | | |0 1 1 1|
>> || | | |0 1 1 2|
>> || | | |0 1 2 0|
>> || | | |0 1 2 1|
>> || | | |0 1 2 2|
>> || | | |0 1 2 3|
>> ++-+---+-----+-------+
>>
>> 'abcd' ;:^:_1@(</.)"1~ allss 4
>> abcd abc d abd c ab cd ab c d acd b ac bd ac b d ad bc a bcd
>> a bc d ad b c a bd c a b cd a b c d
>>
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
More information about the Programming
mailing list