@@ -10,8 +10,9 @@ class Solution : Solver {
10
10
public object PartOne ( string input ) => Tails ( input , 2 ) . ToHashSet ( ) . Count ;
11
11
public object PartTwo ( string input ) => Tails ( input , 10 ) . ToHashSet ( ) . Count ;
12
12
13
- // Moves a rope with the given length according to the input and
14
- // returns the position of its tail in each step.
13
+ // simulates a rope with the given length as its head moves
14
+ // according to the input and returns the position of its
15
+ // tail knot in each step.
15
16
private IEnumerable < Knot > Tails ( string input , int ropeLength ) {
16
17
var rope = Enumerable . Repeat ( new Knot ( 0 , 0 ) , ropeLength ) . ToArray ( ) ;
17
18
yield return rope . Last ( ) ;
@@ -30,7 +31,8 @@ private IEnumerable<Knot> Tails(string input, int ropeLength) {
30
31
31
32
record struct Knot ( int irow , int icol ) ;
32
33
33
- // moves the head in the given direction, inplace update of the rope
34
+ // moves the head in the given direction, inplace update
35
+ // of the rope
34
36
void MoveHead ( Knot [ ] rope , string dir ) {
35
37
rope [ 0 ] = dir switch {
36
38
"U" => rope [ 0 ] with { irow = rope [ 0 ] . irow - 1 } ,
@@ -40,7 +42,8 @@ void MoveHead(Knot[] rope, string dir) {
40
42
_ => throw new ArgumentException ( dir )
41
43
} ;
42
44
43
- // move knots which are not adjacent to their previous sibling in the rope:
45
+ // knots move when become disconnected from the previous
46
+ // sibling in the rope:
44
47
for ( var i = 1 ; i < rope . Length ; i ++ ) {
45
48
var drow = rope [ i - 1 ] . irow - rope [ i ] . irow ;
46
49
var dcol = rope [ i - 1 ] . icol - rope [ i ] . icol ;
0 commit comments