I get: (] -: /:~ permNF~ permN) ? 200 $ 60 |NaN error: permNF
Can you reproduce this error? FYI, -- Raul On Sat, May 7, 2016 at 10:03 PM, 'Pascal Jasmin' via Programming <[email protected]> wrote: > faster version works with gaps. permNF is decoder from permutaion number > > > del1 =: i.~ ({. , >:@[ }. ]) ] > permC =: # %&(x:@:(*/))&:! #/.~ > > permNF =: 2 {:: (] (((0 {:: [) - ] * (1 {:: [) ([ i. {~) (0 {:: [) <.@% ]) ; > [ ((] ,~ 2 {:: [) ;~ ] del1 1 {:: [) (1 {:: [) {~ (0 {:: [) <.@% ]) 1 > (permC % #)@{:: ])^:(0 < 1 #@{:: ])^:_@:(a:,~ ;) f. > > > permN =: +/@:(((permC % #) * 0 i.~ /:)\.) > > > > (] -: /:~ permNF~ permN) ? 200 $ 60 > > ----- Original Message ----- > From: 'Pascal Jasmin' via Programming <[email protected]> > To: Programming Forum <[email protected]> > Sent: Thursday, May 5, 2016 5:58 PM > Subject: [Jprogramming] permutation and combination numbers (with repeat) > > Some routines to calculate permutation and combination numbers, similar to A. > (but allows permutations with repeat) > > del1 =: i.~ ({. , >:@[ }. ]) ] > > combN =: (0:`((<:@[ - {.@]) $: >:@{.@] -~ }.@])@.(0 < #@]) + 0:`(<:@#@] +/@:! > <:@[ - i.@{.@])@.(0 < {.@]) ) > > combNF =: 3 : 'a =. 1 { 0 {:: y label_. (i.a) + +/\ 1 {:: ([ (] ;~ [ - 1 ,~ > _2 >:@{ ]) }:@] , {:@] ([ ({.@] ,(- {:)) ] (] , {~) 1 i:~ >:) (0 , ] (+/\)@:! > ( a i.@:-~ [) -~ [)/@:<:@[ )&>/^: (<:a) y'@:; > > permC =: # %&(x:@:(*/))&:! #/.~ > > permN1 =: ((0:`( (] - <./)@:({.@] del1 [) $: (] - <./)@:}.@] )@.(1 < #@])) + > (permC % #)@] * [ i. {.@] ) f. > > permN =: /:~ permN1 ] > > 100x combN 15 25 35 45 55 65 85 > 11284989655 > > 100 7 combNF 11284989655x > 15 25 35 45 55 65 85 > > permN 1 0 0 2 1 3 3 1 > 434 > > haven't done the reverse to permN yet, but these routines combined can be > used to compress any list into 2 numbers (with a key). You can google for > combinatorial number base, and there is A., but not sure A. has been done for > permutations with repeats. Which produces smaller numbers than A. does (due > to fewer underlying permutations). > ---------------------------------------------------------------------- > 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
