RE: Multiplexing varibles by subscripts
- Posted by Ron Austin <ronaustin at alltel.net> Dec 16, 2003
- 483 views
shepardmar at yahoo.com wrote: > > > Hi Everybody: > First, I will like to thank you for your help in advance. > > I was looking at how to count and add a variable's subcripts > > > Ex. > I have a set of 20 variables > the variables contain three subcripts > > ex > Variable #1 is sequence with three subcripts > { 8,1,5} > > I want to compare the list of 10 variables with 4 variables > that were selected at random with a Rand(10) = VariableX function > > > so, if the rand function gave me a value of 10... the rountine will find > > > the 10Th variable from the list of the 10 variables and put the 2nd > subcript of the 10th variable > into a temp variable for counting. > > the routine would need to check 4 random selected values and see which > of the 4 contain one of two > values in the subscript. THe values being 1 or 0 > > let's say > > > of the 4 random variables when compared with the listofvariables would > > have selected > > variable#1, with subscript#2 at 1 > variable#2, with subscript#2 at 0 > variable#7, with subscript#2 at 1 > variable#8, with subscript#2 at 1 > > the routine would give the following result > > 1) total 1 = 3 > 2) total 0 = 1 > > I tried to put the subsript into another variable but it will not let me > > ex > > x = variable[2] > > I also tried putting the value of x into a variable subcript with no > luck > > variable[2] = x > > > Any help would be appreciated > > Regards > Shep > I'm a newbie too and I was not sure what you wanted, you first said a list of 20 variables, but then refered to "a list of 10 variables". Anyway, I thought I'd take a stab at it. I first build a list of 20 variables, then I randomly picked four of them, then checked and accumilated the results constant CrLf = { '\r', '\n' } sequence list,temp,xxx integer total0,total1,c1,c2,c3,ct,junk,item -- you must initialize all variables list="" total0=0 total1=0 junk=0 item=0 -- build list of 20 variables using random numbers for i=1 to 20 do c1=rand(20) c2=rand(2)-1 c3=rand(20) temp=c1&c2&c3 list=append(list,temp) end for -- print list print(1,list) puts (1,CrLf) -- pick four random sequences and accumilate totals for i=1 to 4 do item=rand(20) ct= (list[item][2]) print(1,ct) puts(1,CrLf) if ct=0 then total0+=1 elsif ct=1 then total1+=1 else junk+=1 end if end for -- print totals puts(1,"total0 ") print (1,total0) puts (1,CrLf) puts(1,"total1 ") print (1,total1) puts (1,CrLf) puts (1,"junk ") print (1,junk) puts(1,CrLf) As you can see, I'm not very good at printing to the screen. I hope this helps