-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay8.cs
203 lines (180 loc) · 5.68 KB
/
Day8.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
namespace advent_of_code_2022;
using System.Collections.Generic;
public class Day8
{
public static void Part1(string[] args)
{
HashSet<Point> results = new HashSet<Point>();
string[] lines = File.ReadAllLines("day8-input.txt");
// left -> right
for (var i = 0; i < lines.Length; i++)
{
int currentMax = lines[i][0] - '0';
for (var j = 0; j < lines[i].Length; j++)
{
if (i == 0 || j == 0 || i == (lines.Length - 1) || j == (lines[i].Length - 1))
{
results.Add(new Point(j, i));
continue;
}
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
results.Add(new Point(j, i));
}
}
}
// right -> left
for (var i = 1; i < lines.Length - 1; i++)
{
int currentMax = lines[i][lines[0].Length - 1] - '0';
for (var j = lines[i].Length - 2; j >= 1; j--)
{
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
results.Add(new Point(j, i));
}
}
}
// top -> bottom
for (var j = 1; j < lines[0].Length - 1; j++)
{
int currentMax = lines[0][j] - '0';
for (var i = 1; i < lines.Length - 1; i++)
{
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
results.Add(new Point(j, i));
}
}
}
// bottom -> top
for (var j = 1; j < lines[0].Length - 1; j++)
{
int currentMax = lines[lines.Length - 1][j] - '0';
for (var i = lines.Length - 2; i >= 1; i--)
{
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
results.Add(new Point(j, i));
}
}
}
Console.WriteLine(results.Count);
}
public class Point
{
public readonly int I;
public readonly int J;
public int Value1 { get; set; }
public int Value2 { get; set; }
public int Value3 { get; set; }
public int Value4 { get; set; }
public Point(int j, int i)
{
this.I = i;
this.J = j;
Value1 = 0;
Value2 = 0;
Value3 = 0;
Value4 = 0;
}
protected bool Equals(Point other)
{
return I == other.I && J == other.J;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Point)obj);
}
public override int GetHashCode()
{
return HashCode.Combine(I, J);
}
public static bool operator ==(Point? left, Point? right)
{
return Equals(left, right);
}
public static bool operator !=(Point? left, Point? right)
{
return !Equals(left, right);
}
}
public static void Solve(string[] args)
{
string[] lines = File.ReadAllLines("day8-input.txt");
Point[,] ar = new Point[lines.Length, lines[0].Length];
for (var i = 0; i < ar.Length; i++)
{
for (var j = 0; j < lines[0].Length; j++)
{
ar[i, j] = new Point(j, i);
}
}
// left -> right
for (var i = 1; i < lines.Length - 1; i++)
{
int currentMax = lines[i][0] - '0';
for (var j = 1; j < lines[i].Length - 1; j++)
{
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
// ar[i, j].Value1 =
// results.Add(new Point(j, i));
}
}
}
// right -> left
for (var i = 1; i < lines.Length - 1; i++)
{
int currentMax = lines[i][lines[0].Length - 1] - '0';
for (var j = lines[i].Length - 2; j >= 1; j--)
{
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
}
}
}
// top -> bottom
for (var j = 1; j < lines[0].Length - 1; j++)
{
int currentMax = lines[0][j] - '0';
for (var i = 1; i < lines.Length - 1; i++)
{
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
}
}
}
// bottom -> top
for (var j = 1; j < lines[0].Length - 1; j++)
{
int currentMax = lines[lines.Length - 1][j] - '0';
for (var i = lines.Length - 2; i >= 1; i--)
{
int current = lines[i][j] - '0';
if (currentMax < current)
{
currentMax = current;
}
}
}
Console.WriteLine(0);
}
}