-
Notifications
You must be signed in to change notification settings - Fork 0
/
23.linq
56 lines (53 loc) · 1.72 KB
/
23.linq
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
<Query Kind="Program" />
void Main()
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Util.CurrentQueryPath));
var inputLines = File.ReadAllLines("23.txt");
int a = 1;
int b = 0;
int idx = 0;
while (true)
{
if (idx < 0 || idx >= inputLines.Length)
{
b.Dump();
return;
}
else
{
string line = inputLines[idx];
string instruction = line.Substring(0, 3);
switch (instruction)
{
case "hlf":
if (line[4] == 'a') a = a / 2;
else b = b / 2;
idx++;
break;
case "tpl":
if (line[4] == 'a') a = a * 3;
else b = b * 3;
idx++;
break;
case "inc":
if (line[4] == 'a') a++;
else b++;
idx++;
break;
case "jmp":
idx += int.Parse(line.Substring(4));
break;
case "jie":
if (line[4] == 'a' && a % 2 == 0) idx += int.Parse(line.Substring(7));
else if (line[4] == 'b' && b % 2 == 0) idx += int.Parse(line.Substring(7));
else idx++;
break;
case "jio":
if (line[4] == 'a' && a == 1) idx += int.Parse(line.Substring(7));
else if (line[4] == 'b' && b == 1) idx += int.Parse(line.Substring(7));
else idx++;
break;
}
}
}
}