Repository navigation
Expand file tree
/
Copy pathDay3.cs
More file actions
68 lines (55 loc) · 1.37 KB
/
Copy pathDay3.cs
File metadata and controls
68 lines (55 loc) · 1.37 KB
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
public static class Day3
{
public static int GetNumberOfTrees(string path)
{
var count = 0;
var lines = File.ReadLines(path).ToList();
var location = 0;
foreach (var line in lines)
{
if (location > line.Length - 1)
{
location -= line.Length;
}
if (line[location] == '#')
{
count++;
}
location += 3;
}
return count;
}
public static long GetNumberOfTrees2(string path)
{
int[][] paths = [
[1, 1],
[3, 1],
[5, 1],
[7, 1],
[1, 2],
];
long res = 1;
foreach (var p in paths)
{
var count = 0;
var lines = File.ReadLines(path).ToList();
var location = 0;
for (int i = 0; i < lines.Count; i += p[1])
{
var line = lines[i];
if (location > line.Length - 1)
{
location -= line.Length;
}
if (line[location] == '#')
{
count++;
}
location += p[0];
}
Console.WriteLine(count);
res *= count;
}
return res;
}
}