This is how I untangled it.
f=:] I.~[:+/\ [ * [: # ]
<span style="font-size: 16px;">
</span>
<span style="font-size: 16px;">g=: 4 :'( x * y)</.y''
</span><div>0.35 0.3 0.3 g i.20
Sent from AOL Mobile Mail

Linda

-----Original Message-----
From: Roger Shepherd <[email protected]>
To: programming <[email protected]>
Sent: Thu, Oct 26, 2017 10:37 AM
Subject: Re: [Jprogramming] Partitions


In addition to the 12-fold way of Rota, there is the classification by a 
20-fold way due to Kenneth Bogart of Dartmouth.
When necessary, reference to a classification can help communicate when one 
problem is being specified and another is being solved for.
There are extreme conditions (empty this and excess that) where convenient, 
generally applicable solution formulas are at least a little bit wrong.
The following is from <a 
href="https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf";
 
target="_blank">https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf</a>
On page 76 is Table 3.2: The number of ways to distribute k objects to n 
recipients, with restrictions on how the objects are received
The Twenty-fold Way: A Table of Distribution Problems k objects and conditions 
n recipients and mathematical model for distribution on how they are received 

Ignore this if I am the only one confused by the properties of the various 
programs/solutions being offered here.

Sent from Mail for Windows 10

From: Erling Hellenäs
Sent: Thursday, October 26, 2017 8:57 AM
To: <a href="mailto:[email protected]";>[email protected]</a>
Subject: Re: [Jprogramming] Partitions

Hi all !

I didn't find any way to improve Esas solution.

I wanted to measure mine so I made it into a program. I improved it 
slightly.

parE =: 4 : 0
NB. All combinations of all items
v=.}.comb i.y
NB. Select combinations with less than or equal to 1+y-x items
v1=.((#&> v)<:1+y-x)#v
NB. All combinations in all buckets
v2=. > , ,&.>//>x#<<"0 v1
NB. Select combinations with one and only one of each number
v3=.(((i.y)-:[:/:~[:;]) "1 v2) # v2
NB. The idea here is to normalize the representation so that
NB. the copies are adjacent.
NB. Sort buckets within each combination after first item in each bucket
v31=.(([: /: [: {.&.> ]){])"1 v3
NB. Sort buckets within each combination after number of items in each 
bucket
v4=.(([: /: [: #&.> ]){])"1 v31
NB. Remove duplicates, sort to show nicely
/:~ ~.v4
)


    ts'4 parE 6'
2.6112 7.66842e8


Cheers,

Erling Hellenäs


Den 2017-10-26 kl. 10:38, skrev Erling Hellenäs:
> Hi all !
>
> I analysed Esa Lippus solution. The printout is long, but here is the 
> code and my explanations.
>
> par2=: 4 : 0
> a=.(y#x) #: i. x^y
> sort ~.((x=#@~."1 a)#a) </."1 i.y
> )
> sort=: /:~
> 3 par2 5
> x=:3
> y=:5
> NB. All combinations of y elements
> [a=:(y#x) #: i. x^y
> NB. Select the combinations in which the y elements
> NB. are distributed over x buckets
> [v=: ((x=#@~."1 a)#a)
> NB. Pack the elements in each bucket combination.
> [w=:v </."1 i.y
> NB. Sort to display nicely
> sort ~. w
>
> Cheers,
>
> Erling Hellenäs
>
>
> Den 2017-10-26 kl. 07:07, skrev 'Skip Cave' via Programming:
>> Lippu,
>>
>> Yes, your par2 is MUCH faster than Raul's nparts. If I have some time, I
>> will put together a time/space test for all the proposed solutions.
>>
>> Skip
>>
>> Skip Cave
>> Cave Consulting LLC
>>
>> On Wed, Oct 25, 2017 at 1:58 PM, Lippu Esa <<a 
>> href="mailto:[email protected]";>[email protected]</a>> wrote:
>>
>>> Hello,
>>>
>>> I get the following with the partition verb I posted last Thursday 
>>> (J8.06
>>> and 4 core 2.9GHz CPU and 16GB RAM):
>>>
>>> par2=: 4 : 0
>>> a=.(y#x) #: i. x^y
>>> sort ~.((x=#@~."1 a)#a) </."1 i.y
>>> )
>>>
>>>     ts '#5 par2 8'
>>> 4.15977615 151821824
>>>     ts '# 6 par2 8'
>>> 2.55073168 358252032
>>>
>>> Esa
>>>
>>> -----Original Message-----
>>> From: Programming [<a 
>>> href="mailto:[email protected]?";>mailto:[email protected]</a>]
>>>  On
>>> Behalf Of 'Skip Cave' via Programming
>>> Sent: Wednesday, October 25, 2017 8:12 PM
>>> To: <a href="mailto:[email protected]";>[email protected]</a>
>>> Subject: Re: [Jprogramming] Partitions
>>>
>>> Raul got it right with his nparts verb. In my original example of 
>>> par, I
>>> constructed the required output of par by hand. In that process, I
>>> overlooked the majority of the possible combinations of the ways that 5
>>> items could be separated into 3 containers. That caused confusion in 
>>> the
>>> various attempts to implement what I proposed. I wasn't very 
>>> thorough in
>>> vetting my example output, and Mike valiantly tried to point out the 
>>> flaws
>>> in my proposal. Raul showed how much I missed clearly in my par example
>>> when he demonstrated:
>>>
>>>     #3 nparts 5
>>> 25
>>>     #3 par 5
>>> 6
>>>
>>> Rob also pointed out the issue in his posts. Erling's v7 verb got to 
>>> the
>>> same result as Raul's nparts.
>>>
>>> The number of possible partitions of n objects grows rapidly with n:
>>>
>>>      #3 nparts 5
>>>
>>> 25
>>>
>>>      #3 nparts 6
>>>
>>> 90
>>>
>>>      #3 nparts 7
>>>
>>> 301
>>>
>>>      #3 nparts 8
>>>
>>> 966
>>>
>>>
>>>
>>> Increasing the number of partitions reduces the number of 
>>> combinations but
>>> significantly increases execution time with Raul's nparts :
>>>
>>>
>>>     #4 nparts 8
>>>
>>> 1701
>>>
>>>     #5 nparts 8
>>>
>>> 1050
>>>
>>>     #6 nparts 8
>>>
>>> 266
>>>
>>>
>>> The 5 #nparts 8  took over 30 seconds to run on my i7 laptop. The #6 
>>> nparts
>>> 8 took about 3 minutes.
>>>
>>>
>>> Is there a more computationally efficient way to calculate the 
>>> partitions?
>>>
>>>
>>> Skip
>>> ----------------------------------------------------------------------
>>> For information about J forums see <a 
>>> href="http://www.jsoftware.com/forums.htm"; 
>>> target="_blank">http://www.jsoftware.com/forums.htm</a>
>>> ----------------------------------------------------------------------
>>> For information about J forums see <a 
>>> href="http://www.jsoftware.com/forums.htm"; 
>>> target="_blank">http://www.jsoftware.com/forums.htm</a>
>>>
>> ----------------------------------------------------------------------
>> For information about J forums see <a 
>> href="http://www.jsoftware.com/forums.htm"; 
>> target="_blank">http://www.jsoftware.com/forums.htm</a>
>
> ----------------------------------------------------------------------
> For information about J forums see <a 
> href="http://www.jsoftware.com/forums.htm"; 
> target="_blank">http://www.jsoftware.com/forums.htm</a>

----------------------------------------------------------------------
For information about J forums see <a 
href="http://www.jsoftware.com/forums.htm"; 
target="_blank">http://www.jsoftware.com/forums.htm</a>

----------------------------------------------------------------------
For information about J forums see <a 
href="http://www.jsoftware.com/forums.htm"; 
target="_blank">http://www.jsoftware.com/forums.htm</a></div>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to