
Originally Posted by
CaptainBlack
So you mean:
Code:
begin
Input X_1 , X_2 .....X_n
count := 0
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 RonL
Which can be animated so we get a trace:
Code:
>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
> RonL