Day 2 solution

This is an ugly, kind-of-brute-force solution. I'm not proud of it, but it works and got me top 1000 on both parts.

I also changed the "which day to run if no day is specified" to just always choose the highest numbered day.
This commit is contained in:
2022-12-01 23:14:45 -06:00
parent 483f1f2502
commit ff7633dc12
5 changed files with 2621 additions and 1001 deletions

View File

@ -73,6 +73,8 @@
<EmbeddedResource Include="inputs\24.txt" />
<None Remove="inputs\25.txt" />
<EmbeddedResource Include="inputs\25.txt" />
<None Remove="inputs\02a.txt" />
<EmbeddedResource Include="inputs\02a.txt" />
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

3
inputs/02a.txt Normal file
View File

@ -0,0 +1,3 @@
A Y
B X
C Z

115
src/02.cs Normal file
View File

@ -0,0 +1,115 @@
namespace aoc2022;
internal class Day02 : Day
{
IEnumerable<string>? lines;
internal override void Parse()
{
lines = Util.ReadAllLines("02");
}
internal override string Part1()
{
int score = 0;
foreach (var line in lines!)
{
int roundScore = 0;
switch (line[0])
{
case 'A' when line[2] == 'X':
roundScore += 1;
roundScore += 3;
break;
case 'A' when line[2] == 'Y':
roundScore += 2;
roundScore += 6;
break;
case 'A' when line[2] == 'Z':
roundScore += 3;
roundScore += 0;
break;
case 'B' when line[2] == 'X':
roundScore += 1;
roundScore += 0;
break;
case 'B' when line[2] == 'Y':
roundScore += 2;
roundScore += 3;
break;
case 'B' when line[2] == 'Z':
roundScore += 3;
roundScore += 6;
break;
case 'C' when line[2] == 'X':
roundScore += 1;
roundScore += 6;
break;
case 'C' when line[2] == 'Y':
roundScore += 2;
roundScore += 0;
break;
case 'C' when line[2] == 'Z':
roundScore += 3;
roundScore += 3;
break;
}
score += roundScore;
}
return $"Score: <+white>{score}";
}
internal override string Part2()
{
int score = 0;
foreach (var line in lines!)
{
int roundScore = 0;
switch (line[0])
{
case 'A' when line[2] == 'X':
roundScore += 3;
roundScore += 0;
break;
case 'A' when line[2] == 'Y':
roundScore += 1;
roundScore += 3;
break;
case 'A' when line[2] == 'Z':
roundScore += 2;
roundScore += 6;
break;
case 'B' when line[2] == 'X':
roundScore += 1;
roundScore += 0;
break;
case 'B' when line[2] == 'Y':
roundScore += 2;
roundScore += 3;
break;
case 'B' when line[2] == 'Z':
roundScore += 3;
roundScore += 6;
break;
case 'C' when line[2] == 'X':
roundScore += 2;
roundScore += 0;
break;
case 'C' when line[2] == 'Y':
roundScore += 3;
roundScore += 3;
break;
case 'C' when line[2] == 'Z':
roundScore += 1;
roundScore += 6;
break;
}
score += roundScore;
}
return $"Score: <+white>{score}";
}
}

View File

@ -49,7 +49,7 @@ else
Day? day = null;
if (string.IsNullOrEmpty(desiredDay))
{
day = new Day01();
day = (Day)Activator.CreateInstance(types.Last())!;
}
else
{