From 0b0f4eabb4856eca1ca66ae4c401fb22ffe4c148 Mon Sep 17 00:00:00 2001 From: Buddhism8003 Date: Sun, 14 Dec 2025 16:06:38 +0100 Subject: [PATCH] Added a Downloader for AoC puzzle inputs --- .../AdventOfCode.Downloader.csproj | 10 ++++++ AdventOfCode.Downloader/Program.cs | 34 +++++++++++++++++++ AdventOfCode.HelperClasses/Coordinate.cs | 4 +-- AdventOfCode.sln | 6 ++++ AoC_2025.Tests/Day09Test.cs | 2 +- 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 AdventOfCode.Downloader/AdventOfCode.Downloader.csproj create mode 100644 AdventOfCode.Downloader/Program.cs diff --git a/AdventOfCode.Downloader/AdventOfCode.Downloader.csproj b/AdventOfCode.Downloader/AdventOfCode.Downloader.csproj new file mode 100644 index 0000000..85b4959 --- /dev/null +++ b/AdventOfCode.Downloader/AdventOfCode.Downloader.csproj @@ -0,0 +1,10 @@ + + + + Exe + net9.0 + enable + enable + + + diff --git a/AdventOfCode.Downloader/Program.cs b/AdventOfCode.Downloader/Program.cs new file mode 100644 index 0000000..e008ab2 --- /dev/null +++ b/AdventOfCode.Downloader/Program.cs @@ -0,0 +1,34 @@ +// See https://aka.ms/new-console-template for more information + +if (args.Length < 3) +{ + Console.WriteLine("Usage: AdventOfCode-Downloader.exe "); + return; +} + +int year, day; +if (!(int.TryParse(args[0], out year) && year <= DateTime.Now.Year && year > 2015) || !(int.TryParse(args[1], out day) && day is >= 1 and <= 25)) +{ + Console.WriteLine("Invalid year or date argument.\nYear must be between 2015 and current year and day must be between 1 and 25"); + return; +} + +var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AoC-PuzzleInputs", + year.ToString(), "Prod", $"day{day:00}.txt"); +if(!Directory.Exists(Path.GetDirectoryName(path))) + Directory.CreateDirectory(Path.GetDirectoryName(path)!); + +var url = new Uri($"https://adventofcode.com/{year}/day/{day}/input"); +using var client = new HttpClient(); +client.DefaultRequestHeaders.Add("Cookie", $"session={args[2]}"); +var responseMessage = await client.GetAsync(url); +if (responseMessage.IsSuccessStatusCode) +{ + var inputString = await responseMessage.Content.ReadAsStringAsync(); + await File.WriteAllTextAsync(path, inputString); +} +else +{ + var inputString = await responseMessage.Content.ReadAsStringAsync(); + Console.WriteLine($"Response status code does not indicate Success: {responseMessage.StatusCode} ({responseMessage.StatusCode.ToString()})\nError Message: " + inputString); +} diff --git a/AdventOfCode.HelperClasses/Coordinate.cs b/AdventOfCode.HelperClasses/Coordinate.cs index bbc94c7..30d3463 100644 --- a/AdventOfCode.HelperClasses/Coordinate.cs +++ b/AdventOfCode.HelperClasses/Coordinate.cs @@ -3,7 +3,7 @@ public record Coordinate(long X, long Y) { public double GetEuclidianDistance(Coordinate other) => - Math.Sqrt((X - other.X) * (X - other.X) + (Y - other.Y) * (Y - other.Y)); + GetEuclidianDistance(this, other); public static double GetEuclidianDistance(Coordinate a, Coordinate b) => Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y)); @@ -15,7 +15,7 @@ public record Coordinate(long X, long Y) public record Coordinate3d(long X, long Y, long Z) { public double GetEuclidianDistance(Coordinate3d other) => - Math.Sqrt((X - other.X) * (X - other.X) + (Y - other.Y) * (Y - other.Y) + (Z - other.Z) * (Z - other.Z)); + GetEuclidianDistance(this, other); public static double GetEuclidianDistance(Coordinate3d a, Coordinate3d b) => Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z)); diff --git a/AdventOfCode.sln b/AdventOfCode.sln index 645a128..5b17a0d 100644 --- a/AdventOfCode.sln +++ b/AdventOfCode.sln @@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode.HelperClasses" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode.HelperClasses.Tests", "AdventOfCode.HelperClasses.Tests\AdventOfCode.HelperClasses.Tests.csproj", "{3D09528A-09A7-4B0B-9D45-7D3AAB26449A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode.Downloader", "AdventOfCode.Downloader\AdventOfCode.Downloader.csproj", "{43B006C3-5296-452B-BD86-225574C0E2A2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -50,6 +52,10 @@ Global {3D09528A-09A7-4B0B-9D45-7D3AAB26449A}.Debug|Any CPU.Build.0 = Debug|Any CPU {3D09528A-09A7-4B0B-9D45-7D3AAB26449A}.Release|Any CPU.ActiveCfg = Release|Any CPU {3D09528A-09A7-4B0B-9D45-7D3AAB26449A}.Release|Any CPU.Build.0 = Release|Any CPU + {43B006C3-5296-452B-BD86-225574C0E2A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43B006C3-5296-452B-BD86-225574C0E2A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43B006C3-5296-452B-BD86-225574C0E2A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43B006C3-5296-452B-BD86-225574C0E2A2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {4F395AE3-DABB-4546-A4D0-5A62425FE168} = {05EBAA1C-B33B-4AFE-8635-A58D7CA509A7} diff --git a/AoC_2025.Tests/Day09Test.cs b/AoC_2025.Tests/Day09Test.cs index f46c558..5c04e00 100644 --- a/AoC_2025.Tests/Day09Test.cs +++ b/AoC_2025.Tests/Day09Test.cs @@ -42,7 +42,7 @@ public class Day09Test public void Part02_Test2_equals_30() { // todo: color edges as right, left, up, down to only allow rectangles between right and left or up and down edges - var actual = _sut.SolvePart2(Test2InputPath); + //var actual = _sut.SolvePart2(Test2InputPath); //Assert.Equal(30, actual); }