Here's what I get playing with it:

   ctoi=:monad : '+/(>:i.#y)!y'  NB. combination to integer
   require 'stats'
   (-: ~.) ctoi"1]3 comb 6
1

But I don't think ctoi retains enough information to distinguish
combinations of differing length. If you wanted that, I expect you'd
need to instead use something like

ctoiL=: p:@# ^ x:@ctoi

Thanks,

-- 
Raul
On Tue, Dec 11, 2018 at 12:10 PM Devon McCormick <[email protected]> wrote:
>
> In chapter 34 of "50 Shades", I'm questioning the assertion "any
> combination of r integers from i.n can be put into one-to-one
> correspondence with the counting integers " because this seems to
> contradict these tests:
>    ctoi=: 3 : '+/(>:i.#y)!y'  NB. combination to integer
>    ctoi&>3 2 1 4;4 3 2 1;1 2 3 4;3 2 1
> 5 7 4 4
> The first three permutations of the same combination map to different
> numbers but the last two different combos map to the same number.
> Am I misinterpreting the assertion?  Or does the combination need to be
> sorted?
>    (ctoi@:/:~) &> 3 2 1 4;4 3 2 1;1 2 3 4;3 2 1  NB. OK
> 4 4 4 3
> but
>    (ctoi@:/:~) &> 0 1 2;0 1 2 3
> 0 0
>
> --
>
> Devon McCormick, CFA
>
> Quantitative Consultant
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to