Added p/puzzle command line option to run only specific puzzles, and updated the application help text

This commit is contained in:
Stefan Müller 2023-12-21 18:32:40 +01:00 committed by Stefan Müller
parent 55f8f3d674
commit 8d5757fae0
1 changed files with 54 additions and 28 deletions

View File

@ -23,10 +23,11 @@ uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, CustApp, USolver, UTrebuchet, UCubeConundrum, UGearRatios, UScratchcards, UGiveSeedFertilizer,
UWaitForIt, UCamelCards, UHauntedWasteland, UNumberTheory, UMirageMaintenance, UPipeMaze, UCosmicExpansion,
UHotSprings, UPointOfIncidence, UParabolicReflectorDish, ULensLibrary, UFloorWillBeLava, UClumsyCrucible,
ULavaductLagoon, UAplenty, UPulsePropagation;
Classes, SysUtils, CustApp, Generics.Collections, USolver,
UTrebuchet, UCubeConundrum, UGearRatios, UScratchcards, UGiveSeedFertilizer, UWaitForIt, UCamelCards,
UHauntedWasteland, UNumberTheory, UMirageMaintenance, UPipeMaze, UCosmicExpansion, UHotSprings, UPointOfIncidence,
UParabolicReflectorDish, ULensLibrary, UFloorWillBeLava, UClumsyCrucible, ULavaductLagoon, UAplenty,
UPulsePropagation;
type
@ -48,30 +49,51 @@ type
procedure TAdventOfCode.RunPuzzleSolutions;
var
engine: TSolverEngine;
solvers: specialize TList<Integer>;
p: string;
n: Integer;
begin
WriteLn('### Advent of Code 2023 ###');
engine := TSolverEngine.Create('data');
engine.RunAndFree(TTrebuchet.Create);
engine.RunAndFree(TCubeConundrum.Create);
engine.RunAndFree(TGearRatios.Create);
engine.RunAndFree(TScratchcards.Create);
engine.RunAndFree(TGiveSeedFertilizer.Create);
engine.RunAndFree(TWaitForIt.Create);
engine.RunAndFree(TCamelCards.Create);
engine.RunAndFree(THauntedWasteland.Create);
engine.RunAndFree(TMirageMaintenance.Create);
engine.RunAndFree(TPipeMaze.Create);
engine.RunAndFree(TCosmicExpansion.Create);
engine.RunAndFree(THotSprings.Create);
engine.RunAndFree(TPointOfIncidence.Create);
engine.RunAndFree(TParabolicReflectorDish.Create);
engine.RunAndFree(TLensLibrary.Create);
engine.RunAndFree(TFloorWillBeLava.Create);
engine.RunAndFree(TClumsyCrucible.Create);
engine.RunAndFree(TLavaductLagoon.Create);
engine.RunAndFree(TAplenty.Create);
engine.RunAndFree(TPulsePropagation.Create);
solvers := specialize TList<Integer>.Create;
if HasOption('p', 'puzzle') then
begin
for p in GetOptionValues('p', 'puzzle') do
if TryStrToInt(p, n) then
solvers.Add(n);
end
else
for n := 1 to 25 do
solvers.Add(n);
for n in solvers do
case n of
1: engine.RunAndFree(TTrebuchet.Create);
2: engine.RunAndFree(TCubeConundrum.Create);
3: engine.RunAndFree(TGearRatios.Create);
4: engine.RunAndFree(TScratchcards.Create);
5: engine.RunAndFree(TGiveSeedFertilizer.Create);
6: engine.RunAndFree(TWaitForIt.Create);
7: engine.RunAndFree(TCamelCards.Create);
8: engine.RunAndFree(THauntedWasteland.Create);
9: engine.RunAndFree(TMirageMaintenance.Create);
10: engine.RunAndFree(TPipeMaze.Create);
11: engine.RunAndFree(TCosmicExpansion.Create);
12: engine.RunAndFree(THotSprings.Create);
13: engine.RunAndFree(TPointOfIncidence.Create);
14: engine.RunAndFree(TParabolicReflectorDish.Create);
15: engine.RunAndFree(TLensLibrary.Create);
16: engine.RunAndFree(TFloorWillBeLava.Create);
17: engine.RunAndFree(TClumsyCrucible.Create);
18: engine.RunAndFree(TLavaductLagoon.Create);
19: engine.RunAndFree(TAplenty.Create);
20: engine.RunAndFree(TPulsePropagation.Create);
end;
engine.Free;
solvers.Free;
WriteLn;
end;
procedure TAdventOfCode.DoRun;
@ -79,7 +101,7 @@ var
ErrorMsg: String;
begin
// quick check parameters
ErrorMsg := CheckOptions('h', 'help');
ErrorMsg := CheckOptions('hp:', ['help', 'puzzle:']);
if ErrorMsg <> '' then
begin
ShowException(Exception.Create(ErrorMsg));
@ -95,7 +117,6 @@ begin
Exit;
end;
{ add your program here }
RunPuzzleSolutions;
// stop program loop
@ -115,8 +136,13 @@ end;
procedure TAdventOfCode.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ', ExeName, ' -h');
WriteLn('Usage: ', ExeName, ' [Options]');
WriteLn('Options:');
WriteLn(' --help, -h');
WriteLn(' Shows this usage help.');
WriteLn(' --puzzle=<n>, -p <n>');
WriteLn(' Instead of running all solvers, only run the one for day <n>.');
WriteLn(' Integer from 1 to 25. Can be specified multiple times.');
end;
var