the _ stand for subscript
i need to see if the algorithm works with the list 2, 3,6,2,6Code:begin Input X_1 , X_2 .....X_n count := - for i:=2 to n do begin for j:=1 to (i-1) do begin if x_i = x_j then begin count := count = 1 end end output count end end
the theory would be very muc appricated
many thanks
well looking at it
you started by inputting a sequecne of numbers
set the count to zero
the you see if i is equal to 2 - n and then you begin the fsecond loop which check to see if j is equal to 1 all the way to i-1 (which in the first casue is 1)
and if that is correct then you add one to the count if x_i it equal to x_j
you end but outputting the count
that is what i think it does
many thanks
Which can be animated so we get a trace:
RonLCode:>load "C:\Documents and Settings\Ron\My Documents\temp\test.e" >type test function test () count= 0; x=[2,3,6,2,6]; n=length(x); for i=2 to n for j=1 to (i-1) if x(i) == x(j) count = count + 1; endif [i,j,count] end end return 0 endfunction > > >..output is i, j, count > >test 2 1 0 3 1 0 3 2 0 4 1 1 4 2 1 4 3 1 5 1 1 5 2 1 5 3 2 5 4 2 0 >
As it says above the output is i, j, count for each trip around the inner loop.
The final 0 is the return value of the function to indicate successfull execution, and can be ignored.
The only thing that might be considered slightly obscure is the line [i,j,count], which because it does not end in a semicolon echos the vector consisting ot i, j and count to the console.
RonL