2023-06-07 22:13:21 +00:00
|
|
|
namespace AdventOfCode.Year2022;
|
|
|
|
|
|
|
|
public class Day2
|
|
|
|
{
|
2023-06-07 23:12:01 +00:00
|
|
|
private static readonly List<string[]> Matches = LoadMatches();
|
2023-06-07 22:13:21 +00:00
|
|
|
|
|
|
|
public Day2()
|
|
|
|
{
|
2023-06-07 22:59:16 +00:00
|
|
|
Console.WriteLine("Day2 Solution");
|
|
|
|
Console.WriteLine($"Part1 Result: {Part1()}");
|
|
|
|
Console.WriteLine($"Part2 Result: {Part2()}");
|
|
|
|
Console.WriteLine("\n=============================\n");
|
2023-06-07 22:13:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static int Part1()
|
|
|
|
{
|
|
|
|
int score = 0;
|
2023-06-07 23:12:01 +00:00
|
|
|
foreach (string[] match in Matches)
|
2023-06-07 22:13:21 +00:00
|
|
|
{
|
|
|
|
if (match[0] == "A")
|
|
|
|
{
|
|
|
|
if (match[1] == "X")
|
|
|
|
score += 1 + 3;
|
|
|
|
if (match[1] == "Y")
|
|
|
|
score += 2 + 6;
|
|
|
|
if (match[1] == "Z")
|
|
|
|
score += 3;
|
|
|
|
}
|
|
|
|
if (match[0] == "B")
|
|
|
|
{
|
|
|
|
if (match[1] == "X")
|
|
|
|
score += 1;
|
|
|
|
if (match[1] == "Y")
|
|
|
|
score += 2 + 3;
|
|
|
|
if (match[1] == "Z")
|
|
|
|
score += 3 + 6;
|
|
|
|
}
|
|
|
|
if (match[0] == "C")
|
|
|
|
{
|
|
|
|
if (match[1] == "X")
|
|
|
|
score += 1 + 6;
|
|
|
|
if (match[1] == "Y")
|
|
|
|
score += 2;
|
|
|
|
if (match[1] == "Z")
|
|
|
|
score += 3 + 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int Part2()
|
|
|
|
{
|
|
|
|
int score = 0;
|
2023-06-07 23:12:01 +00:00
|
|
|
foreach (string[] match in Matches)
|
2023-06-07 22:13:21 +00:00
|
|
|
{
|
|
|
|
if (match[0] == "A")
|
|
|
|
{
|
|
|
|
if (match[1] == "X")
|
|
|
|
score += 3;
|
|
|
|
if (match[1] == "Y")
|
|
|
|
score += 1 + 3;
|
|
|
|
if (match[1] == "Z")
|
|
|
|
score += 2 + 6;
|
|
|
|
}
|
|
|
|
if (match[0] == "B")
|
|
|
|
{
|
|
|
|
if (match[1] == "X")
|
|
|
|
score += 1;
|
|
|
|
if (match[1] == "Y")
|
|
|
|
score += 2 + 3;
|
|
|
|
if (match[1] == "Z")
|
|
|
|
score += 3 + 6;
|
|
|
|
}
|
|
|
|
if (match[0] == "C")
|
|
|
|
{
|
|
|
|
if (match[1] == "X")
|
|
|
|
score += 2;
|
|
|
|
if (match[1] == "Y")
|
|
|
|
score += 3 + 3;
|
|
|
|
if (match[1] == "Z")
|
|
|
|
score += 1 + 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
2023-06-07 23:12:01 +00:00
|
|
|
private static List<string[]> LoadMatches()
|
2023-06-07 22:13:21 +00:00
|
|
|
{
|
2023-06-07 23:12:01 +00:00
|
|
|
List<string[]> matches = new List<string[]>();
|
2023-06-07 22:13:21 +00:00
|
|
|
foreach (string line in File.ReadAllLines("inputs/day2.txt"))
|
2023-06-07 23:12:01 +00:00
|
|
|
matches.Add(line.Split(" "));
|
|
|
|
return matches;
|
2023-06-07 22:13:21 +00:00
|
|
|
}
|
|
|
|
}
|