Mike,

I wasn't very thorough in my definition of the original problem. I thought
that the example I gave was enough to clarify the requirements, but looking
back, more definition would have been good.

The original problem I posted was to develop a dyadic verb that would take
y objects and show all the ways that those y objects could be partitioned
into x groups. Each partition set must include all objects exactly once.
Duplication of objects is not allowed. The order of the objects in each
partition is not important.

Erling got the right idea in his previous post:

  par=: 4 : '(1,.2</\"1(i.x)#/~(y=+/"1 o)#o=.((x$v)#:i.v^x){1+i.v=.1+
y-x)<;.1[1+i.y'

   2 par 3
┌───┬───┐
│1  │2 3│
├───┼───┤
│1 2│3  │
└───┴───┘
   2 par 4
┌─────┬─────┐
│1    │2 3 4│
├─────┼─────┤
│1 2  │3 4  │
├─────┼─────┤
│1 2 3│4    │
└─────┴─────┘
   2 par 5
┌───────┬───────┐
│1      │2 3 4 5│
├───────┼───────┤
│1 2    │3 4 5  │
├───────┼───────┤
│1 2 3  │4 5    │
├───────┼───────┤
│1 2 3 4│5      │
└───────┴───────┘
   3 par 4
┌───┬───┬───┐
│1  │2  │3 4│
├───┼───┼───┤
│1  │2 3│4  │
├───┼───┼───┤
│1 2│3  │4  │
└───┴───┴───┘
   3 par 5
┌─────┬─────┬─────┐
│1    │2    │3 4 5│
├─────┼─────┼─────┤
│1    │2 3  │4 5  │
├─────┼─────┼─────┤
│1    │2 3 4│5    │
├─────┼─────┼─────┤
│1 2  │3    │4 5  │
├─────┼─────┼─────┤
│1 2  │3 4  │5    │
├─────┼─────┼─────┤
│1 2 3│4    │5    │
└─────┴─────┴─────┘
   3 par 6
┌───────┬───────┬───────┐
│1      │2      │3 4 5 6│
├───────┼───────┼───────┤
│1      │2 3    │4 5 6  │
├───────┼───────┼───────┤
│1      │2 3 4  │5 6    │
├───────┼───────┼───────┤
│1      │2 3 4 5│6      │
├───────┼───────┼───────┤
│1 2    │3      │4 5 6  │
├───────┼───────┼───────┤
│1 2    │3 4    │5 6    │
├───────┼───────┼───────┤
│1 2    │3 4 5  │6      │
├───────┼───────┼───────┤
│1 2 3  │4      │5 6    │
├───────┼───────┼───────┤
│1 2 3  │4 5    │6      │
├───────┼───────┼───────┤
│1 2 3 4│5      │6      │
└───────┴───────┴───────┘

Skip Cave
Cave Consulting LLC

On Thu, Oct 19, 2017 at 5:47 PM, 'Mike Day' via Programming <
[email protected]> wrote:

> Skip,  in your actual Quora Problem,  why not include other triads,
> such as 1 1 24,  2 3 4 etc;   or, otherwise,  why include both 2 4 3 and 4
> 2 3 ?
>
> Anyway,  this is (quite) short and brutish but not too nasty to solve your
> Quora problem for quite small numbers and numbers of factors:
>
>    |: 24 ([ ( (= */"1)#])  [:>:[#.inv i.@^ ) 3  NB. transpose gratuitous!
>  1  1 1 1 1 1  1  1  2 2 2 2 2  2 3 3 3 3 4 4 4 4 6 6 6 8 8 12 12 24
>  1  2 3 4 6 8 12 24  1 2 3 4 6 12 1 2 4 8 1 2 3 6 1 2 4 1 3  1  2 1
> 24 12 8 6 4 3  2  1 12 6 4 3 2  1 8 4 2 1 6 3 2 1 4 2 1 3 1  2  1 1
>
> It builds triads 1 1 1 , 1 1 2 ,...1 1 24, ... up to 24 24 24, and keeps
>
> just those whose product is 24.
>
>
> No points for space or time, filtering 30 out of 13824 candidates, but it's
>
> quite straightforward,  and it does yield all 30 permutations,  which some
>
> of the Quora corresondents appear to consider the requirement.
>
>
> NB - it's not clear to me what the problem actually is - is 30 the required
>
> answer (number of permutations of 3 suitable factors),  or 6 (number of
>
> combinations of same)?
>
>
> Mike
>
>
>
> ​​
>>
>>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to