Day2
This commit is contained in:
parent
96fe2d121d
commit
803266f078
2
Day1.cs
2
Day1.cs
|
|
@ -1,4 +1,4 @@
|
|||
#define Day1
|
||||
// #define Day1
|
||||
#if Day1
|
||||
var scans = File.ReadAllLines("day1/input").Select(int.Parse).ToList();
|
||||
Console.WriteLine(Enumerable.Range(1, scans.Count - 1).Count(i => scans[i - 1] < scans[i]));
|
||||
|
|
|
|||
43
Day2.cs
43
Day2.cs
|
|
@ -1,4 +1,43 @@
|
|||
// #define Day2
|
||||
#define Day2
|
||||
#if Day2
|
||||
var toBeDefined = File.ReadAllLines("day2/input");
|
||||
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
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue