mirror of
https://github.com/parnic/advent-of-code-2022.git
synced 2025-06-16 13:40:13 -05:00
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:
@ -73,6 +73,8 @@
|
|||||||
<EmbeddedResource Include="inputs\24.txt" />
|
<EmbeddedResource Include="inputs\24.txt" />
|
||||||
<None Remove="inputs\25.txt" />
|
<None Remove="inputs\25.txt" />
|
||||||
<EmbeddedResource Include="inputs\25.txt" />
|
<EmbeddedResource Include="inputs\25.txt" />
|
||||||
|
<None Remove="inputs\02a.txt" />
|
||||||
|
<EmbeddedResource Include="inputs\02a.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
3500
inputs/02.txt
3500
inputs/02.txt
File diff suppressed because it is too large
Load Diff
3
inputs/02a.txt
Normal file
3
inputs/02a.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
A Y
|
||||||
|
B X
|
||||||
|
C Z
|
115
src/02.cs
Normal file
115
src/02.cs
Normal 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}";
|
||||||
|
}
|
||||||
|
}
|
@ -49,7 +49,7 @@ else
|
|||||||
Day? day = null;
|
Day? day = null;
|
||||||
if (string.IsNullOrEmpty(desiredDay))
|
if (string.IsNullOrEmpty(desiredDay))
|
||||||
{
|
{
|
||||||
day = new Day01();
|
day = (Day)Activator.CreateInstance(types.Last())!;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user