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 PossibleScores; private static void BuildScoreDic() { if (PossibleScores == null) { PossibleScores = new Dictionary { // Rock combos { OpponentRock + " " + PlayPaper, Paper + Win }, // win { OpponentRock + " " + PlayRock, Rock + Draw }, // draw { OpponentRock + " " + PlayScissors, Scissors + Lost }, // lose // Paper { OpponentPaper + " " + PlayScissors, Scissors + Win }, // win { OpponentPaper + " " + PlayPaper, Paper + Draw }, // draw { OpponentPaper + " " + PlayRock, Rock + Lost }, // lose // Scissors { OpponentScissors + " " + PlayRock, Rock + Win }, // win { OpponentScissors + " " + PlayScissors, Scissors + Draw }, // draw { OpponentScissors + " " + PlayPaper, Paper + Lost } // lose }; } } private static void BuildWinDrawLoseTable() { if (PossibleScores == null) { PossibleScores = new Dictionary { // Rock combos { OpponentRock + " " + PlayWin, Paper + Win }, // win { OpponentRock + " " + PlayDraw, Rock + Draw }, // draw { OpponentRock + " " + PlayLose, Scissors + Lost }, // lose // Paper { OpponentPaper + " " + PlayWin, Scissors + Win }, // win { OpponentPaper + " " + PlayDraw, Paper + Draw }, // draw { OpponentPaper + " " + PlayLose, Rock + Lost }, // lose // Scissors { OpponentScissors + " " + PlayWin, Rock + Win }, // win { OpponentScissors + " " + PlayDraw, Scissors + Draw }, // draw { 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(); } } }