1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Collections . Immutable ;
4
3
using System . ComponentModel ;
5
4
using System . Linq ;
6
- using System . Text . RegularExpressions ;
7
- using System . Text ;
8
- using AdventOfCode . Y2018 . Day13 ;
9
5
10
6
namespace AdventOfCode . Y2023 . Day10 ;
11
7
@@ -28,74 +24,31 @@ public object PartOne(string input)
28
24
if ( pipesMap . Last ( ) . Value == Direction . Right )
29
25
{
30
26
currentPoint = ( pipesMap . Last ( ) . Key . Item1 , pipesMap . Last ( ) . Key . Item2 + 1 ) ;
31
- Console . WriteLine ( "We went right\n " + lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
32
27
newDirection = GetNewDirection ( Direction . Right , lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
33
28
}
34
29
else if ( pipesMap . Last ( ) . Value == Direction . Left )
35
30
{
36
31
currentPoint = ( pipesMap . Last ( ) . Key . Item1 , pipesMap . Last ( ) . Key . Item2 - 1 ) ;
37
- Console . WriteLine ( "We went left\n " + lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
38
32
newDirection = GetNewDirection ( Direction . Left , lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
39
33
}
40
34
else if ( pipesMap . Last ( ) . Value == Direction . Up )
41
35
{
42
36
currentPoint = ( pipesMap . Last ( ) . Key . Item1 - 1 , pipesMap . Last ( ) . Key . Item2 ) ;
43
- Console . WriteLine ( "We went up\n " + lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
44
37
newDirection = GetNewDirection ( Direction . Up , lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
45
38
}
46
39
else if ( pipesMap . Last ( ) . Value == Direction . Down )
47
40
{
48
41
currentPoint = ( pipesMap . Last ( ) . Key . Item1 + 1 , pipesMap . Last ( ) . Key . Item2 ) ;
49
- Console . WriteLine ( "We went Down\n " + lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
50
42
newDirection = GetNewDirection ( Direction . Down , lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ) ;
51
43
}
52
44
53
45
if ( newDirection == Direction . End )
54
46
{
55
47
// We went back to the previous point
56
- Console . WriteLine ( "We went back to the starting point" ) ;
57
48
break ;
58
49
}
59
50
60
- // Just to be sure
61
- var actualChar = lines [ currentPoint . Item1 ] [ currentPoint . Item2 ] ;
62
- Console . WriteLine ( "==> " + actualChar ) ;
63
- switch ( pipesMap . Last ( ) . Value )
64
- {
65
- case Direction . Down :
66
- {
67
- var down = new [ ] { '|' , 'L' , 'J' } ;
68
- if ( ! down . Contains ( actualChar ) )
69
- throw new InvalidOperationException ( "We went down but there is no correct pipe" ) ;
70
- break ;
71
- }
72
- case Direction . Up :
73
- {
74
- var up = new [ ] { '|' , '7' , 'F' } ;
75
- if ( ! up . Contains ( actualChar ) )
76
- throw new InvalidOperationException ( "We went up but there is no correct pipe" ) ;
77
- break ;
78
- }
79
- case Direction . Left :
80
- {
81
- var left = new [ ] { '-' , 'F' , 'L' } ;
82
- if ( ! left . Contains ( actualChar ) )
83
- throw new InvalidOperationException ( "We went left but there is no correct pipe" ) ;
84
- break ;
85
- }
86
- case Direction . Right :
87
- {
88
- var right = new [ ] { '-' , 'J' , '7' } ;
89
- if ( ! right . Contains ( actualChar ) )
90
- throw new InvalidOperationException ( "We went right but there is no correct pipe" ) ;
91
- break ;
92
- }
93
- }
94
-
95
51
pipesMap . Add ( currentPoint , newDirection ) ;
96
-
97
- // Display pipesMap.Last() data
98
- Console . WriteLine ( $ "Step { pipesMap . Count } Key: { string . Join ( ", " , pipesMap . Last ( ) . Key ) } , Value: { pipesMap . Last ( ) . Value } ") ;
99
52
}
100
53
101
54
return ( pipesMap . Count ) / 2 ;
@@ -117,7 +70,6 @@ private static string[] ParseLines(string input) =>
117
70
{
118
71
if ( lines [ i ] [ j ] == 'S' )
119
72
{
120
- Console . WriteLine ( $ "We found the starting point ({ i } , { j } )") ;
121
73
// Hardcoded starting direction
122
74
return new KeyValuePair < ( int , int ) , Direction > ( ( i , j ) , Direction . Right ) ;
123
75
}
@@ -127,48 +79,6 @@ private static string[] ParseLines(string input) =>
127
79
return new KeyValuePair < ( int , int ) , Direction > ( ) ;
128
80
}
129
81
130
- // private static Direction GetStartingDirection(IReadOnlyList<string> lines, int lineIndex, int pipeIndex)
131
- // {
132
- // var newDirections = new List<Direction>();
133
- // if (lineIndex > 0)
134
- // {
135
- // var newDirection = GetNewDirection(Direction.Up, lines[lineIndex - 1][pipeIndex]);
136
- // if (newDirection != Direction.Down)
137
- // {
138
- // newDirections.Add(newDirection);
139
- // }
140
- // }
141
- //
142
- // if (lineIndex < lines.Count - 1)
143
- // {
144
- // var newDirection = GetNewDirection(Direction.Down, lines[lineIndex + 1][pipeIndex]);
145
- // if (newDirection != Direction.Up)
146
- // {
147
- // newDirections.Add(newDirection);
148
- // }
149
- // }
150
- //
151
- // if (pipeIndex > 0)
152
- // {
153
- // var newDirection = GetNewDirection(Direction.Left, lines[lineIndex][pipeIndex - 1]);
154
- // if (newDirection != Direction.Right)
155
- // {
156
- // newDirections.Add(newDirection);
157
- // }
158
- // }
159
- //
160
- // if (pipeIndex < lines[lineIndex].Length - 1)
161
- // {
162
- // var newDirection = GetNewDirection(Direction.Right, lines[lineIndex][pipeIndex + 1]);
163
- // if (newDirection != Direction.Left)
164
- // {
165
- // newDirections.Add(newDirection);
166
- // }
167
- // }
168
- //
169
- // return newDirections.Last();
170
- // }
171
-
172
82
private static Direction GetNewDirection ( Direction previousDirection , char pipe )
173
83
{
174
84
if ( pipe == 'S' )
@@ -218,103 +128,3 @@ internal enum Direction
218
128
Right ,
219
129
End
220
130
}
221
-
222
- class Position
223
- {
224
- public int x ;
225
- public int y ;
226
-
227
- public Position ( int x , int y )
228
- {
229
- this . x = x ;
230
- this . y = y ;
231
- }
232
- }
233
-
234
- class Pipe
235
- {
236
- public char symbol ;
237
- public int x ;
238
- public int y ;
239
-
240
- public bool north ;
241
- public bool east ;
242
- public bool south ;
243
- public bool west ;
244
-
245
- public bool scheduleToRemove ;
246
-
247
- public Pipe ( char symbol , int x , int y )
248
- {
249
- this . symbol = symbol ;
250
- this . x = x ;
251
- this . y = y ;
252
- SetConnections ( ) ;
253
- }
254
-
255
- public void ScheduleToRemove ( )
256
- {
257
- scheduleToRemove = true ;
258
- }
259
-
260
- public void CleanUp ( )
261
- {
262
- if ( scheduleToRemove )
263
- {
264
- symbol = '.' ;
265
- north = false ;
266
- east = false ;
267
- south = false ;
268
- west = false ;
269
- }
270
- }
271
-
272
- private void SetConnections ( )
273
- {
274
- switch ( symbol )
275
- {
276
- case 'S' :
277
- north = true ;
278
- east = true ;
279
- south = true ;
280
- west = true ;
281
- break ;
282
- case 'F' :
283
- north = false ;
284
- east = true ;
285
- south = true ;
286
- west = false ;
287
- break ;
288
- case '-' :
289
- north = false ;
290
- east = true ;
291
- south = false ;
292
- west = true ;
293
- break ;
294
- case '7' :
295
- north = false ;
296
- east = false ;
297
- south = true ;
298
- west = true ;
299
- break ;
300
- case '|' :
301
- north = true ;
302
- east = false ;
303
- south = true ;
304
- west = false ;
305
- break ;
306
- case 'J' :
307
- north = true ;
308
- east = false ;
309
- south = false ;
310
- west = true ;
311
- break ;
312
- case 'L' :
313
- north = true ;
314
- east = true ;
315
- south = false ;
316
- west = false ;
317
- break ;
318
- }
319
- }
320
- }
0 commit comments