-
Notifications
You must be signed in to change notification settings - Fork 0
/
2017_09.cs
56 lines (51 loc) · 1.26 KB
/
2017_09.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
namespace AOC.CSharp;
public static class AOC2017_09
{
public static long Solve1(string[] lines)
{
(long score, _) = Solve(lines);
return score;
}
public static long Solve2(string[] lines)
{
(_, long nonCanceled) = Solve(lines);
return nonCanceled;
}
private static (long, long) Solve(string[] lines)
{
long score = 0;
long currScore = 0;
long nonCanceled = 0;
List<char> chars = lines[0].ToList();
for (int i = 0; i < chars.Count; i++)
{
char ch = chars[i];
if (ch == '{')
{
currScore++;
}
else if (ch == '}')
{
score += currScore;
currScore--;
}
else if (ch == '<')
{
i++;
while (chars[i] != '>')
{
if (chars[i] != '>' && chars[i] != '!')
{
nonCanceled++;
}
if (chars[i] == '!')
{
i++;
}
i++;
}
}
}
return (score, nonCanceled);
}
}