From 9a29e0f5c61e8840fa7f7c72d90e1db4ed88a454 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 3 Dec 2023 23:03:46 -0600 Subject: [PATCH] docs: add xml comments --- 01/Trebuchet.Tests/GlobalUsings.cs | 2 +- 02/CubeConundrum.Tests/GlobalUsings.cs | 2 +- 03/GearRatios.Tests/GlobalUsings.cs | 3 +- 03/GearRatios/Program.cs | 57 ++++++++++++++++++++++++++ 03/SCRATCH.md | 7 +++- README.md | 8 +++- 6 files changed, 74 insertions(+), 5 deletions(-) diff --git a/01/Trebuchet.Tests/GlobalUsings.cs b/01/Trebuchet.Tests/GlobalUsings.cs index 2d5b473..d6f0167 100644 --- a/01/Trebuchet.Tests/GlobalUsings.cs +++ b/01/Trebuchet.Tests/GlobalUsings.cs @@ -1,3 +1,3 @@ global using FluentAssertions; -global using Xunit; +global using Xunit; \ No newline at end of file diff --git a/02/CubeConundrum.Tests/GlobalUsings.cs b/02/CubeConundrum.Tests/GlobalUsings.cs index 2d5b473..d6f0167 100644 --- a/02/CubeConundrum.Tests/GlobalUsings.cs +++ b/02/CubeConundrum.Tests/GlobalUsings.cs @@ -1,3 +1,3 @@ global using FluentAssertions; -global using Xunit; +global using Xunit; \ No newline at end of file diff --git a/03/GearRatios.Tests/GlobalUsings.cs b/03/GearRatios.Tests/GlobalUsings.cs index 7fef4b0..2d5b473 100644 --- a/03/GearRatios.Tests/GlobalUsings.cs +++ b/03/GearRatios.Tests/GlobalUsings.cs @@ -1,2 +1,3 @@ +global using FluentAssertions; + global using Xunit; -global using FluentAssertions; \ No newline at end of file diff --git a/03/GearRatios/Program.cs b/03/GearRatios/Program.cs index 5596c24..baaa1d6 100644 --- a/03/GearRatios/Program.cs +++ b/03/GearRatios/Program.cs @@ -36,8 +36,16 @@ public class Program } } +/// +/// Solves the puzzle. +/// public class PuzzleSolver { + /// + /// Sums all part numbers in the schematic. + /// + /// The schematic to parse. + /// The sum of all part numbers. public int SumPartNumbers(string[] schematic) { var allPartNumbers = new List(); @@ -54,6 +62,11 @@ public class PuzzleSolver return allPartNumbers.Sum(); } + /// + /// Sums all gear ratios in the schematic. + /// + /// The schematic to parse. + /// The sum of all gear ratios. public int SumGearRatios(string[] schematic) { var allGearRatios = new List(); @@ -71,17 +84,40 @@ public class PuzzleSolver } } +/// +/// Represents a line in the schematic. +/// +/// The numbers in the line. +/// The special characters in the line. +/// A line in the schematic. public class Line( List> numbers, List> specialCharacters ) { + /// + /// Gets the numbers in the line. + /// public List> Numbers { get; init; } = numbers; + + /// + /// Gets the special characters in the line. + /// public List> SpecialCharacters { get; init; } = specialCharacters; + + /// + /// Gets the indexes of all special characters in the line. + /// public List SpecialCharacterIndexes => SpecialCharacters.SelectMany(dict => dict.Values).Select(v => v.Start).ToList(); private bool IsGearCharacter(string character) => character == "*"; + /// + /// Gets the gear ratios in the line. + /// + /// The previous line in the schematic. + /// The next line in the schematic. + /// A list of gear ratios. public List GetGearRatios(Line? previousLine = null, Line? nextLine = null) { var gearRatios = new List(); @@ -125,6 +161,12 @@ public class Line( return gearRatios; } + /// + /// Gets the part numbers in the line. + /// + /// The previous line in the schematic. + /// The next line in the schematic. + /// A list of part numbers. public List GetPartNumbers(Line? previousLine = null, Line? nextLine = null) { var partNumbers = new List(); @@ -156,6 +198,11 @@ public class Line( return partNumbers; } + /// + /// Parses a line in the schematic. + /// + /// The line to parse. + /// An instance of . public static Line Parse(string line) { var numbers = new List>(); @@ -221,8 +268,18 @@ public class Line( } } +/// +/// Represents the start and end indexes of a number or special character. +/// public class Indexes(int start, int end) { + /// + /// Gets the start index. The start index is the position of the first character in the number or special character. + /// public int Start { get; init; } = start; + + /// + /// Gets the end index. The end index is the position of the last character in the number or special character. + /// public int End { get; init; } = end; } \ No newline at end of file diff --git a/03/SCRATCH.md b/03/SCRATCH.md index 0c65a13..664a93f 100644 --- a/03/SCRATCH.md +++ b/03/SCRATCH.md @@ -82,9 +82,14 @@ public class Indexes Then you see if those numbers are part numbers just by checking if a special character proceeds or follows their start and end indexes. ```csharp + ``` If not then you need to see if there is a previous line and whether there is a special character at on the previous line that has an index that is between 1 less than the start index and 1 more than the end index. If not then you need to see if there is a next line and whether there is a special character at on the next line that has an index that is between 1 less than the start index and 1 more than the end index. -``` + +Basic approach: + +- Parse the current, previous, and next lines into a model that keeps track of the numbers and special characters and their indexes for that line. +- Then each line should be able to evaluate what is a part number or not. Or what is a gear or not given its previous and next lines. diff --git a/README.md b/README.md index 81e4ddb..f44df71 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,19 @@ To run the solutions, navigate to the solution folder and run the following comm dotnet run -- ``` +Or for part 2 solutions + +```bash +dotnet run -- part2 +``` + ## Challenges | Day | Problem | Solution | Status | Notes | | --- | -------------------------- | :-----------------------------: | :----: | ------------------------------------------------------------------- | | 01 | [Problem](./01/PROBLEM.md) | [Solution](./01/Trebuchet/) | ✅ | The trickiest part here was accounting for overlapping digit words. | | 02 | [Problem](./02/PROBLEM.md) | [Solution](./02/CubeConundrum/) | ✅ | The key to me here was to parse the input into a useful model. | -| 03 | [Problem](./03/PROBLEM.md) | [Solution](./03/GearRatios/) | ⌛ | +| 03 | [Problem](./03/PROBLEM.md) | [Solution](./03/GearRatios/) | ✅ | The edge case that got me here was lines ending with a part number. | | 04 | [Problem](./04/PROBLEM.md) | [Solution](./04/) | ⌛ | | 05 | [Problem](./05/PROBLEM.md) | [Solution](./05/) | ⌛ | | 06 | [Problem](./06/PROBLEM.md) | [Solution](./06/) | ⌛ |