-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day6.cs
44 lines (33 loc) · 1.44 KB
/
Day6.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
using System.Text.RegularExpressions;
static class Day6{
internal static void doit(){
Regex dayNoR = new(@"\d*$");
var lines = Helper.getInputAsLines(int.Parse(dayNoR.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Value),
test:false);
long sumA = 1;
long sumB = 0;
var times = lines.First().Split(":")[1].Split(" ", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Select(a=>long.Parse(a));
var records = lines.Last().Split(":")[1].Split(" ", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Select(a=>long.Parse(a));
for (int i = 0; i < times.Count(); i++)
{
var time=times.Skip(i).First();
var rec=records.Skip(i).First();
long count=0;
for (long j = 0; j <= time; j++)
{
var meters = (time-j)*j;
if (meters>rec) count++;
}
sumA*=count;
}
var time2 = long.Parse(lines.First().Split(":")[1].Replace(" ",""));
var rec2 = long.Parse(lines.Last().Split(":")[1].Replace(" ",""));
for (long j = 0; j <= time2; j++)
{
var meters = (time2-j)*j;
if (meters>rec2) sumB++;
}
Console.WriteLine($"Sum: {sumA}");
Console.WriteLine($"SumB: {sumB}");
}
}