Untitled
unknown
plain_text
3 years ago
2.4 kB
18
Indexable
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\chris\source\repos\advent1\advent1\TextFile2.txt");
int total = 0;
//part1
static int calculateScore(char opp, char you)
{
var convOpp = convertOpponent(opp);
var score = 0;
score += checkSymbol(you);
score += checkWin(convOpp, you);
if (convOpp == you) { score += 3; }
return score;
}
static char convertOpponent(char opp)
{
if (opp == 'A')
{
return 'X';
}
if (opp == 'B')
{
return 'Y';
}
return 'Z';
}
static int checkWin(char opp, char you)
{
if (opp == 'X' && you == 'Y' || opp == 'Y' && you == 'Z' || opp == 'Z' && you == 'X')
{
return 6;
}
return 0;
}
static int checkSymbol(char input)
{
if (input == 'X')
{
return 1;
}
if (input == 'Y')
{
return 2;
}
return 3;
}
//part 2
static string checkNeededResult(char you)
{
if (you == 'X')
{
return "loss";
}
if(you == 'Y')
{
return "draw";
}
return "win";
}
static int makeDraw(char opp)
{
return 3 + checkSymbol(opp);
}
static int makeLoss(char opp)
{
if (opp == 'X')
{
return 3;
}
if (opp == 'Y')
{
return 1;
}
return 2;
}
static int makeWin(char opp)
{
if (opp == 'X')
{
return 8;
}
if (opp == 'Y')
{
return 9;
}
return 7;
}
foreach (var line in lines)
{
char opp = Convert.ToChar(line.Substring(0, 1));
char you = Convert.ToChar(line.Substring(2, 1));
var convOpp = convertOpponent(opp);
var resultNeeded = checkNeededResult(you);
Console.WriteLine("should be " + resultNeeded + "input" + opp + you);
if (resultNeeded == "draw")
{
Console.WriteLine("draw" + " " + makeDraw(convOpp) + " " + convOpp + " " + you);
total += makeDraw(convOpp);
}
if (resultNeeded == "loss")
{
Console.WriteLine("loss" + " " + makeLoss(convOpp) + " " + convOpp + " " + you);
total += makeLoss(convOpp);
}
if (resultNeeded == "win")
{
Console.WriteLine("win" +" " + makeWin(convOpp) +" "+ convOpp + " " + you);
total += makeWin(convOpp);
}
//total += calculateScore(opp, you);
}
Console.WriteLine(total);
Editor is loading...