43 lines
818 B
C#
43 lines
818 B
C#
#define Day2
|
|
#if Day2
|
|
long f = 0;
|
|
long d = 0;
|
|
var linesSplit = File.ReadAllLines("day2/input")
|
|
.Select(l => l.Split(" "))
|
|
.Select(lineParts => new { op = lineParts[0], x = long.Parse(lineParts[1]) })
|
|
.ToList();
|
|
|
|
linesSplit.ForEach(v => {
|
|
switch (v.op) {
|
|
case "down":
|
|
d += v.x;
|
|
break;
|
|
case "up":
|
|
d -= v.x;
|
|
break;
|
|
default:
|
|
f += v.x;
|
|
break;
|
|
}
|
|
});
|
|
Console.WriteLine(f * d);
|
|
|
|
f = 0;
|
|
d = 0;
|
|
long aim = 0;
|
|
linesSplit.ForEach(v => {
|
|
switch (v.op) {
|
|
case "down":
|
|
aim += v.x;
|
|
break;
|
|
case "up":
|
|
aim -= v.x;
|
|
break;
|
|
default:
|
|
f += v.x;
|
|
d += aim * v.x;
|
|
break;
|
|
}
|
|
});
|
|
Console.WriteLine(f * d);
|
|
#endif |