Skip to content

Commit 386fa49

Browse files
authored
Update Solution.cs
1 parent ed5bca7 commit 386fa49

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

2022/Day09/Solution.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ class Solution : Solver {
1010
public object PartOne(string input) => Tails(input, 2).ToHashSet().Count;
1111
public object PartTwo(string input) => Tails(input, 10).ToHashSet().Count;
1212

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.
1516
private IEnumerable<Knot> Tails(string input, int ropeLength) {
1617
var rope = Enumerable.Repeat(new Knot(0, 0), ropeLength).ToArray();
1718
yield return rope.Last();
@@ -30,7 +31,8 @@ private IEnumerable<Knot> Tails(string input, int ropeLength) {
3031

3132
record struct Knot(int irow, int icol);
3233

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
3436
void MoveHead(Knot[] rope, string dir) {
3537
rope[0] = dir switch {
3638
"U" => rope[0] with { irow = rope[0].irow - 1 },
@@ -40,7 +42,8 @@ void MoveHead(Knot[] rope, string dir) {
4042
_ => throw new ArgumentException(dir)
4143
};
4244

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:
4447
for (var i = 1; i < rope.Length; i++) {
4548
var drow = rope[i - 1].irow - rope[i].irow;
4649
var dcol = rope[i - 1].icol - rope[i].icol;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy