Skip to content

Commit

Permalink
2018 Day10 Solved
Browse files Browse the repository at this point in the history
  • Loading branch information
smabuk committed Nov 11, 2023
1 parent 8094318 commit de4f19d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
42 changes: 26 additions & 16 deletions Solutions/2018/Day10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,11 @@ private static void LoadTheStars(string[] input) {
_pointsOfLight = input.Select(PointOfLight.Parse);
}

private static string Solution1(string[] _) {
private static string Solution1(string[] _)
{
List<PointOfLight> pointsOfLight = _pointsOfLight.ToList();

int letterHeight = pointsOfLight.Count < 35 ? 8 : 10;

int minY = int.MinValue;
int maxY = int.MaxValue;
do {
for (int i = 0; i < pointsOfLight.Count; i++) {
pointsOfLight[i] = pointsOfLight[i].Move();
}

minY = pointsOfLight.Min(p => p.Position.Y);
maxY = pointsOfLight.Max(p => p.Position.Y);
} while (maxY - minY > letterHeight);
int noOfSeconds = MoveTheStars(pointsOfLight, out int minY, out int maxY);

int minX = pointsOfLight.Min(p => p.Position.X);
int maxX = pointsOfLight.Max(p => p.Position.X);
Expand All @@ -53,9 +43,29 @@ private static string Solution1(string[] _) {
return message;
}

private static string Solution2(string[] input) {
List<PointOfLight> pointsOfLight = input.Select(ParseLine).ToList();
return "** Solution not written yet **";
private static int Solution2(string[] input)
{
List<PointOfLight> pointsOfLight = _pointsOfLight.ToList();
return MoveTheStars(pointsOfLight, out int _, out int _);
}

private static int MoveTheStars(List<PointOfLight> pointsOfLight, out int minY, out int maxY)
{
int letterHeight = pointsOfLight.Count < 35 ? 8 : 10;
int noOfSeconds = 0;
minY = int.MinValue;
maxY = int.MaxValue;
do {
for (int i = 0; i < pointsOfLight.Count; i++) {
pointsOfLight[i] = pointsOfLight[i].Move();
}

minY = pointsOfLight.Min(p => p.Position.Y);
maxY = pointsOfLight.Max(p => p.Position.Y);
noOfSeconds++;
} while (maxY - minY > letterHeight);

return noOfSeconds;
}

private record PointOfLight(Point Position, Point Velocity) : IParsable<PointOfLight> {
Expand Down
6 changes: 3 additions & 3 deletions Tests/2018/Tests_10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public void Part1(string input, string expected)
position=< 5, 9> velocity=< 1, -2>
position=<14, 7> velocity=<-2, 0>
position=<-3, 6> velocity=< 2, -1>
""", "???")]
public void Part2(string input, string expected)
""", 3)]
public void Part2(string input, int expected)
{
string actual = SolutionRouter.SolveProblem(YEAR, DAY, PART2, input);
_ = int.TryParse(SolutionRouter.SolveProblem(YEAR, DAY, PART2, input), out int actual);
Assert.Equal(expected, actual);
}
}

0 comments on commit de4f19d

Please sign in to comment.