docs: add xml comments
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
global using FluentAssertions;
|
global using FluentAssertions;
|
||||||
|
|
||||||
global using Xunit;
|
global using Xunit;
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
global using FluentAssertions;
|
global using FluentAssertions;
|
||||||
|
|
||||||
global using Xunit;
|
global using Xunit;
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
|
global using FluentAssertions;
|
||||||
|
|
||||||
global using Xunit;
|
global using Xunit;
|
||||||
global using FluentAssertions;
|
|
||||||
@@ -36,8 +36,16 @@ public class Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Solves the puzzle.
|
||||||
|
/// </summary>
|
||||||
public class PuzzleSolver
|
public class PuzzleSolver
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sums all part numbers in the schematic.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="schematic">The schematic to parse.</param>
|
||||||
|
/// <returns>The sum of all part numbers.</returns>
|
||||||
public int SumPartNumbers(string[] schematic)
|
public int SumPartNumbers(string[] schematic)
|
||||||
{
|
{
|
||||||
var allPartNumbers = new List<int>();
|
var allPartNumbers = new List<int>();
|
||||||
@@ -54,6 +62,11 @@ public class PuzzleSolver
|
|||||||
return allPartNumbers.Sum();
|
return allPartNumbers.Sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sums all gear ratios in the schematic.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="schematic">The schematic to parse.</param>
|
||||||
|
/// <returns>The sum of all gear ratios.</returns>
|
||||||
public int SumGearRatios(string[] schematic)
|
public int SumGearRatios(string[] schematic)
|
||||||
{
|
{
|
||||||
var allGearRatios = new List<int>();
|
var allGearRatios = new List<int>();
|
||||||
@@ -71,17 +84,40 @@ public class PuzzleSolver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a line in the schematic.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="numbers">The numbers in the line.</param>
|
||||||
|
/// <param name="specialCharacters">The special characters in the line.</param>
|
||||||
|
/// <returns>A line in the schematic.</returns>
|
||||||
public class Line(
|
public class Line(
|
||||||
List<Dictionary<int, Indexes>> numbers,
|
List<Dictionary<int, Indexes>> numbers,
|
||||||
List<Dictionary<string, Indexes>> specialCharacters
|
List<Dictionary<string, Indexes>> specialCharacters
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the numbers in the line.
|
||||||
|
/// </summary>
|
||||||
public List<Dictionary<int, Indexes>> Numbers { get; init; } = numbers;
|
public List<Dictionary<int, Indexes>> Numbers { get; init; } = numbers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the special characters in the line.
|
||||||
|
/// </summary>
|
||||||
public List<Dictionary<string, Indexes>> SpecialCharacters { get; init; } = specialCharacters;
|
public List<Dictionary<string, Indexes>> SpecialCharacters { get; init; } = specialCharacters;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the indexes of all special characters in the line.
|
||||||
|
/// </summary>
|
||||||
public List<int> SpecialCharacterIndexes => SpecialCharacters.SelectMany(dict => dict.Values).Select(v => v.Start).ToList();
|
public List<int> SpecialCharacterIndexes => SpecialCharacters.SelectMany(dict => dict.Values).Select(v => v.Start).ToList();
|
||||||
|
|
||||||
private bool IsGearCharacter(string character) => character == "*";
|
private bool IsGearCharacter(string character) => character == "*";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the gear ratios in the line.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="previousLine">The previous line in the schematic.</param>
|
||||||
|
/// <param name="nextLine">The next line in the schematic.</param>
|
||||||
|
/// <returns>A list of gear ratios.</returns>
|
||||||
public List<int> GetGearRatios(Line? previousLine = null, Line? nextLine = null)
|
public List<int> GetGearRatios(Line? previousLine = null, Line? nextLine = null)
|
||||||
{
|
{
|
||||||
var gearRatios = new List<int>();
|
var gearRatios = new List<int>();
|
||||||
@@ -125,6 +161,12 @@ public class Line(
|
|||||||
return gearRatios;
|
return gearRatios;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the part numbers in the line.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="previousLine">The previous line in the schematic.</param>
|
||||||
|
/// <param name="nextLine">The next line in the schematic.</param>
|
||||||
|
/// <returns>A list of part numbers.</returns>
|
||||||
public List<int> GetPartNumbers(Line? previousLine = null, Line? nextLine = null)
|
public List<int> GetPartNumbers(Line? previousLine = null, Line? nextLine = null)
|
||||||
{
|
{
|
||||||
var partNumbers = new List<int>();
|
var partNumbers = new List<int>();
|
||||||
@@ -156,6 +198,11 @@ public class Line(
|
|||||||
return partNumbers;
|
return partNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses a line in the schematic.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="line">The line to parse.</param>
|
||||||
|
/// <returns>An instance of <see cref="Line"/>.</returns>
|
||||||
public static Line Parse(string line)
|
public static Line Parse(string line)
|
||||||
{
|
{
|
||||||
var numbers = new List<Dictionary<int, Indexes>>();
|
var numbers = new List<Dictionary<int, Indexes>>();
|
||||||
@@ -221,8 +268,18 @@ public class Line(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the start and end indexes of a number or special character.
|
||||||
|
/// </summary>
|
||||||
public class Indexes(int start, int end)
|
public class Indexes(int start, int end)
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the start index. The start index is the position of the first character in the number or special character.
|
||||||
|
/// </summary>
|
||||||
public int Start { get; init; } = start;
|
public int Start { get; init; } = start;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the end index. The end index is the position of the last character in the number or special character.
|
||||||
|
/// </summary>
|
||||||
public int End { get; init; } = end;
|
public int End { get; init; } = end;
|
||||||
}
|
}
|
||||||
+6
-1
@@ -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.
|
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
|
```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 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.
|
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.
|
||||||
|
|||||||
@@ -27,13 +27,19 @@ To run the solutions, navigate to the solution folder and run the following comm
|
|||||||
dotnet run -- <path-to-input-file>
|
dotnet run -- <path-to-input-file>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or for part 2 solutions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dotnet run -- <path-to-input-file> part2
|
||||||
|
```
|
||||||
|
|
||||||
## Challenges
|
## Challenges
|
||||||
|
|
||||||
| Day | Problem | Solution | Status | Notes |
|
| Day | Problem | Solution | Status | Notes |
|
||||||
| --- | -------------------------- | :-----------------------------: | :----: | ------------------------------------------------------------------- |
|
| --- | -------------------------- | :-----------------------------: | :----: | ------------------------------------------------------------------- |
|
||||||
| 01 | [Problem](./01/PROBLEM.md) | [Solution](./01/Trebuchet/) | ✅ | The trickiest part here was accounting for overlapping digit words. |
|
| 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. |
|
| 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/) | ⌛ |
|
| 04 | [Problem](./04/PROBLEM.md) | [Solution](./04/) | ⌛ |
|
||||||
| 05 | [Problem](./05/PROBLEM.md) | [Solution](./05/) | ⌛ |
|
| 05 | [Problem](./05/PROBLEM.md) | [Solution](./05/) | ⌛ |
|
||||||
| 06 | [Problem](./06/PROBLEM.md) | [Solution](./06/) | ⌛ |
|
| 06 | [Problem](./06/PROBLEM.md) | [Solution](./06/) | ⌛ |
|
||||||
|
|||||||
Reference in New Issue
Block a user