2023-12-02 00:25:07 +01:00
|
|
|
{
|
|
|
|
Solutions to the Advent Of Code.
|
2024-06-03 20:50:56 +02:00
|
|
|
Copyright (C) 2023-2024 Stefan Müller
|
2023-12-02 00:25:07 +01:00
|
|
|
|
|
|
|
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}
|
2023-12-21 18:32:40 +01:00
|
|
|
Classes, SysUtils, CustApp, Generics.Collections, USolver,
|
|
|
|
UTrebuchet, UCubeConundrum, UGearRatios, UScratchcards, UGiveSeedFertilizer, UWaitForIt, UCamelCards,
|
2024-06-03 20:50:56 +02:00
|
|
|
UHauntedWasteland, UMirageMaintenance, UPipeMaze, UCosmicExpansion, UHotSprings, UPointOfIncidence,
|
2023-12-21 18:32:40 +01:00
|
|
|
UParabolicReflectorDish, ULensLibrary, UFloorWillBeLava, UClumsyCrucible, ULavaductLagoon, UAplenty,
|
2024-06-04 17:14:24 +02:00
|
|
|
UPulsePropagation, UStepCounter, USandSlabs, ULongWalk, UNeverTellMeTheOdds, USnowverload;
|
2023-12-02 00:25:07 +01:00
|
|
|
|
|
|
|
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;
|
2023-12-03 17:55:00 +01:00
|
|
|
var
|
|
|
|
engine: TSolverEngine;
|
2023-12-21 18:32:40 +01:00
|
|
|
solvers: specialize TList<Integer>;
|
|
|
|
p: string;
|
|
|
|
n: Integer;
|
2023-12-02 00:25:07 +01:00
|
|
|
begin
|
2023-12-03 01:27:35 +01:00
|
|
|
WriteLn('### Advent of Code 2023 ###');
|
2024-02-22 22:26:31 +01:00
|
|
|
engine := TSolverEngine.Create(TStringArray.Create(
|
|
|
|
'data',
|
|
|
|
ConcatPaths(['..', '..', 'data'])
|
|
|
|
));
|
2023-12-21 18:32:40 +01:00
|
|
|
|
|
|
|
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);
|
2023-12-21 21:11:31 +01:00
|
|
|
21: engine.RunAndFree(TStepCounter.Create);
|
2023-12-23 01:30:41 +01:00
|
|
|
22: engine.RunAndFree(TSandSlabs.Create);
|
2023-12-25 00:44:13 +01:00
|
|
|
23: engine.RunAndFree(TLongWalk.Create);
|
2023-12-26 18:29:05 +01:00
|
|
|
24: engine.RunAndFree(TNeverTellMeTheOdds.Create);
|
2024-06-04 17:14:24 +02:00
|
|
|
25: engine.RunAndFree(TSnowverload.Create);
|
2023-12-21 18:32:40 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-03 17:55:00 +01:00
|
|
|
engine.Free;
|
2023-12-21 18:32:40 +01:00
|
|
|
solvers.Free;
|
|
|
|
WriteLn;
|
2023-12-02 00:25:07 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TAdventOfCode.DoRun;
|
|
|
|
var
|
|
|
|
ErrorMsg: String;
|
|
|
|
begin
|
|
|
|
// quick check parameters
|
2023-12-21 18:32:40 +01:00
|
|
|
ErrorMsg := CheckOptions('hp:', ['help', 'puzzle:']);
|
2023-12-02 00:25:07 +01:00
|
|
|
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
|
2023-12-21 18:32:40 +01:00
|
|
|
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.');
|
2023-12-02 00:25:07 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
Application: TAdventOfCode;
|
|
|
|
begin
|
|
|
|
Application := TAdventOfCode.Create(nil);
|
|
|
|
Application.Title := 'Advent of Code 2023';
|
|
|
|
Application.Run;
|
|
|
|
Application.Free;
|
|
|
|
end.
|
|
|
|
|