Standing on Roger's shoulders I can see so much further! f=: (|. each) @: (/: #each) @: (#:@i.@(2^#) <@#"1 ]) @|. f 1 6 6 8 ┌┬─┬─┬─┬─┬───┬───┬───┬───┬───┬───┬─────┬─────┬─────┬─────┬───────┐ ││1│6│6│8│1 6│1 6│6 6│1 8│6 8│6 8│1 6 6│1 6 8│1 6 8│6 6 8│1 6 6 8│ └┴─┴─┴─┴─┴───┴───┴───┴───┴───┴───┴─────┴─────┴─────┴─────┴───────┘
Cheers, bob > On May 7, 2016, at 10:18 PM, Skip Cave <[email protected]> wrote: > > Roger, > > Nice! However, I realized that I didn't specify my problem in quite > enough detail. I need to keep duplicated integers in the final > sub-sets: > > s =. 1 6 6 8 > f s > > ┌─┬─┬─┬─┬───┬───┬───┬───┬───┬───┬─────┬─────┬─────┬─────┬───────┐ > > │1│6│6│8│1 6│1 6│1 8│6 6│6 8│6 8│1 6 6│1 6 8│1 6 8│6 6 8│1 6 6 8│ > > └─┴─┴─┴─┴───┴───┴───┴───┴───┴───┴─────┴─────┴─────┴─────┴───────┘ > Skip Cave > Cave Consulting LLC > > > On Sun, May 8, 2016 at 12:05 AM, Roger Hui <[email protected]> wrote: >> subsets=: (#:@i.@(2^#) <@#"1 ]) @ ~. >> subsets 1 3 6 8 >> ┌┬─┬─┬───┬─┬───┬───┬─────┬─┬───┬───┬─────┬───┬─────┬─────┬───────┐ >> ││8│6│6 8│3│3 8│3 6│3 6 8│1│1 8│1 6│1 6 8│1 3│1 3 8│1 3 6│1 3 6 8│ >> └┴─┴─┴───┴─┴───┴───┴─────┴─┴───┴───┴─────┴───┴─────┴─────┴───────┘ >> subsets 1 3 6 8 8 1 >> ┌┬─┬─┬───┬─┬───┬───┬─────┬─┬───┬───┬─────┬───┬─────┬─────┬───────┐ >> ││8│6│6 8│3│3 8│3 6│3 6 8│1│1 8│1 6│1 6 8│1 3│1 3 8│1 3 6│1 3 6 8│ >> └┴─┴─┴───┴─┴───┴───┴─────┴─┴───┴───┴─────┴───┴─────┴─────┴───────┘ >> >> >> >> >> On Sat, May 7, 2016 at 9:59 PM, Skip Cave <[email protected]> wrote: >> >>> Given a set of N random integers, create a function that will generate >>> all the possible sub-sets of numbers that can be derived from that >>> set. >>> >>> For example: >>> >>> s =. 1 3 6 8 >>> f s >>> >>> ┌─┬─┬─┬─┬───┬───┬───┬───┬───┬───┬─────┬─────┬─────┬─────┬───────┐ >>> >>> │1│3│6│8│1 3│1 6│1 8│3 6│3 8│6 8│1 3 6│1 3 8│1 6 8│3 6 8│1 3 6 8│ >>> >>> └─┴─┴─┴─┴───┴───┴───┴───┴───┴───┴─────┴─────┴─────┴─────┴───────┘ >>> >>> Define f >>> >>> Skip >>> >>> Skip Cave >>> Cave Consulting LLC >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
