-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay6.cs
83 lines (68 loc) · 2.01 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Diagnostics;
namespace _2023_cs;
public class Day6
{
private static List<int> to_ints(string[] numbers)
{
List<int> result = new List<int>();
foreach (var num in numbers)
{
if (num.Length !=0 && char.IsNumber(num[0]))
{
result.Add(Convert.ToInt32(num));
}
}
return result;
}
public static int part2_read(string line)
{
int result = 0;
foreach (var c in line)
{
if (char.IsNumber(c))
{
result *= 10;
result += c - '0';
}
}
return result;
}
public static void solve(string filename)
{
StreamReader input = new StreamReader(filename);
string? line = input.ReadLine();
line = line.TrimEnd();
long p2_time = 44899691;
string[] strtimes = line.Split(' ');
line = input.ReadLine();
line = line.TrimEnd();
long p2_dist = 277113618901768;
string[] strdistances = line.Split(' ');
List<int> times = to_ints(strtimes);
List<int> distances = to_ints(strdistances);
int sum = 1;
for (int i = 0; i < times.Count; i++)
{
int beaten = 0;
for (int timeHeld = 0; timeHeld <= times[i]; timeHeld++)
{
if (timeHeld*(times[i]-timeHeld)> distances[i])
{
beaten++;
}
}
sum *= beaten;
}
Console.WriteLine("Day 6");
Console.WriteLine(sum);
int beaten2 = 0;
for (int timeHeld = 0; timeHeld <= p2_time; timeHeld++)
{
if (timeHeld*(p2_time-timeHeld)> p2_dist)
{
beaten2++;
}
}
Console.WriteLine(beaten2);
}
}