Subject: Compare fields and synchronize values
@for( i := 1; i <= @Length(field1); i := i + 1;
. . . . match := @False;
. . . . @for( j := 1; j <= @Length(field2); j := j + 1;
. . . . . . . . @if( field1[i] = field2[j]; @Do( ans := sum1[i] - sum2[j]; match := @True) ; "')
. . . . );
. . . . result := result : @if( match; ans; sum1[i])
);
@for( j := 1; j <= @Length(field2); j := j + 1;
. . . . match := @False;
. . . . @for( i := 1; i <= @Length(field1); i := i + 1;
. . . . . . . . @if( field2[j] = field1[i]; @do(match := @True) ; “”)
. . . . );
. . . . @if( match; “”; result := result : -1*sum2[j] )
);
3 6 1 1 7 -3
but doesn’t work if the first list has gaps.
Ignore the following - I see I mis-understood the original problem thinking you wanted to add the values. I realized after writing the following I should just be able to add up the numbers and then I realized I misunderstood your question.
Are field 1 and 2 arrays of values?
Will values in 2 always be in the first array? Or could I have a Z in the second array that isn’t in the first array?
Are the values unique?
Assuming the above how about:
ans := 0;
@for( i := 1; i <= @Length(field1); i := i + 1;
. . . . match := @False;
. . . . @for( j := 1; j <= @Length(field2); j := j + 1;
. . . . . . . . @if( field1[i] = field2[j]; @do(ans := ans + sum1[i] - sum2[j]; match := @True) ; “”)
. . . . );
. . . . ans := ans + @if( match; 0; sum1[i])
);
@for( j := 1; j <= @Length(field2); j := j + 1;
. . . . match := @False;
. . . . @for( i := 1; i <= @Length(field1); i := i + 1;
. . . . . . . . @if( field2[j] = field1[i]; @do(match := @True) ; “”)
. . . . );
. . . . ans := ans - @if( match; 0; sum2[j])
);
field1: A B C D E
sum1: 3 6 4 2 7
field2: C D Z
sum2: 3 1 3
I think this would give the answer of 15