From 660e2ff75b97a18cadebb2d0eb866cb7f90a732c Mon Sep 17 00:00:00 2001 From: deckelmouck Date: Thu, 30 Nov 2023 11:46:17 +0000 Subject: [PATCH] solve day 2 part 1 --- 2022/Day02/solution.cs | 66 +++++++++++++++++++++++++++++++++++++++++- 2022/Day02/test | 3 ++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 2022/Day02/test diff --git a/2022/Day02/solution.cs b/2022/Day02/solution.cs index 80a5db7..36a608e 100644 --- a/2022/Day02/solution.cs +++ b/2022/Day02/solution.cs @@ -10,10 +10,74 @@ public class solutionDay02 : ISolver public void SolvePart1() { Console.WriteLine("to implement"); + solutionBase sb = new(); + var input = sb.getInputLines(@"2022/Day02/input"); + //var input = sb.getInputLines(@"2022/Day02/test"); + + var totalScore = 0; + + foreach (var item in input) + { + Console.WriteLine(item); + var temp = RockPaperScissors(item); + Console.WriteLine(temp); + + totalScore += temp; + Console.WriteLine(totalScore); + Console.WriteLine("-------------"); + } + + //a rock, b paper, c scissors //x rock, y paper, z scissors + //rock = 1, paper = 2, scissors = 3 + //lost = 0, draw = 3, win = 6 + + Console.WriteLine($"totalScore: {totalScore}"); + + } public void SolvePart2() { - Console.WriteLine("to implement"); + //Console.WriteLine("to implement"); + } + + int RockPaperScissors(string game) + { + int score = 0; + switch (game) + { + case "A X": + score = 1 + 3; + break; + case "B X": + score = 1; + break; + case "C X": + score = 1 + 6; + break; + + case "A Y": + score = 2 + 6; + break; + case "B Y": + score = 2 + 3; + break; + case "C Y": + score = 2; + break; + + case "A Z": + score = 3; + break; + case "B Z": + score = 3 + 6; + break; + case "C Z": + score = 3 + 3; + break; + default: + break; + } + return score; } } diff --git a/2022/Day02/test b/2022/Day02/test new file mode 100644 index 0000000..25097e8 --- /dev/null +++ b/2022/Day02/test @@ -0,0 +1,3 @@ +A Y +B X +C Z \ No newline at end of file