-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day2.cs
57 lines (52 loc) · 1.53 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
namespace AdventOfCode
{
public static class Day2
{
public static int Part1()
{
List<(string direction, int value)> data = DataService.GetDay2Data();
int horizontal = 0;
int depth = 0;
foreach ((string direction, int value) in data)
{
switch (direction)
{
case "forward":
horizontal += value;
break;
case "up":
depth -= value;
break;
case "down":
depth += value;
break;
}
}
return horizontal * depth;
}
public static int Part2()
{
List<(string direction, int value)> data = DataService.GetDay2Data();
int horizontal = 0;
int depth = 0;
int aim = 0;
foreach ((string direction, int value) in data)
{
switch (direction)
{
case "forward":
horizontal += value;
depth += aim * value;
break;
case "up":
aim -= value;
break;
case "down":
aim += value;
break;
}
}
return horizontal * depth;
}
}
}