-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day2.cs
71 lines (59 loc) · 1.59 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
public static class Day2
{
public static int DoTheThing(string path)
{
var aim = 0;
var horizontal = 0;
var depth = 0;
var lines = File.ReadAllLines(path);
foreach (var line in lines)
{
var split = line.Split(' ');
var instruction = split.First();
var amount = Convert.ToInt32(split.Last());
switch (instruction)
{
case "forward":
horizontal += amount;
depth += aim * amount;
break;
case "down":
aim += amount;
break;
case "up":
aim -= amount;
break;
default:
break;
}
}
return horizontal * depth;
}
public static int DoTheThing1(string path)
{
var h = 0;
var d = 0;
var lines = File.ReadAllLines(path);
foreach (var line in lines)
{
var split = line.Split(' ');
var instruction = split.First();
var amount = Convert.ToInt32(split.Last());
switch (instruction)
{
case "forward":
h += amount;
break;
case "down":
d += amount;
break;
case "up":
d -= amount;
break;
default:
break;
}
}
return h * d;
}
}