-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay2.cs
133 lines (130 loc) · 4.04 KB
/
Day2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
namespace advent_of_code_2022;
public class Day2
{
public static void Part1(string[] args)
{
string[] lines = File.ReadAllLines("day2-input.txt");
int total = 0;
foreach (var line in lines)
{
char opponent = line[0];
char my = line[2];
if (opponent == 'A') // Rock
{
if (my == 'X') // Rock
{
total += 1;
total += 3; // draw
} else if (my == 'Y') // Paper
{
total += 2;
total += 6;
} else if (my == 'Z') // Scissors
{
total += 3;
total += 0;
}
} else if (opponent == 'B') // Paper
{
if (my == 'X') // Rock
{
total += 1;
total += 0;
} else if (my == 'Y') // Paper
{
total += 2;
total += 3; // draw
} else if (my == 'Z') // Scissors
{
total += 3;
total += 6;
}
} else if (opponent == 'C') // Scissors
{
if (my == 'X') // Rock
{
total += 1;
total += 6;
} else if (my == 'Y') // Paper
{
total += 2;
total += 0;
} else if (my == 'Z') // Scissors
{
total += 3;
total += 3; // draw
}
}
}
Console.WriteLine(total);
}
public static void Solve(string[] args)
{
string[] lines = File.ReadAllLines("day2-input.txt");
int total = 0;
// Rock defeats Scissors, Scissors defeats Paper, and Paper defeats Rock
// 1 for Rock, 2 for Paper, and 3 for Scissors
// 0 if you lost, 3 if the round was a draw, and 6 if you won
foreach (var line in lines)
{
char opponent = line[0];
char my = line[2];
if (opponent == 'A') // Rock
{
if (my == 'X') // you need to lose
{
// my Scissors
total += 3;
total += 0;
} else if (my == 'Y') // you need to end the round in a draw
{
// my Rock
total += 1;
total += 3;
} else if (my == 'Z') // you need to win
{
// my Paper
total += 2;
total += 6;
}
} else if (opponent == 'B') // Paper
{
if (my == 'X') // you need to lose
{
// my Rock
total += 1;
total += 0;
} else if (my == 'Y') // you need to end the round in a draw
{
// my Paper
total += 2;
total += 3;
} else if (my == 'Z') // you need to win
{
// my Scissors
total += 3;
total += 6;
}
} else if (opponent == 'C') // Scissors
{
if (my == 'X') // you need to lose
{
// my Paper
total += 2;
total += 0;
} else if (my == 'Y') // you need to end the round in a draw
{
// my Scissors
total += 3;
total += 3;
} else if (my == 'Z') // you need to win
{
// my Rock
total += 1;
total += 6;
}
}
}
Console.WriteLine(total);
}
}