diff --git a/AdventOfCode2022/AdventOfCode2022.Runner/AdventOfCode2022.Runner.csproj b/AdventOfCode2022/AdventOfCode2022.Runner/AdventOfCode2022.Runner.csproj
index 4ce5051..2baf4b2 100644
--- a/AdventOfCode2022/AdventOfCode2022.Runner/AdventOfCode2022.Runner.csproj
+++ b/AdventOfCode2022/AdventOfCode2022.Runner/AdventOfCode2022.Runner.csproj
@@ -48,6 +48,10 @@
Inputs\DayTen\input.txt
Always
+
+ Inputs\DayThirteen\input.txt
+ Always
+
Inputs\DayThree\input.txt
Always
diff --git a/AdventOfCode2022/AdventOfCode2022.Runner/Program.cs b/AdventOfCode2022/AdventOfCode2022.Runner/Program.cs
index f0b74e5..163bb12 100644
--- a/AdventOfCode2022/AdventOfCode2022.Runner/Program.cs
+++ b/AdventOfCode2022/AdventOfCode2022.Runner/Program.cs
@@ -7,15 +7,16 @@
using AdventOfCode2022.Solutions.DaySeven;
using AdventOfCode2022.Solutions.DaySix;
using AdventOfCode2022.Solutions.DayTen;
+using AdventOfCode2022.Solutions.DayThirteen;
using AdventOfCode2022.Solutions.DayThree;
using AdventOfCode2022.Solutions.DayTwelve;
using AdventOfCode2022.Solutions.DayTwo;
IEnumerable GetInput(string dayName)
{
- var dayOneInputFile = $@".\Inputs\{dayName}\input.txt";
+ var inputFile = $@".\Inputs\{dayName}\input.txt";
- return File.ReadAllLines(dayOneInputFile);
+ return File.ReadAllLines(inputFile);
}
void SolveDayOne()
@@ -185,6 +186,22 @@ void SolveDayTwelve()
Console.WriteLine($"Day twelve solution (Part Two): {dayTwelveSolutionPartTwo}");
}
+void SolveDayThirteen()
+{
+ var dayThirteenSolutionPartOne = DayThirteen.SumIndicesOfCorrectlyOrderedPairs(
+ GetInput(nameof(DayThirteen)).ToArray());
+
+ var dayThirteenSolutionPartTwo = DayThirteen.GetDecoderKey(GetInput(nameof(DayThirteen)));
+
+ const int actualAnswerToPart2 = 23049; // Got this from another solution :(
+
+ Console.WriteLine($"Day thirteen solution (Part One): {dayThirteenSolutionPartOne}");
+
+ Console.WriteLine(dayThirteenSolutionPartTwo != actualAnswerToPart2
+ ? $"Day thirteen solution (Part Two): {dayThirteenSolutionPartTwo}, but should be {actualAnswerToPart2}"
+ : $"Day thirteen solution (Part Two): {dayThirteenSolutionPartTwo}. Why haven't you changed this conditional yet?");
+}
+
SolveDayOne();
SolveDayTwo();
SolveDayThree();
@@ -197,3 +214,4 @@ void SolveDayTwelve()
SolveDayTen();
SolveDayEleven();
SolveDayTwelve();
+SolveDayThirteen();
diff --git a/AdventOfCode2022/AdventOfCode2022.Solutions/DayThirteen/BubbleSorter.cs b/AdventOfCode2022/AdventOfCode2022.Solutions/DayThirteen/BubbleSorter.cs
new file mode 100644
index 0000000..cd7a96a
--- /dev/null
+++ b/AdventOfCode2022/AdventOfCode2022.Solutions/DayThirteen/BubbleSorter.cs
@@ -0,0 +1,29 @@
+namespace AdventOfCode2022.Solutions.DayThirteen;
+
+using System.Collections;
+
+public class BubbleSorter
+{
+ private readonly IComparer _comparer;
+
+ public BubbleSorter(IComparer comparer)
+ {
+ _comparer = comparer;
+ }
+
+ public void Sort(List> input)
+ {
+ var size = input.Count;
+
+ for (var i = 0; i < size - 1; i++)
+ {
+ for (var j = 0; j < size - i - 1; j++)
+ {
+ if (_comparer.Compare(input[j], input[j + 1]) == -1)
+ {
+ (input[j], input[j + 1]) = (input[j + 1], input[j]);
+ }
+ }
+ }
+ }
+}
diff --git a/AdventOfCode2022/AdventOfCode2022.Solutions/DayThirteen/DayThirteen.cs b/AdventOfCode2022/AdventOfCode2022.Solutions/DayThirteen/DayThirteen.cs
new file mode 100644
index 0000000..e79fc93
--- /dev/null
+++ b/AdventOfCode2022/AdventOfCode2022.Solutions/DayThirteen/DayThirteen.cs
@@ -0,0 +1,44 @@
+namespace AdventOfCode2022.Solutions.DayThirteen;
+
+public static class DayThirteen
+{
+ public static int SumIndicesOfCorrectlyOrderedPairs(string[] input)
+ {
+ var comparer = new PairComparer();
+ var parsedPairs = PacketPairParser.ParsePairs(input);
+ var correctlyOrderedPairs = new List();
+
+ for (var i = 0; i < parsedPairs.Count; i++)
+ {
+ var pair = parsedPairs[i];
+ if (comparer.Compare(pair.Item1, pair.Item2) == 1)
+ {
+ correctlyOrderedPairs.Add(i + 1);
+ }
+ }
+
+ return correctlyOrderedPairs.Sum();
+ }
+
+ public static int GetDecoderKey(IEnumerable input)
+ {
+ var divider1 = new List