Funny you mention perm.
I was thinking on permutations the other day and found a (not (yet)
optimised) solution which is more efficient.
prm=: 3 : '>([:,/ [,."0 _1 ]+"_ _1 <:"0 _)&.>/<@i."0 |.>:i.y'
ts'prm 8'
0.0154299 10499456
ts'perm 8'
0.035711181 9046912
ts'prm 10'
3.3036164 1.1073105e9
ts'perm 10'
4.3941163 1.1156879e9
(prm -: perm)8
1
(prm -: perm)10
1
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] Namens Brian Schott
> Verzonden: woensdag 13 augustus 2008 15:47
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] Choosing k items out of n and Equal
> sizedpartitions
>
>
> I propose altering the verb perm in statfns.ijs (and
> elsewhere, if perm exists elsewhere) with the following so
> that perm is ambivalent and the dyadic form is syntactically
> like comb. It may also be time to replace comb with cmb but
> I am less clear on this replacement.
>
> chs=: 4 : ';(,/@:(([,. ]+ <:)"0 _) )&.>/ (<i.1 0),~ i.&.>x{.(-i.)y'
> perm=: (! A.&i. ]) : chs
>
>
> On Sun, 10 Aug 2008, R.E. Boss wrote:
>
> + Define a
> + (k,n)-choice to be an ordered subset of k elements from a set of n
> + elements and a
> + (k,n)-combination to be an unordered subset of k elements from a set
> of n
> + elements,
> + than the question (see (*0) below) naturally arises:
> + What is the index of a (k,n)-combination in the lexicographically
> ordered
> + set of (k,n)-choices?
> +
> + Let cmb generates all (k,n)-combinations (see also (*1) below):
> + cmb=: [:,.^:(2>[EMAIL PROTECTED])@; [:(,.&.><@;\.)/ >:@[EMAIL PROTECTED]
> +
> + and chs all (k,n)-choices, see
> + http://www.jsoftware.com/pipermail/programming/2008-August/011683.html
> + chs=: 4 : ';(,/@:(([,. ]+ <:)"0 _) )&.>/ (<i.1 0),~ i.&.>x{.(-i.)y'
> +
> + Example:
> +
> + |:2 chs 5 NB. (2,5)-choices in columns
> + 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
> + 1 2 3 4 0 2 3 4 0 1 3 4 0 1 2 4 0 1 2 3
> +
> + |:2 cmb 5 NB. (2,5)-combinations in columns
> + 0 0 0 0 1 1 1 2 2 3
> + 1 2 3 4 2 3 4 3 4 4
> +
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm