-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay2_Pt1.linq
52 lines (40 loc) · 1.13 KB
/
Day2_Pt1.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
void Main()
{
string[] input = File.ReadAllText(@"c:\Users\Kaylyn\Desktop\AOC\Day2_A.txt").Trim().Split(new[] { "\r\n", "\r", "\n", "," }, StringSplitOptions.None);
//string[] test ="1,9,10,3,2,3,11,0,99,30,40,50".Split(',');
input[1] = "12";
input[2] = "2";
string[] result = RecreateIntcodeComputer(input);
Console.WriteLine(result[0]);
}
public string[] RecreateIntcodeComputer(string[] input)
{
int i = 0;
do
{
int value = int.Parse(input[i]);
if (value == 99)
break;
else if (value == 1)
{
//add
int i1 = int.Parse(input[i + 1]);
int i2 = int.Parse(input[i + 2]);
int result = int.Parse(input[i1]) + int.Parse(input[i2]);
int newI = int.Parse(input[i + 3]);
input[newI] = result.ToString();
i += 4;
}
else if (value == 2)
{
int i1 = int.Parse(input[i + 1]);
int i2 = int.Parse(input[i + 2]);
int result = int.Parse(input[i1]) * int.Parse(input[i2]);
int newI = int.Parse(input[i + 3]);
input[newI] = result.ToString();
i += 4;
}
} while (i <= input.Length);
return input;
}
// Define other methods and classes here