Cool.

If we relax the requirement that the order of the items is preserved we get 
more solutions (my clumsy solution):

par2=: 4 : 0
a=.(y#x) #: i. x^y
sort ~.((x=#@~."1 a)#a) </."1 i.y
)
3 par2 5
┌─────┬─────┬─────┐
│0    │1    │2 3 4│
├─────┼─────┼─────┤
│0    │1 2  │3 4  │
├─────┼─────┼─────┤
│0    │1 2 3│4    │
├─────┼─────┼─────┤
│0    │1 2 4│3    │
├─────┼─────┼─────┤
│0    │1 3  │2 4  │
├─────┼─────┼─────┤
│0    │1 3 4│2    │
├─────┼─────┼─────┤
│0    │1 4  │2 3  │
├─────┼─────┼─────┤
│0 1  │2    │3 4  │
├─────┼─────┼─────┤
│0 1  │2 3  │4    │
├─────┼─────┼─────┤
│0 1  │2 4  │3    │
├─────┼─────┼─────┤
│0 1 2│3    │4    │
├─────┼─────┼─────┤
│0 1 3│2    │4    │
├─────┼─────┼─────┤
│0 1 4│2    │3    │
├─────┼─────┼─────┤
│0 2  │1    │3 4  │
├─────┼─────┼─────┤
│0 2  │1 3  │4    │
├─────┼─────┼─────┤
│0 2  │1 4  │3    │
├─────┼─────┼─────┤
│0 2 3│1    │4    │
├─────┼─────┼─────┤
│0 2 4│1    │3    │
├─────┼─────┼─────┤
│0 3  │1    │2 4  │
├─────┼─────┼─────┤
│0 3  │1 2  │4    │
├─────┼─────┼─────┤
│0 3  │1 4  │2    │
├─────┼─────┼─────┤
│0 3 4│1    │2    │
├─────┼─────┼─────┤
│0 4  │1    │2 3  │
├─────┼─────┼─────┤
│0 4  │1 2  │3    │
├─────┼─────┼─────┤
│0 4  │1 3  │2    │
└─────┴─────┴─────┘

I don't have a nice tacit verb for this yet.

Esa
-----Original Message-----
From: Programming [mailto:[email protected]] On Behalf 
Of Henry Rich
Sent: Thursday, October 19, 2017 5:20 PM
To: [email protected]
Subject: Re: [Jprogramming] Partitions

par =: 2 (}. i.)&.>/\"1 0: ,. (comb&.<:) ,. ]


Henry Rich



On 10/19/2017 9:53 AM, 'Skip Cave' via Programming wrote:
> Design a dyadic function 'par' that will partition y items into x
> partitions. For example:
>
> 3 par 5
>
> ┌─────┬─────┬─────┐
>
> │0    │1    │2 3 4│
>
> ├─────┼─────┼─────┤
>
> │0    │1 2  │3 4  │
>
> ├─────┼─────┼─────┤
>
> │0    │1 2 3│4    │
>
> ├─────┼─────┼─────┤
>
> │0 1  │2    │3 4  │
>
> ├─────┼─────┼─────┤
>
> │0 1  │2 3  │4    │
>
> ├─────┼─────┼─────┤
>
> │0 1 2│3    │4    │
>
> └─────┴─────┴─────┘
>
>
>
> Skip Cave
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



---
This email has been checked for viruses by AVG.
http://www.avg.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

Reply via email to