Untitled
unknown
plain_text
2 years ago
3.3 kB
8
Indexable
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Day2 { internal class Program { //a rock1 b paper2 C scippsor3 public static List<string> Input => File.ReadAllLines(@"input.txt").ToList(); static void Main(string[] args) { var scorePart1 = 0; var scorePart2 = 0; foreach (var item in Input) { var opponent = item[0].ToString(); var you = item[2].ToString(); scorePart1 += GetScorePart1(opponent, you); scorePart2 += GetScorePart2(opponent, you); } Console.WriteLine(scorePart1); Console.WriteLine(scorePart2); Console.ReadLine(); } public static int GetScorePart2(string opponent, string you) { //Lose if (you == "X") { if (opponent == "A") { return 3; } else if (opponent == "B") { return 1; } else { return 2; } } //Draw else if (you == "Y") { if (opponent == "A") { return 4; } else if (opponent == "B") { return 5; } else { return 6; } } //Win else { if (opponent == "A") { return 8; } else if (opponent == "B") { return 9; } else { return 7; }; } } public static int GetScorePart1(string opponent, string you) { //Draw if (opponent == "A" && you == "X" || opponent == "B" && you == "Y" || opponent == "C" && you == "Z") { if (you == "X") { return 4; } else if (you == "Y") { return 5; } else { return 6; } } //Win if (you == "X" && opponent == "C") { return 7; } else if (you == "Y" && opponent == "A") { return 8; } else if (you == "Z" && opponent == "B") { return 9; } //Lose if(you == "X") { return 1; } else if(you == "Y") { return 2; } else { return 3; } } } }
Editor is loading...