Re: how to calculate an index and vice versa
- To: mathgroup at smc.vnet.net
- Subject: [mg119304] Re: how to calculate an index and vice versa
- From: Heike Gramberg <heike.gramberg at gmail.com>
- Date: Mon, 30 May 2011 06:33:09 -0400 (EDT)
I'm not entirely sure what it is you're asking, but if I interpret your question correctly then one way to do this is to create a list with all the subsets of length 4 of {1,2,...,90} and use Position[] to find the index, e.g. n = 90; k = 4; lst = Subsets[Range[n], {k}]; index[s_] := Position[lst, s, 1, 1][[1, 1]] Then index[{a,b,c,d}] will give you the index of subset {a,b,c,d}. Note that in this example I start counting from 1, so index[{1,2,3,4}]==1 (and index[{87,88,89,90}]==2555190 which is Binomial[90,4] as it should be). lst[[k]] will give you the subset with index k. Heike. On 28 May 2011, at 12:20, ferradini 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 >