-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay02.cs
38 lines (35 loc) · 1.24 KB
/
Day02.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
using static MoreLinq.Extensions.PairwiseExtension;
using WinstonPuckett.PipeExtensions;
using System.Reflection;
public static class Day02
{
private static async Task<IList<(string Ins, int Unit)>> GetInput() =>
await Inputs
.Read(MethodBase.GetCurrentMethod()?.DeclaringType?.FullName?.Split("+").First() ?? "")
.Select(text => (Ins: text.Split(" ")[0].Trim().ToLower(), Unit: int.Parse(text.Split(" ")[1])))
.ToListAsync();
public static async Task<int> One() =>
(await GetInput())
.Select(i => (
x: i.Ins switch { "forward" => i.Unit, _ => 0 },
y: i.Ins switch { "down" => i.Unit, "up" => -i.Unit, _ => 0 }
))
.Aggregate((p, n) => (
x: p.x + n.x,
y: p.y + n.y
))
.Pipe(p => p.x * p.y);
public static async Task<int> Two() =>
(await GetInput())
.Select(i => (
x: i.Ins switch { "forward" => i.Unit, _ => 0 },
y: 0,
aim: i.Ins switch { "down" => i.Unit, "up" => -i.Unit, _ => 0 }
))
.Aggregate((p, n) => (
x: p.x + n.x,
y: p.y + (n.x * (p.aim + n.aim)),
aim: p.aim + n.aim
))
.Pipe(p => p.x * p.y);
}