161 lines
4.5 KiB
Plaintext
161 lines
4.5 KiB
Plaintext
{
|
|
Solutions to the Advent Of Code.
|
|
Copyright (C) 2023 Stefan Müller
|
|
|
|
This program is free software: you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
version.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
}
|
|
|
|
program AdventOfCode;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
uses
|
|
{$IFDEF UNIX}
|
|
cthreads,
|
|
{$ENDIF}
|
|
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, UStepCounter, USandSlabs, ULongWalk, UNeverTellMeTheOdds;
|
|
|
|
type
|
|
|
|
{ TAdventOfCode }
|
|
|
|
TAdventOfCode = class(TCustomApplication)
|
|
private
|
|
procedure RunPuzzleSolutions;
|
|
protected
|
|
procedure DoRun; override;
|
|
public
|
|
constructor Create(TheOwner: TComponent); override;
|
|
destructor Destroy; override;
|
|
procedure WriteHelp; virtual;
|
|
end;
|
|
|
|
{ TAdventOfCode }
|
|
|
|
procedure TAdventOfCode.RunPuzzleSolutions;
|
|
var
|
|
engine: TSolverEngine;
|
|
solvers: specialize TList<Integer>;
|
|
p: string;
|
|
n: Integer;
|
|
begin
|
|
WriteLn('### Advent of Code 2023 ###');
|
|
engine := TSolverEngine.Create('data');
|
|
|
|
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);
|
|
21: engine.RunAndFree(TStepCounter.Create);
|
|
22: engine.RunAndFree(TSandSlabs.Create);
|
|
23: engine.RunAndFree(TLongWalk.Create);
|
|
24: engine.RunAndFree(TNeverTellMeTheOdds.Create);
|
|
end;
|
|
|
|
engine.Free;
|
|
solvers.Free;
|
|
WriteLn;
|
|
end;
|
|
|
|
procedure TAdventOfCode.DoRun;
|
|
var
|
|
ErrorMsg: String;
|
|
begin
|
|
// quick check parameters
|
|
ErrorMsg := CheckOptions('hp:', ['help', 'puzzle:']);
|
|
if ErrorMsg <> '' then
|
|
begin
|
|
ShowException(Exception.Create(ErrorMsg));
|
|
Terminate;
|
|
Exit;
|
|
end;
|
|
|
|
// parse parameters
|
|
if HasOption('h', 'help') then
|
|
begin
|
|
WriteHelp;
|
|
Terminate;
|
|
Exit;
|
|
end;
|
|
|
|
RunPuzzleSolutions;
|
|
|
|
// stop program loop
|
|
Terminate;
|
|
end;
|
|
|
|
constructor TAdventOfCode.Create(TheOwner: TComponent);
|
|
begin
|
|
inherited Create(TheOwner);
|
|
StopOnException := True;
|
|
end;
|
|
|
|
destructor TAdventOfCode.Destroy;
|
|
begin
|
|
inherited Destroy;
|
|
end;
|
|
|
|
procedure TAdventOfCode.WriteHelp;
|
|
begin
|
|
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
|
|
Application: TAdventOfCode;
|
|
begin
|
|
Application := TAdventOfCode.Create(nil);
|
|
Application.Title := 'Advent of Code 2023';
|
|
Application.Run;
|
|
Application.Free;
|
|
end.
|
|
|