Very nice! Esa
-----Original Message----- From: Programming [mailto:[email protected]] On Behalf Of Raul Miller Sent: Friday, October 20, 2017 12:24 AM To: Programming forum <[email protected]> Subject: Re: [Jprogramming] Partitions Here's a faster way of computing bell numbers: Bell=: {:@(+/\@(,~{:)@]^:[ 1:) Bell 8 21147 timespacex 'Bell 8' 6e_6 2048 Thanks, -- Raul On Thu, Oct 19, 2017 at 5:11 PM, Lippu Esa <[email protected]> wrote: > I used par2 to generate bell numbers ( > https://en.wikipedia.org/wiki/Bell_number ) from 1 up : > > bell=.+/@(>:@i.#@par2"0]) > > bell"0 >:i.7 > 1 2 5 15 52 203 877 > > but it becomes slow very quickly > > ts 'bell 8' > 17.82442772 2509478016 > > But of course there are formulas for that. > > Esa > -----Original Message----- > From: Lippu Esa > Sent: Thursday, October 19, 2017 11:45 PM > To: [email protected] > Subject: RE: [Jprogramming] Partitions > > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
