feat: solve part 1 and part 2

This commit is contained in:
Stevan Freeborn
2023-12-20 00:21:58 -06:00
parent 92e3e32d0b
commit c20b490454
2 changed files with 509 additions and 82 deletions
+124 -3
View File
@@ -19,6 +19,15 @@ public class PatternTests
result.Should().BeEquivalentTo(expected);
}
[Theory]
[MemberData(nameof(TestData.FindPointOfReflectionWithoutSmudgeTestData), MemberType = typeof(TestData))]
public void FindPointOfReflection_GivenAPatternAndCleanSmudgeIsTrue_ItShouldReturnPointOfReflection(string[] input, PointOfReflection expected)
{
var pattern = Pattern.Parse(input);
var result = pattern.FindPointOfReflection(true);
result.Should().BeEquivalentTo(expected);
}
[Fact]
public void SummarizePatternNotes_GivenExampleInput_ItShouldReturnExpectedValue()
{
@@ -49,14 +58,35 @@ public class PatternTests
.Split(Environment.NewLine + Environment.NewLine)
.Select(p => p.Split(Environment.NewLine));
var result = patterns
var summaries = patterns
.Select(Pattern.Parse)
.Select(p => p.SummarizePatternNotes())
.Sum();
.Select(p => p.SummarizePatternNotes());
var result = summaries.Sum();
result.Should().Be(33728);
}
[Fact]
public void SummarizePatternNotes_GivenInputAndIsPartTwo_ItShouldReturnExpectedValue()
{
var input = File
.ReadAllText("INPUT.txt")
.ReplaceLineEndings();
var patterns = input
.Split(Environment.NewLine + Environment.NewLine)
.Select(p => p.Split(Environment.NewLine));
var summaries = patterns
.Select(Pattern.Parse)
.Select(p => p.SummarizePatternNotes(true));
var result = summaries.Sum();
result.Should().Be(28235);
}
public static class TestData
{
public static IEnumerable<object[]> ParseTestData =>
@@ -89,6 +119,97 @@ public class PatternTests
}
};
public static IEnumerable<object[]> FindPointOfReflectionWithoutSmudgeTestData =>
new List<object[]>
{
new object[]
{
new string[]
{
"#...##..#",
"#....#..#",
"..##..###",
"#####.##.",
"#####.##.",
"..##..###",
"#....#..#",
},
new PointOfReflection
{
Type = ReflectionType.Horizontal,
StartIndex = 0,
EndIndex = 1,
},
},
new object[]
{
new string[]
{
"#.##..##.",
"..#.##.#.",
"##......#",
"##......#",
"..#.##.#.",
"..##..##.",
"#.#.##.#.",
},
new PointOfReflection
{
Type = ReflectionType.Horizontal,
StartIndex = 2,
EndIndex = 3,
}
},
new object[]
{
new string[]
{
"#..#.#........#",
"#..######..####",
".##..#.#.##.#.#",
"#..##..........",
"######........#",
"#..####......##",
".##.##.#...##.#",
},
new PointOfReflection
{
Type = ReflectionType.Vertical,
StartIndex = 9,
EndIndex = 10,
}
},
new object[]
{
new string[]
{
"####.##.....###.#",
"#####.......#..#.",
"#####.......#..#.",
"####..#.....###.#",
"#..####..#.#.##.#",
".##..#..........#",
"######..#.##....#",
"#..####...###...#",
"####..#..###.....",
".......#.##.##...",
"....##.###.##..#.",
"#..##..###...#.#.",
"....#...#.##...##",
".##........##....",
".....#.####..##.#",
"#..#..#..#.#.#..#",
"#######.#.#.#....",
},
new PointOfReflection
{
Type = ReflectionType.Horizontal,
StartIndex = 1,
EndIndex = 2,
},
}
};
public static IEnumerable<object[]> FindPointOfReflectionTestData =>
new List<object[]>
{