[2022] Day2 added

This commit is contained in:
Tiago Garcia 2023-06-07 23:13:21 +01:00
parent 3bc1c6ca17
commit 41d4667ca8
No known key found for this signature in database
GPG Key ID: F423E37A2415E160
2 changed files with 96 additions and 0 deletions

View File

@ -7,6 +7,7 @@ class Program
public static void Main(string[] args)
{
new Day1();
new Day2();
new Day3();
new Day7();
}

View File

@ -0,0 +1,95 @@
namespace AdventOfCode.Year2022;
public class Day2
{
private static List<string[]> matches = new();
public Day2()
{
Console.WriteLine("Day2 Solution\n");
LoadMatches();
Console.WriteLine($"Part1\nResult: {Part1()}\n");
Console.WriteLine($"Part2\nResult: {Part2()}\n");
Console.WriteLine("=============================\n");
}
private static int Part1()
{
int score = 0;
foreach (string[] match in matches)
{
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;
foreach (string[] match in matches)
{
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;
}
private static void LoadMatches()
{
foreach (string line in File.ReadAllLines("inputs/day2.txt"))
matches.Add(line.Split(" "));
}
}