Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
- [==============================================================================}
- function TIAMatch(TIA1, TIA2: TIntArray): Integer;
- var
- i, m: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- for i := 0 to m do
- if (TIA1[i] = TIA2[i]) then
- Inc(Result);
- end;
- {==============================================================================]
- Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
- [==============================================================================}
- function TIAMatches(TIA1, TIA2: TIntArray): TIntArray;
- var
- i, m, r: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- begin
- SetLength(Result, (m + 1));
- for i := 0 to m do
- if (TIA1[i] = TIA2[i]) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- SetLength(Result, r);
- end;
- end;
- {==============================================================================]
- Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
- If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.
- [==============================================================================}
- function TIAMatchEx(TIA1, TIA2: TIntArray; specialMatches: TIntArray): Integer;
- var
- i, m: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- for i := 0 to m do
- case (TIA1[i] = TIA2[i]) of
- True: Inc(Result);
- False:
- if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
- Inc(Result);
- end;
- end;
- {==============================================================================]
- Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
- If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.
- [==============================================================================}
- function TIAMatchesEx(TIA1, TIA2: TIntArray; specialMatches: TIntArray): TIntArray;
- var
- i, m, r: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- begin
- SetLength(Result, (m + 1));
- for i := 0 to m do
- case (TIA1[i] = TIA2[i]) of
- True:
- begin
- Result[r] := i;
- Inc(r);
- end;
- False:
- if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- end;
- SetLength(Result, r);
- end;
- end;
- var
- TIA, TIA1, TIA2: TIntArray;
- begin
- ClearDebug;
- TIA1 := [0, 1, 2, 3, 4, 3, 2, 1, 0];
- WriteLn('TIA1: ' + TIAToStr(TIA1) + ' [' + IntToStr(Length(TIA1)) + ' items]');
- TIA2 := [1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 0];
- WriteLn('TIA2: ' + TIAToStr(TIA2) + ' [' + IntToStr(Length(TIA2)) + ' items]' + #13#10);
- WriteLn('TIAMatch(TIA1, TIA2): ' + IntToStr(TIAMatch(TIA1, TIA2)));
- TIA := TIAMatches(TIA1, TIA2);
- WriteLn('TIAMatches(TIA1, TIA2): ' + TIAToStr(TIA) + #13#10);
- SetLength(TIA, 0);
- WriteLn('TIAMatchEx(TIA1, TIA2, [4, 0]): ' + IntToStr(TIAMatchEx(TIA1, TIA2, [4, 0])));
- TIA := TIAMatchesEx(TIA1, TIA2, [4, 0]);
- WriteLn('TIAMatchesEx(TIA1, TIA2, [4, 0]): ' + TIAToStr(TIA));
- SetLength(TIA, 0);
- SetLength(TIA1, 0);
- SetLength(TIA2, 0);
- end.
Advertisement
Add Comment
Please, Sign In to add comment