-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_6.cs
67 lines (58 loc) · 1.87 KB
/
Day_6.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace AdventOfCode_2023
{
public class Day_6 : Day
{
public override long FirstPart()
{
long res = 1;
List<long> times = inputs[0]
.Split(":")[1]
.Trim()
.Split(" ")
.Where(t => !string.IsNullOrWhiteSpace(t))
.Select(t => long.Parse(t.Trim()))
.ToList();
List<long> records = inputs[1]
.Split(":")[1]
.Trim()
.Split(" ")
.Where(t => !string.IsNullOrWhiteSpace(t))
.Select(t => long.Parse(t.Trim()))
.ToList();
for (int i = 0; i < times.Count; i++)
res *= CalculatePossibleWays(times[i], records[i]);
return res;
}
public override long SecondPart()
{
long time = long.Parse(
string.Join(
"",
inputs[0]
.Split(":")[1]
.Split(" ")
.Select(t => (t.Trim()))
.Where(t => !string.IsNullOrWhiteSpace(t))));
long record = long.Parse(
string.Join(
"",
inputs[1]
.Split(":")[1]
.Split(" ")
.Select(t => (t.Trim()))
.Where(t => !string.IsNullOrWhiteSpace(t))));
return CalculatePossibleWays(time, record);
}
private static long CalculatePossibleWays(long time, long record)
{
long res = 0;
for (int j = 0; j < time; j++)
{
long boatSpeed = j;
long currentDistance = (time - j) * boatSpeed;
if (currentDistance > record) res++;
}
return res;
}
}
}