SCAR Code:
program new;
Function Mean(Values: TExtendedArray): Extended;
Var
I: Integer;
Begin
For I := 0 To High(Values) Do
Result := Result + Values[i];
Result := Result / GetArrayLength(Values);
End;
Function UpdateColorFromArray(Ref: Integer; Colors: TIntegerArray): Integer;
Var
Dif: Array of Array [0..2] Of Extended;
HSL, HSL2: Array [0..2] Of Extended;
SortedDif: TExtendedArray;
C, I, L, D: Integer;
R: Extended;
Begin
ColorToHSL(Ref, HSL[0], HSL[1], HSL[2]);
SetArrayLength(Dif, GetArrayLength(Colors));
L := High(Colors);
For I := 0 To L Do
Begin
ColorToHSL(Colors[i], HSL2[0], HSL2[1], HSL2[2]);
For C := 0 To 2 Do
Dif[i][c] := Abs(HSL[c] - HSL2[c]);
End;
L := High(Dif);
SetArrayLength(SortedDif, L + 1);
For D := 0 To L Do
SortedDif[d] := Mean([Dif[d][0], Dif[d][1], Dif[d][2]]);
R := AMinE(SortedDif);
For C := 0 To L Do
If SortedDif[c] = R Then
Begin
Result := Colors[c];
Exit;
End;
End;
begin
Writeln(IntToStr(UpdateColorFromArray(255, [210, 22, 244])));
End.