├── .gitignore ├── AdventOfCode.Solutions ├── InputService.cs ├── SolutionBase.cs ├── SolutionCollector.cs ├── SolutionResult.cs ├── Utils │ ├── CalculationUtils.cs │ ├── CollectionUtils.cs │ └── StringUtils.cs └── Year2024 │ ├── Day01 │ └── Solution.cs │ ├── Day02 │ └── Solution.cs │ ├── Day03 │ └── Solution.cs │ ├── Day04 │ └── Solution.cs │ ├── Day05 │ └── Solution.cs │ ├── Day06 │ └── Solution.cs │ ├── Day07 │ └── Solution.cs │ ├── Day08 │ └── Solution.cs │ ├── Day09 │ └── Solution.cs │ ├── Day10 │ └── Solution.cs │ ├── Day11 │ └── Solution.cs │ ├── Day12 │ └── Solution.cs │ ├── Day13 │ └── Solution.cs │ ├── Day14 │ └── Solution.cs │ ├── Day15 │ └── Solution.cs │ ├── Day16 │ └── Solution.cs │ ├── Day17 │ └── Solution.cs │ ├── Day18 │ └── Solution.cs │ ├── Day19 │ └── Solution.cs │ ├── Day20 │ └── Solution.cs │ ├── Day21 │ └── Solution.cs │ ├── Day22 │ └── Solution.cs │ ├── Day23 │ └── Solution.cs │ ├── Day24 │ └── Solution.cs │ └── Day25 │ └── Solution.cs ├── AdventOfCode.csproj ├── AdventOfCode.sln ├── Config.cs ├── GenerateSolutionFiles.ps1 ├── LICENSE.md ├── Makefile ├── Program.cs ├── README.md └── templates └── solution.cs.template /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | 30 | # Visual Studio Code 31 | .vscode/ 32 | 33 | # Uncomment if you have tasks that create the project's static files in wwwroot 34 | #wwwroot/ 35 | 36 | # Visual Studio 2017 auto generated files 37 | Generated\ Files/ 38 | 39 | # MSTest test Results 40 | [Tt]est[Rr]esult*/ 41 | [Bb]uild[Ll]og.* 42 | 43 | # NUNIT 44 | *.VisualState.xml 45 | TestResult.xml 46 | 47 | # Build Results of an ATL Project 48 | [Dd]ebugPS/ 49 | [Rr]eleasePS/ 50 | dlldata.c 51 | 52 | # Benchmark Results 53 | BenchmarkDotNet.Artifacts/ 54 | 55 | # .NET Core 56 | project.lock.json 57 | project.fragment.lock.json 58 | artifacts/ 59 | **/Properties/launchSettings.json 60 | 61 | # StyleCop 62 | StyleCopReport.xml 63 | 64 | # Files built by Visual Studio 65 | *_i.c 66 | *_p.c 67 | *_i.h 68 | *.ilk 69 | *.meta 70 | *.obj 71 | *.iobj 72 | *.pch 73 | *.pdb 74 | *.ipdb 75 | *.pgc 76 | *.pgd 77 | *.rsp 78 | *.sbr 79 | *.tlb 80 | *.tli 81 | *.tlh 82 | *.tmp 83 | *.tmp_proj 84 | *.log 85 | *.vspscc 86 | *.vssscc 87 | .builds 88 | *.pidb 89 | *.svclog 90 | *.scc 91 | 92 | # Chutzpah Test files 93 | _Chutzpah* 94 | 95 | # Visual C++ cache files 96 | ipch/ 97 | *.aps 98 | *.ncb 99 | *.opendb 100 | *.opensdf 101 | *.sdf 102 | *.cachefile 103 | *.VC.db 104 | *.VC.VC.opendb 105 | 106 | # Visual Studio profiler 107 | *.psess 108 | *.vsp 109 | *.vspx 110 | *.sap 111 | 112 | # Visual Studio Trace Files 113 | *.e2e 114 | 115 | # TFS 2012 Local Workspace 116 | $tf/ 117 | 118 | # Guidance Automation Toolkit 119 | *.gpState 120 | 121 | # ReSharper is a .NET coding add-in 122 | _ReSharper*/ 123 | *.[Rr]e[Ss]harper 124 | *.DotSettings.user 125 | 126 | # JustCode is a .NET coding add-in 127 | .JustCode 128 | 129 | # TeamCity is a build add-in 130 | _TeamCity* 131 | 132 | # DotCover is a Code Coverage Tool 133 | *.dotCover 134 | 135 | # AxoCover is a Code Coverage Tool 136 | .axoCover/* 137 | !.axoCover/settings.json 138 | 139 | # Visual Studio code coverage results 140 | *.coverage 141 | *.coveragexml 142 | 143 | # NCrunch 144 | _NCrunch_* 145 | .*crunch*.local.xml 146 | nCrunchTemp_* 147 | 148 | # MightyMoose 149 | *.mm.* 150 | AutoTest.Net/ 151 | 152 | # Web workbench (sass) 153 | .sass-cache/ 154 | 155 | # Installshield output folder 156 | [Ee]xpress/ 157 | 158 | # DocProject is a documentation generator add-in 159 | DocProject/buildhelp/ 160 | DocProject/Help/*.HxT 161 | DocProject/Help/*.HxC 162 | DocProject/Help/*.hhc 163 | DocProject/Help/*.hhk 164 | DocProject/Help/*.hhp 165 | DocProject/Help/Html2 166 | DocProject/Help/html 167 | 168 | # Click-Once directory 169 | publish/ 170 | 171 | # Publish Web Output 172 | *.[Pp]ublish.xml 173 | *.azurePubxml 174 | # Note: Comment the next line if you want to checkin your web deploy settings, 175 | # but database connection strings (with potential passwords) will be unencrypted 176 | *.pubxml 177 | *.publishproj 178 | 179 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 180 | # checkin your Azure Web App publish settings, but sensitive information contained 181 | # in these scripts will be unencrypted 182 | PublishScripts/ 183 | 184 | # NuGet Packages 185 | *.nupkg 186 | # The packages folder can be ignored because of Package Restore 187 | **/[Pp]ackages/* 188 | # except build/, which is used as an MSBuild target. 189 | !**/[Pp]ackages/build/ 190 | # Uncomment if necessary however generally it will be regenerated when needed 191 | #!**/[Pp]ackages/repositories.config 192 | # NuGet v3's project.json files produces more ignorable files 193 | *.nuget.props 194 | *.nuget.targets 195 | 196 | # Microsoft Azure Build Output 197 | csx/ 198 | *.build.csdef 199 | 200 | # Microsoft Azure Emulator 201 | ecf/ 202 | rcf/ 203 | 204 | # Windows Store app package directories and files 205 | AppPackages/ 206 | BundleArtifacts/ 207 | Package.StoreAssociation.xml 208 | _pkginfo.txt 209 | *.appx 210 | 211 | # Visual Studio cache files 212 | # files ending in .cache can be ignored 213 | *.[Cc]ache 214 | # but keep track of directories ending in .cache 215 | !*.[Cc]ache/ 216 | 217 | # Others 218 | ClientBin/ 219 | ~$* 220 | *~ 221 | *.dbmdl 222 | *.dbproj.schemaview 223 | *.jfm 224 | *.pfx 225 | *.publishsettings 226 | orleans.codegen.cs 227 | 228 | # Including strong name files can present a security risk 229 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 230 | #*.snk 231 | 232 | # Since there are multiple workflows, uncomment next line to ignore bower_components 233 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 234 | #bower_components/ 235 | 236 | # RIA/Silverlight projects 237 | Generated_Code/ 238 | 239 | # Backup & report files from converting an old project file 240 | # to a newer Visual Studio version. Backup files are not needed, 241 | # because we have git ;-) 242 | _UpgradeReport_Files/ 243 | Backup*/ 244 | UpgradeLog*.XML 245 | UpgradeLog*.htm 246 | ServiceFabricBackup/ 247 | *.rptproj.bak 248 | 249 | # SQL Server files 250 | *.mdf 251 | *.ldf 252 | *.ndf 253 | 254 | # Business Intelligence projects 255 | *.rdl.data 256 | *.bim.layout 257 | *.bim_*.settings 258 | *.rptproj.rsuser 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush 299 | .cr/ 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Visual Studio Code 337 | .vscode/* 338 | !.vscode/settings.json 339 | !.vscode/extensions.json 340 | *.code-workspace 341 | 342 | # Local configuration 343 | config.json 344 | AdventOfCode.Solutions/Year*/Day*/debug 345 | AdventOfCode.Solutions/Year*/Day*/input 346 | 347 | .ionide -------------------------------------------------------------------------------- /AdventOfCode.Solutions/InputService.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace AdventOfCode.Solutions; 4 | 5 | public static class InputService 6 | { 7 | private static readonly HttpClientHandler _handler = new() 8 | { 9 | CookieContainer = GetCookieContainer(), 10 | UseCookies = true, 11 | }; 12 | 13 | private static readonly HttpClient _client = new(_handler) 14 | { 15 | BaseAddress = new Uri("https://adventofcode.com/"), 16 | }; 17 | 18 | public static async Task FetchInput(int year, int day) 19 | { 20 | var currentEst = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Utc).AddHours(-5); 21 | if (currentEst < new DateTime(year, 12, day)) 22 | { 23 | throw new InvalidOperationException("Too early to get puzzle input."); 24 | } 25 | 26 | var response = await _client.GetAsync($"{year}/day/{day}/input"); 27 | return await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync(); 28 | } 29 | 30 | private static CookieContainer GetCookieContainer() 31 | { 32 | var container = new CookieContainer(); 33 | container.Add(new Cookie 34 | { 35 | Name = "session", 36 | Domain = ".adventofcode.com", 37 | Value = Config.Get().Cookie.Replace("session=", ""), 38 | }); 39 | 40 | return container; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/SolutionBase.cs: -------------------------------------------------------------------------------- 1 | global using System; 2 | global using System.Collections; 3 | global using System.Collections.Generic; 4 | global using System.Linq; 5 | global using System.Text; 6 | global using AdventOfCode.Solutions.Utils; 7 | 8 | using System.Diagnostics; 9 | using System.Net; 10 | 11 | namespace AdventOfCode.Solutions; 12 | 13 | public abstract class SolutionBase 14 | { 15 | public int Day { get; } 16 | public int Year { get; } 17 | public string Title { get; } 18 | public bool Debug { get; set; } 19 | public string Input => LoadInput(Debug); 20 | public string DebugInput => LoadInput(true); 21 | 22 | public SolutionResult Part1 => Solve(1); 23 | public SolutionResult Part2 => Solve(2); 24 | 25 | private protected SolutionBase(int day, int year, string title, bool useDebugInput = false) 26 | { 27 | Day = day; 28 | Year = year; 29 | Title = title; 30 | Debug = useDebugInput; 31 | } 32 | 33 | public IEnumerable SolveAll() 34 | { 35 | yield return Solve(SolvePartOne); 36 | yield return Solve(SolvePartTwo); 37 | } 38 | 39 | public SolutionResult Solve(int part = 1) 40 | { 41 | if (part == 1) return Solve(SolvePartOne); 42 | if (part == 2) return Solve(SolvePartTwo); 43 | 44 | throw new InvalidOperationException("Invalid part param supplied."); 45 | } 46 | 47 | SolutionResult Solve(Func SolverFunction) 48 | { 49 | if (Debug) 50 | { 51 | if (string.IsNullOrEmpty(DebugInput)) 52 | { 53 | throw new Exception("DebugInput is null or empty"); 54 | } 55 | } 56 | else if (string.IsNullOrEmpty(Input)) 57 | { 58 | throw new Exception("Input is null or empty"); 59 | } 60 | 61 | try 62 | { 63 | var then = DateTime.Now; 64 | var result = SolverFunction(); 65 | var now = DateTime.Now; 66 | return string.IsNullOrEmpty(result) 67 | ? SolutionResult.Empty 68 | : new SolutionResult { Answer = result, Time = now - then }; 69 | } 70 | catch (Exception) 71 | { 72 | if (Debugger.IsAttached) 73 | { 74 | Debugger.Break(); 75 | return SolutionResult.Empty; 76 | } 77 | else 78 | { 79 | throw; 80 | } 81 | } 82 | } 83 | 84 | string LoadInput(bool debug = false) 85 | { 86 | var inputFilepath = 87 | $"./AdventOfCode.Solutions/Year{Year}/Day{Day:D2}/{(debug ? "debug" : "input")}"; 88 | 89 | if (File.Exists(inputFilepath) && new FileInfo(inputFilepath).Length > 0) 90 | { 91 | return File.ReadAllText(inputFilepath); 92 | } 93 | 94 | if (debug) return ""; 95 | 96 | try 97 | { 98 | var input = InputService.FetchInput(Year, Day).Result; 99 | File.WriteAllText(inputFilepath, input); 100 | return input; 101 | } 102 | catch (HttpRequestException e) 103 | { 104 | var code = e.StatusCode; 105 | var colour = Console.ForegroundColor; 106 | Console.ForegroundColor = ConsoleColor.DarkRed; 107 | if (code == HttpStatusCode.BadRequest) 108 | { 109 | Console.WriteLine($"Day {Day}: Received 400 when attempting to retrieve puzzle input. Your session cookie is probably not recognized."); 110 | 111 | } 112 | else if (code == HttpStatusCode.NotFound) 113 | { 114 | Console.WriteLine($"Day {Day}: Received 404 when attempting to retrieve puzzle input. The puzzle is probably not available yet."); 115 | } 116 | else 117 | { 118 | Console.ForegroundColor = colour; 119 | Console.WriteLine(e.ToString()); 120 | } 121 | Console.ForegroundColor = colour; 122 | } 123 | catch (InvalidOperationException) 124 | { 125 | var colour = Console.ForegroundColor; 126 | Console.ForegroundColor = ConsoleColor.DarkYellow; 127 | Console.WriteLine($"Day {Day}: Cannot fetch puzzle input before given date (Eastern Standard Time)."); 128 | Console.ForegroundColor = colour; 129 | } 130 | 131 | return ""; 132 | } 133 | 134 | public override string ToString() => 135 | $"\n--- Day {Day}: {Title} --- {(Debug ? "!! Debug mode active, using DebugInput !!" : "")}\n" 136 | + $"{ResultToString(1, Part1)}\n" 137 | + $"{ResultToString(2, Part2)}"; 138 | 139 | string ResultToString(int part, SolutionResult result) => 140 | $" - Part{part} => " + (string.IsNullOrEmpty(result.Answer) 141 | ? "Unsolved" 142 | : $"{result.Answer} ({result.Time.TotalMilliseconds}ms)"); 143 | 144 | protected abstract string SolvePartOne(); 145 | protected abstract string SolvePartTwo(); 146 | } 147 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/SolutionCollector.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions; 2 | 3 | public static class SolutionCollector 4 | { 5 | public static IEnumerable FetchSolutions(int year, IEnumerable days) 6 | { 7 | if (days.Sum() == 0) days = Enumerable.Range(1, 25).ToArray(); 8 | 9 | foreach (int day in days) 10 | { 11 | var type = Type.GetType($"AdventOfCode.Solutions.Year{year}.Day{day:D2}.Solution"); 12 | if (type != null) 13 | { 14 | if (Activator.CreateInstance(type) is SolutionBase solution) 15 | { 16 | yield return solution; 17 | } 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/SolutionResult.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions; 2 | 3 | public struct SolutionResult 4 | { 5 | public string Answer { get; set; } 6 | public TimeSpan Time { get; set; } 7 | 8 | public static SolutionResult Empty => new SolutionResult(); 9 | } 10 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Utils/CalculationUtils.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Utils; 2 | 3 | public static class CalculationUtils 4 | { 5 | public static double FindGCD(double a, double b) 6 | { 7 | if (a == 0 || b == 0) return Math.Max(a, b); 8 | return (a % b == 0) ? b : FindGCD(b, a % b); 9 | } 10 | 11 | public static double FindLCM(double a, double b) => a * b / FindGCD(a, b); 12 | 13 | public static int ManhattanDistance((int x, int y) a, (int x, int y) b) => 14 | Math.Abs(a.x - b.x) + Math.Abs(a.y - b.y); 15 | } 16 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Utils/CollectionUtils.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Utils; 2 | 3 | public static class CollectionUtils 4 | { 5 | public static IEnumerable IntersectAll(this IEnumerable> input) 6 | => input.Aggregate(input.First(), (intersector, next) => intersector.Intersect(next)); 7 | 8 | public static string JoinAsStrings(this IEnumerable items, string delimiter = "") => 9 | string.Join(delimiter, items); 10 | 11 | public static IEnumerable> Permutations(this IEnumerable values) => values.Count() == 1 12 | ? new[] { values } 13 | : values.SelectMany(v => 14 | Permutations(values.Where(x => x?.Equals(v) == false)), (v, p) => p.Prepend(v)); 15 | } 16 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Utils/StringUtils.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Utils; 2 | 3 | public static class StringUtils 4 | { 5 | public static string Reverse(this string str) 6 | { 7 | char[] arr = str.ToCharArray(); 8 | Array.Reverse(arr); 9 | return new string(arr); 10 | } 11 | 12 | public static string[] SplitByNewline(this string str, bool shouldTrim = false) => str 13 | .Split(new[] { "\r", "\n", "\r\n" }, StringSplitOptions.None) 14 | .Where(s => !string.IsNullOrWhiteSpace(s)) 15 | .Select(s => shouldTrim ? s.Trim() : s) 16 | .ToArray(); 17 | 18 | public static string[] SplitByParagraph(this string str, bool shouldTrim = false) => str 19 | .Split(new[] { "\r\r", "\n\n", "\r\n\r\n" }, StringSplitOptions.None) 20 | .Where(s => !string.IsNullOrWhiteSpace(s)) 21 | .Select(s => shouldTrim ? s.Trim() : s) 22 | .ToArray(); 23 | 24 | public static int[] ToIntArray(this string str, string delimiter = "") 25 | { 26 | if (delimiter == "") 27 | { 28 | var result = new List(); 29 | foreach (char c in str) if (int.TryParse(c.ToString(), out int n)) result.Add(n); 30 | return [.. result]; 31 | } 32 | else 33 | { 34 | return str 35 | .Split(delimiter) 36 | .Where(n => int.TryParse(n, out int v)) 37 | .Select(n => Convert.ToInt32(n)) 38 | .ToArray(); 39 | } 40 | } 41 | 42 | public static long[] ToLongArray(this string str, string delimiter = "") 43 | { 44 | if (delimiter == "") 45 | { 46 | var result = new List(); 47 | foreach (char c in str) if (long.TryParse(c.ToString(), out long n)) result.Add(n); 48 | return [.. result]; 49 | } 50 | else 51 | { 52 | return str 53 | .Split(delimiter) 54 | .Where(n => long.TryParse(n, out long v)) 55 | .Select(n => Convert.ToInt64(n)) 56 | .ToArray(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day01/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day01; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(01, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day02/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day02; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(02, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day03/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day03; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(03, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day04/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day04; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(04, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day05/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day05; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(05, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day06/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day06; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(06, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day07/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day07; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(07, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day08/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day08; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(08, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day09/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day09; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(09, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day10/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day10; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(10, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day11/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day11; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(11, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day12/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day12; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(12, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day13/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day13; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(13, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day14/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day14; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(14, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day15/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day15; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(15, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day16/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day16; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(16, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day17/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day17; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(17, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day18/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day18; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(18, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day19/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day19; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(19, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day20/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day20; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(20, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day21/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day21; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(21, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day22/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day22; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(22, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day23/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day23; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(23, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day24/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day24; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(24, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.Solutions/Year2024/Day25/Solution.cs: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year2024.Day25; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(25, 2024, "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AdventOfCode.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /AdventOfCode.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31919.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode", "AdventOfCode.csproj", "{4D64DBD2-6062-4130-B358-CAACE4400BA1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4D64DBD2-6062-4130-B358-CAACE4400BA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {4D64DBD2-6062-4130-B358-CAACE4400BA1}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {4D64DBD2-6062-4130-B358-CAACE4400BA1}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {4D64DBD2-6062-4130-B358-CAACE4400BA1}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {95D6B372-98F9-4C56-A637-D0CF6CCB87E9} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Config.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using System.Text.Json.Serialization; 3 | 4 | struct Config 5 | { 6 | public string Cookie { get; set; } 7 | 8 | public int Year { get; set; } 9 | 10 | [JsonConverter(typeof(DaysConverter))] 11 | public int[] Days { get; set; } 12 | 13 | private void SetDefaults() 14 | { 15 | //Make sure we're looking at EST, or it might break for most of the US 16 | var currentEst = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Utc).AddHours(-5); 17 | if (Cookie == default) Cookie = ""; 18 | if (Year == default) Year = currentEst.Year; 19 | if (Days == default(int[])) Days = (currentEst.Month == 12 && currentEst.Day <= 25) ? [currentEst.Day] : [0]; 20 | } 21 | 22 | public static Config Get(string path = "config.json") 23 | { 24 | var options = new JsonSerializerOptions() 25 | { 26 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, 27 | PropertyNameCaseInsensitive = true, 28 | WriteIndented = true 29 | }; 30 | Config config; 31 | if (File.Exists(path)) 32 | { 33 | config = JsonSerializer.Deserialize(File.ReadAllText(path), options); 34 | config.SetDefaults(); 35 | } 36 | else 37 | { 38 | config = new Config(); 39 | config.SetDefaults(); 40 | File.WriteAllText(path, JsonSerializer.Serialize(config, options)); 41 | } 42 | 43 | return config; 44 | } 45 | } 46 | 47 | class DaysConverter : JsonConverter 48 | { 49 | public override int[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 50 | { 51 | IEnumerable tokens; 52 | 53 | switch (reader.TokenType) 54 | { 55 | case JsonTokenType.Number: 56 | return [reader.GetInt16()]; 57 | 58 | case JsonTokenType.String: 59 | tokens = new string[] { reader.GetString() ?? "" }; 60 | break; 61 | 62 | default: 63 | var obj = JsonSerializer 64 | .Deserialize(ref reader); 65 | 66 | tokens = obj != null 67 | ? obj.Select(o => o.ToString() ?? "") 68 | : Array.Empty(); 69 | break; 70 | } 71 | 72 | var days = tokens.SelectMany(ParseString); 73 | if (days.Contains(0)) return [0]; 74 | 75 | return days.Where(v => v < 26 && v > 0).OrderBy(day => day).ToArray(); 76 | } 77 | 78 | private IEnumerable ParseString(string str) 79 | { 80 | return str.Split(",").SelectMany(str => 81 | { 82 | if (str.Contains("..")) 83 | { 84 | var split = str.Split(".."); 85 | int start = int.Parse(split[0]); 86 | int stop = int.Parse(split[1]); 87 | return Enumerable.Range(start, stop - start + 1); 88 | } 89 | else if (int.TryParse(str, out int day)) 90 | { 91 | return new int[] { day }; 92 | } 93 | 94 | return Array.Empty(); 95 | }); 96 | } 97 | 98 | public override void Write(Utf8JsonWriter writer, int[] value, JsonSerializerOptions options) 99 | { 100 | writer.WriteStartArray(); 101 | foreach (int val in value) writer.WriteNumberValue(val); 102 | writer.WriteEndArray(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /GenerateSolutionFiles.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [int]$Year = (Get-Date).Year 3 | ) 4 | 5 | $template = Get-Content -Raw .\templates\solution.cs.template 6 | 7 | $newDirectory = [IO.Path]::Combine($PSScriptRoot, "AdventOfCode.Solutions", "Year$Year") 8 | 9 | if(!(Test-Path $newDirectory)) { 10 | New-Item $newDirectory -ItemType Directory | Out-Null 11 | } 12 | 13 | for($i = 1; $i -le 25; $i++) { 14 | $newFile = [IO.Path]::Combine($newDirectory, "Day$("{0:00}" -f $i)", "Solution.cs") 15 | if(!(Test-Path $newFile)) { 16 | New-Item $newFile -ItemType File -Value ($template -replace "", $Year -replace "", "$("{0:00}" -f $i)") -Force | Out-Null 17 | } 18 | } 19 | 20 | Write-Host "Files Generated" 21 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 sindrekjr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | define newline 2 | 3 | 4 | endef 5 | 6 | YEAR ?= $(shell date +%Y) 7 | DAYS ?= $(shell seq 1 25) 8 | 9 | TEMPLATE := $(subst ,$(YEAR),$(subst $(newline),\n,$(file < ./templates/solution.cs.template))) 10 | DIRECTORY := "$(shell pwd)/AdventOfCode.Solutions/Year$(YEAR)" 11 | 12 | solutions-files: $(DAYS) 13 | 14 | $(DAYS): 15 | $(eval DAY=$(shell printf "%02d" $@)) 16 | $(eval DAY_DIR="$(DIRECTORY)/Day$(DAY)") 17 | $(eval DAY_FILE="$(DAY_DIR)/Solution.cs") 18 | @if [ ! -f $(DAY_FILE) ]; then \ 19 | mkdir -p $(DAY_DIR); \ 20 | echo '$(subst ,$(DAY),$(TEMPLATE))' > $(DAY_FILE); \ 21 | fi 22 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using AdventOfCode.Solutions; 2 | 3 | var config = Config.Get(); 4 | var year = config.Year; 5 | var days = config.Days; 6 | 7 | if (args.Length > 0 && int.TryParse(args.First(), out int day)) days = [day]; 8 | 9 | foreach (var solution in SolutionCollector.FetchSolutions(year, days)) 10 | { 11 | Console.WriteLine(solution.ToString()); 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AdventOfCodeBase 2 | Template project for solving Advent of Code in C#, running on [.NET 8.0](https://dotnet.microsoft.com/en-us/download/dotnet/8.0). 3 | 4 | - [Features](#features) 5 | - [Usage](#usage) 6 | - [Creating a repository](#creating-a-repository) 7 | - [Configuring](#configuring) 8 | - [Running the project](#running-the-project) 9 | - [Example solution](#example-solution) 10 | - [Notes](#notes) 11 | - [Generating Solution Files](#generating-solution-files) 12 | - [Automatic Debugger Break On Exception](#automatic-debugger-break-on-exception) 13 | - [Background](#background) 14 | - [Contributing](#contributing) 15 | - [License](#license) 16 | 17 | ## Features 18 | * Simple configuration with `config.json`. 19 | * Fetches puzzle input from adventofcode.com and stores it locally. 20 | * Supports easily switching between debug-input and real input. 21 | * Naive benchmarking, showing as millisecond count. 22 | 23 | ## Usage 24 | 25 | ### Creating a repository 26 | To get started using this template, click the green "Use this template" button above (or [this link](https://github.com/sindrekjr/AdventOfCodeBase/generate)) to create a new repository of your own from it. 27 | 28 | If any solution files that you need are not already included, see **[Generating Previous Year's Solution Files](#generating-previous-years-solution-files)**. 29 | 30 | ### Configuring 31 | Create a new file named `config.json` at the root of the project. 32 | ```json 33 | { 34 | "cookie": "c0nt3nt", 35 | "year": 2020, 36 | "days": [0] 37 | } 38 | ``` 39 | 40 | If you run the program without adding this file, one will be created for you without a cookie field. The program will not be able to fetch puzzle inputs from adventofcode.com before a valid cookie is added to the configuration. 41 | 42 | #### `cookie` - Note that `c0nt3nt` must be replaced with a valid cookie value that your browser stores when logging in at adventofcode.com. Instructions on locating your session cookie can be found here: https://github.com/wimglenn/advent-of-code-wim/issues/1 43 | 44 | #### `year` - Specifies which year you wish to output solutions for when running the project. Defaults to the current year if left unspecified. 45 | 46 | #### `days` - Specifies which days you wish to output solutions for when running the project. Defaults to current day if left unspecified and an event is actively running, otherwise defaults to `0`. 47 | 48 | The field supports list comprehension syntax and strings, meaning the following notations are valid. 49 | * `"1..4, 10"` - runs day 1, 2, 3, 4, and 10. 50 | * `[1, 3, "5..9", 15]` - runs day 1, 3, 5, 6, 7, 8, 9, and 15. 51 | * `0` - runs all days 52 | 53 | ### Running the project 54 | Write your advent of code solutions in the appropriate solution classes, `AdventOfCode.Solutions/Year/Day
/Solution.cs`. 55 | 56 | Then run the project. From the command line you can use `dotnet run`, and optionally specify a day inline. For example, to run your solution for day 21: 57 | ``` 58 | dotnet run 21 59 | ``` 60 | 61 | ### Example solution 62 | ```csharp 63 | class Solution : SolutionBase 64 | { 65 | // the constructor calls its base class with (day, year, name) 66 | public Solution() : base(02, 2021, "The Big Bad Sample Santa") 67 | { 68 | // you can use the constructor for preparations shared by both part one and two if you wish 69 | } 70 | 71 | protected override string SolvePartOne() 72 | { 73 | var lines = Input.SplitByNewline(); 74 | return lines.First(); 75 | // this would return the first line of the input as this part's solution 76 | } 77 | 78 | protected override string SolvePartTwo() 79 | { 80 | Debug = true; 81 | // we choose to use the debug input for this part 82 | // note that the debug input cannot be fetched automatically; it has to be copied into the solution folder manually 83 | return ""; 84 | } 85 | } 86 | ``` 87 | 88 | ## Notes 89 | ### Generating Solution Files 90 | 91 | Solution files can be automatically generated via GNU Make or PowerShell, and both methods use the included file `solution.template`, which is customisable. Both options default to current YEAR and all DAYS (1-25). 92 | 93 | #### GNU Make 94 | 95 | ```bash 96 | $ make solution-files [,YEAR] [,DAYS] 97 | ``` 98 | 99 | Requires GNU Make v4 or later. 100 | 101 | #### PowerShell 102 | 103 | ```pwsh 104 | > GenerateSolutionFiles.ps1 [-Year ] 105 | ``` 106 | 107 | Requires PowerShell v3 or later due to the way `$PSScriptRoot` behaves. If you have Windows 8+ you should be set. Upgrades for previous versions, and installs for macOS and Linux can be found in [Microsoft's Powershell Documentation](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.1) 108 | 109 | ### Automatic Debugger Break On Exception 110 | When running your Solutions with a Debugger attached e.g. [VSCode](https://code.visualstudio.com/docs/editor/debugging) or [Visual Studio](https://docs.microsoft.com/en-us/visualstudio/debugger/quickstart-debug-with-managed?view=vs-2019) the BaseSolution base class will try to pause/break the debugger when there is an uncaught Exception thrown by your solution part. This allows for inspection with the debugger without having to specifically set-up additional exception handling within the debugger or your solution. 111 | 112 | ## Background 113 | I intended to use Advent of Code 2019 to learn C#, and found that I wanted to try to put together a small solutions framework of my own. In that way this template came about as an introductory project to C# and .NET Core. 114 | 115 | ## Contributing 116 | If you wish to contribute to this project, simply fork and the clone the repository, make your changes, and submit a pull request. Contributions are quite welcome! 117 | 118 | Please adhere to the [conventional commit format](https://www.conventionalcommits.org/en/v1.0.0/). 119 | 120 | ## License 121 | [MIT](https://github.com/sindrekjr/AdventOfCodeBase/blob/master/LICENSE.md) 122 | -------------------------------------------------------------------------------- /templates/solution.cs.template: -------------------------------------------------------------------------------- 1 | namespace AdventOfCode.Solutions.Year.Day; 2 | 3 | class Solution : SolutionBase 4 | { 5 | public Solution() : base(, , "") { } 6 | 7 | protected override string SolvePartOne() 8 | { 9 | return ""; 10 | } 11 | 12 | protected override string SolvePartTwo() 13 | { 14 | return ""; 15 | } 16 | } 17 | --------------------------------------------------------------------------------