Skip to content

Commit

Permalink
refactor day 8
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 8, 2024
1 parent e01f596 commit d09ccc5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions AdventOfCode/Day08.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ private List<Point> GetAntinodes(Point a, Point b)
{
List<Point> result = new List<Point>();

var antinodeOne = new Point(2 * b.I - a.I, 2 * b.J - a.J);
var antinodeTwo = new Point(2 * a.I - b.I, 2 * a.J - b.J);
var antinodeOne = GetAntinode(a, b, 2);
var antinodeTwo = GetAntinode(b, a, 2);

if (IsWithinBounds(antinodeOne))
{
Expand All @@ -104,17 +104,22 @@ private List<Point> GetAntinodesUpdatedOneDirection(Point a, Point b)
List<Point> result = new List<Point>();

int n = 1;
var antinode = new Point(n * b.I - (n - 1) * a.I, n * b.J - (n - 1) * a.J);
var antinode = GetAntinode(a, b, n);
while (IsWithinBounds(antinode))
{
result.Add(antinode);
n++;
antinode = new Point(n * b.I - (n - 1) * a.I, n * b.J - (n - 1) * a.J);
antinode = GetAntinode(a, b, n);
}

return result;
}

private Point GetAntinode(Point a, Point b, int n)
{
return new Point(n * b.I - (n - 1) * a.I, n * b.J - (n - 1) * a.J);
}

private bool IsWithinBounds(Point point)
{
return point.I >= 0 && point.I < _input.Length
Expand Down

0 comments on commit d09ccc5

Please sign in to comment.