-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
53 lines (42 loc) · 1.06 KB
/
Program.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
using AdventOfCode.Common;
var lines = Resources.GetInputFileLines();
static void Simulate(string[] lines, Action<int> forward, Action<int> down, Action<int> up)
{
foreach (var line in lines)
{
var parts = line.Split(' ');
var direction = parts[0];
var distance = int.Parse(parts[1]);
switch (direction)
{
case "forward":
forward(distance);
break;
case "down":
down(distance);
break;
case "up":
up(distance);
break;
}
}
}
var position = (0, 0);
// Part 1
Simulate(lines,
f => position.Item2 += f,
d => position.Item1 += d,
u => position.Item1 -= u);
Console.WriteLine($"Part 1: {position.Item1 * position.Item2}");
// Part 2
position = (0, 0);
var aim = 0;
Simulate(lines,
f =>
{
position.Item1 += aim * f;
position.Item2 += f;
},
d => aim += d,
u => aim -= u);
Console.WriteLine($"Part 2: {position.Item1 * position.Item2}");