Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2779

Re: how to calculate an index and vice versa [ADDENDUM]

From Bob Hanlon <hanlonr@cox.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: how to calculate an index and vice versa [ADDENDUM]
Date 2011-05-29 11:38 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <irtb6p$plb$1@smc.vnet.net> (permalink)

Show all headers | View raw


My first response did not include examples of inverse.

ss = Subsets[Range[90], {4}];

Length[ss] == Binomial[90, 4]

True

assocIndex[elem_] := Position[ss, elem][[1, 1]] - 1

assocIndex[{1, 2, 3, 7}]

3

ss[[% + 1]]

{1, 2, 3, 7}

assocIndex[{10, 41, 60, 61}]

954721

ss[[% + 1]]

{10, 41, 60, 61}

assocIndex[{87, 88, 89, 90}]

2555189

ss[[% + 1]]

{87, 88, 89, 90}

Note that since you you started your index at zero your index numbers for your last two examples are off by one.


Bob Hanlon

---- ferradini <gianmarco.ferradini@email.it> wrote: 

=============
given n numbers (eg. 1 to 90)
I can build the following list of numbers k (in this case 4)

1, 2, 3, 4 associated index -> 0
1, 2, 3, 5 associated index -> 1
1, 2, 3, 6 associated index -> 2
1, 2, 3, 7 associated index -> 3
1, 2, 3, 8 ................... ....
1, 2, 3, 9 .......................
.......................
.......................
10, 41, 60, 61 associated index -> 954722
.......................
.......................
87, 88, 89, 90 associated index -> 2555190
I need to build an algorithm to assign eg 4 elemnti can obtain its index 
in the list
(1, 2, 3, 7 return 3)

The second algorithm is 'inverse: given a number such as 954722 I get 
the four elements 87; 88, 89, 90.
The elemnti in the list are always sorted values.

I thank those who will send me information on the subject to follow
Thank ferradini

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: how to calculate an index and vice versa [ADDENDUM] Bob Hanlon <hanlonr@cox.net> - 2011-05-29 11:38 +0000

csiph-web