I tried a dozen times and got the NaN error every time. Both del1 and permC are defined. I redefined permNF again (verifying that it was a single line ending in f.) just to be sure, and tried again. Still got NaN error.
The result of permN in an example I threw into dissect was _ and I am wondering if that might be the problem? -- Raul On Sun, May 8, 2016 at 8:57 AM, 'Pascal Jasmin' via Programming <[email protected]> wrote: > If you rerun the same line, does it return 1? I don't get the error, but its > operating on random numbers, so it could be rare. > > permNF definition is a single line, and relies on the 2 definitions above it. > > > > ----- Original Message ----- > From: Raul Miller <[email protected]> > To: Programming forum <[email protected]> > Sent: Sunday, May 8, 2016 7:44 AM > Subject: Re: [Jprogramming] permutation and combination numbers (with repeat) > > 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 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
