Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 11, 2023
1 parent faef329 commit bbbd1e5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions AdventOfCode/Day10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ public Day10()

public override ValueTask<string> Solve_1()
{
List<Point> points = GetLoopPoints();
return new((points.Count / 2).ToString());
List<Point> loopPoints = GetLoopPoints();
return new((loopPoints.Count / 2).ToString());
}

public override ValueTask<string> Solve_2()
{
List<Point> loopPoints = GetLoopPoints();
var insidePoints = GetInsidePoints(loopPoints);
return new(insidePoints.Count.ToString());
return new(insidePoints.ToString());
}

private List<Point> GetInsidePoints(List<Point> loopPoints)
private int GetInsidePoints(List<Point> loopPoints)
{
List<Point> points = new List<Point>();
int insidePoints = 0;
for (int i = 0; i < _input.Length; ++i)
{
var lineLoopPoints = loopPoints.Where(p => p.I == i);
var lineLoopPoints = loopPoints.Where(p => p.I == i).ToList();
bool inside = false;

for (int j = 0; j < _input[0].Length; ++j)
{
Point p = lineLoopPoints.SingleOrDefault(p => p.I == i && p.J == j);
Point p = lineLoopPoints.FirstOrDefault(p => p.I == i && p.J == j);
lineLoopPoints.Remove(p);

if (p != null)
{
if (p.Value == '|')
Expand All @@ -56,11 +59,11 @@ private List<Point> GetInsidePoints(List<Point> loopPoints)
}
else if (inside)
{
points.Add(new Point(i, j, 'I'));
insidePoints++;
}
}
}
return points;
return insidePoints;
}

private Point GetStart()
Expand Down

0 comments on commit bbbd1e5

Please sign in to comment.