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

Reply via email to