Added custom constructors for TCosmicExpansion and TStepCounter to simplify test case setup
This commit is contained in:
@@ -35,17 +35,17 @@ type
|
||||
|
||||
TCosmicExpansion = class(TSolver)
|
||||
private
|
||||
FExpansionFactor: Integer;
|
||||
FColumnExpansion, FRowExpansion: specialize TList<Integer>;
|
||||
FGalaxies: specialize TList<TPoint>;
|
||||
procedure InitColumnExpansion(const ASize: Integer);
|
||||
public
|
||||
constructor Create;
|
||||
constructor Create(const AExpansionFactor: Integer = 999999);
|
||||
destructor Destroy; override;
|
||||
procedure ProcessDataLine(const ALine: string); override;
|
||||
procedure Finish; override;
|
||||
function GetDataFileName: string; override;
|
||||
function GetPuzzleName: string; override;
|
||||
function GetExpansionFactor: Integer; virtual;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -64,8 +64,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TCosmicExpansion.Create;
|
||||
constructor TCosmicExpansion.Create(const AExpansionFactor: Integer);
|
||||
begin
|
||||
FExpansionFactor := AExpansionFactor;
|
||||
FColumnExpansion := specialize TList<Integer>.Create;
|
||||
FRowExpansion := specialize TList<Integer>.Create;
|
||||
FGalaxies := specialize TList<TPoint>.Create;
|
||||
@@ -110,12 +111,12 @@ begin
|
||||
for k := Min(FGalaxies[i].X, FGalaxies[j].X) to Max(FGalaxies[i].X, FGalaxies[j].X) - 1 do
|
||||
begin
|
||||
Inc(FPart1, 1 + FColumnExpansion[k]);
|
||||
Inc(FPart2, 1 + FColumnExpansion[k] * GetExpansionFactor);
|
||||
Inc(FPart2, 1 + FColumnExpansion[k] * FExpansionFactor);
|
||||
end;
|
||||
for k := Min(FGalaxies[i].Y, FGalaxies[j].Y) + 1 to Max(FGalaxies[i].Y, FGalaxies[j].Y) do
|
||||
begin
|
||||
Inc(FPart1, 1 + FRowExpansion[k]);
|
||||
Inc(FPart2, 1 + FRowExpansion[k] * GetExpansionFactor);
|
||||
Inc(FPart2, 1 + FRowExpansion[k] * FExpansionFactor);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@@ -130,10 +131,5 @@ begin
|
||||
Result := 'Day 11: Cosmic Expansion';
|
||||
end;
|
||||
|
||||
function TCosmicExpansion.GetExpansionFactor: Integer;
|
||||
begin
|
||||
Result := 999999;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ type
|
||||
function GetPosition(constref APoint: TPoint): Char;
|
||||
procedure SetPosition(constref APoint: TPoint; const AValue: Char);
|
||||
public
|
||||
property MaxSteps: Integer read FMaxSteps write FMaxSteps;
|
||||
constructor Create;
|
||||
constructor Create(const AMaxSteps: Integer = 64);
|
||||
destructor Destroy; override;
|
||||
procedure ProcessDataLine(const ALine: string); override;
|
||||
procedure Finish; override;
|
||||
@@ -90,9 +89,9 @@ begin
|
||||
FLines[APoint.Y] := s;
|
||||
end;
|
||||
|
||||
constructor TStepCounter.Create;
|
||||
constructor TStepCounter.Create(const AMaxSteps: Integer);
|
||||
begin
|
||||
FMaxSteps := 64;
|
||||
FMaxSteps := AMaxSteps;
|
||||
FLines := TStringList.Create;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user