Completed Day 02, fixed layout
This commit is contained in:
parent
0a756ab472
commit
bae60144d6
@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<RootNamespace>Day_01</RootNamespace>
|
<RootNamespace>2022</RootNamespace>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -12,6 +12,9 @@
|
|||||||
<None Update="Day 01\day-01-input.txt">
|
<None Update="Day 01\day-01-input.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="Day 02\day-02-input.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32922.545
|
VisualStudioVersion = 17.3.32922.545
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "2022", "Day 01\2022.csproj", "{0547286C-CC14-44D9-8D7B-26BAA3377721}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "2022", "2022.csproj", "{10D21159-084F-4D2B-9254-1BC9D86E60F9}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -11,10 +11,10 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{0547286C-CC14-44D9-8D7B-26BAA3377721}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{10D21159-084F-4D2B-9254-1BC9D86E60F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{0547286C-CC14-44D9-8D7B-26BAA3377721}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{10D21159-084F-4D2B-9254-1BC9D86E60F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{0547286C-CC14-44D9-8D7B-26BAA3377721}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{10D21159-084F-4D2B-9254-1BC9D86E60F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{0547286C-CC14-44D9-8D7B-26BAA3377721}.Release|Any CPU.Build.0 = Release|Any CPU
|
{10D21159-084F-4D2B-9254-1BC9D86E60F9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
using Day_01.Day_01;
|
|
||||||
|
|
||||||
Console.WriteLine($"Max value: {Day01.GetPart2()}");
|
|
||||||
Console.ReadKey(true);
|
|
||||||
79
Day 02/Day02.cs
Normal file
79
Day 02/Day02.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
namespace Day_02.Day_02
|
||||||
|
{
|
||||||
|
internal class Day02
|
||||||
|
{
|
||||||
|
private static string inputPath = "Day 02/day-02-input.txt";
|
||||||
|
|
||||||
|
private static int Win = 6, Draw = 3, Lost = 0, Rock = 1, Paper = 2, Scissors = 3;
|
||||||
|
|
||||||
|
private static string OpponentRock = "A", OpponentPaper = "B", OpponentScissors = "C",
|
||||||
|
PlayRock = "X", PlayPaper = "Y", PlayScissors = "Z",
|
||||||
|
PlayWin = "Z", PlayDraw = "Y", PlayLose = "X";
|
||||||
|
|
||||||
|
private static Dictionary<string, int> PossibleScores;
|
||||||
|
|
||||||
|
private static void BuildScoreDic()
|
||||||
|
{
|
||||||
|
if (PossibleScores == null)
|
||||||
|
{
|
||||||
|
PossibleScores = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
// Rock combos
|
||||||
|
PossibleScores.Add(OpponentRock + " " + PlayPaper, Paper + Win); // win
|
||||||
|
PossibleScores.Add(OpponentRock + " " + PlayRock, Rock + Draw); // draw
|
||||||
|
PossibleScores.Add(OpponentRock + " " + PlayScissors, Scissors + Lost); // lose
|
||||||
|
|
||||||
|
// Paper
|
||||||
|
PossibleScores.Add(OpponentPaper + " " + PlayScissors, Scissors + Win); // win
|
||||||
|
PossibleScores.Add(OpponentPaper + " " + PlayPaper, Paper + Draw); // draw
|
||||||
|
PossibleScores.Add(OpponentPaper + " " + PlayRock, Rock + Lost); // lose
|
||||||
|
|
||||||
|
// Scissors
|
||||||
|
PossibleScores.Add(OpponentScissors + " " + PlayRock, Rock + Win); // win
|
||||||
|
PossibleScores.Add(OpponentScissors + " " + PlayScissors, Scissors + Draw); // draw
|
||||||
|
PossibleScores.Add(OpponentScissors + " " + PlayPaper, Paper + Lost); // lose
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BuildWinDrawLoseTable()
|
||||||
|
{
|
||||||
|
if (PossibleScores == null)
|
||||||
|
{
|
||||||
|
PossibleScores = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
// Rock combos
|
||||||
|
PossibleScores.Add(OpponentRock + " " + PlayWin, Paper + Win); // win
|
||||||
|
PossibleScores.Add(OpponentRock + " " + PlayDraw, Rock + Draw); // draw
|
||||||
|
PossibleScores.Add(OpponentRock + " " + PlayLose, Scissors + Lost); // lose
|
||||||
|
|
||||||
|
// Paper
|
||||||
|
PossibleScores.Add(OpponentPaper + " " + PlayWin, Scissors + Win); // win
|
||||||
|
PossibleScores.Add(OpponentPaper + " " + PlayDraw, Paper + Draw); // draw
|
||||||
|
PossibleScores.Add(OpponentPaper + " " + PlayLose, Rock + Lost); // lose
|
||||||
|
|
||||||
|
// Scissors
|
||||||
|
PossibleScores.Add(OpponentScissors + " " + PlayWin, Rock + Win); // win
|
||||||
|
PossibleScores.Add(OpponentScissors + " " + PlayDraw, Scissors + Draw); // draw
|
||||||
|
PossibleScores.Add(OpponentScissors + " " + PlayLose, Paper + Lost); // lose
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int GetScore(string input) => PossibleScores[input];
|
||||||
|
|
||||||
|
internal static int GetPart1()
|
||||||
|
{
|
||||||
|
BuildScoreDic();
|
||||||
|
return File.ReadAllLines(inputPath)
|
||||||
|
.Select(GetScore)
|
||||||
|
.Sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static int GetPart2()
|
||||||
|
{
|
||||||
|
BuildWinDrawLoseTable();
|
||||||
|
return File.ReadAllLines(inputPath)
|
||||||
|
.Select(GetScore)
|
||||||
|
.Sum();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2500
Day 02/day-02-input.txt
Normal file
2500
Day 02/day-02-input.txt
Normal file
File diff suppressed because it is too large
Load Diff
4
Program.cs
Normal file
4
Program.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
using Day_02.Day_02;
|
||||||
|
|
||||||
|
Console.WriteLine($"Max value: {Day02.GetPart2()}");
|
||||||
|
Console.ReadKey(true);
|
||||||
Loading…
Reference in New Issue
Block a user