Extract Coordinate, IntegerRange and Coordinate3d to new AdventOfCode.HelperClasses project and refactor solution for modularity and type consistency
This commit is contained in:
+6
-11
@@ -1,11 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using AdvenOfCode.Contracts;
|
||||
using AdvenOfCode.Contracts;
|
||||
using AdventOfCode.Extensions;
|
||||
using Coordinate = (long x, long y);
|
||||
using AdventOfCode.HelperClasses;
|
||||
using CoordinatePair = (long minX, long minY, long maxX, long maxY);
|
||||
|
||||
namespace AoC_2025;
|
||||
@@ -17,7 +12,7 @@ public class Day09 : IPuzzleSolver<long>
|
||||
var puzzleInput = File.ReadAllLines(path)
|
||||
.Where(line => !string.IsNullOrWhiteSpace(line))
|
||||
.Select(line => line.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(str => long.Parse(str)).ToArray())
|
||||
.Select(numbers => (numbers[0], numbers[1]))
|
||||
.Select(numbers => new Coordinate(numbers[0], numbers[1]))
|
||||
.ToArray();
|
||||
return puzzleInput;
|
||||
}
|
||||
@@ -43,7 +38,7 @@ public class Day09 : IPuzzleSolver<long>
|
||||
private IOrderedEnumerable<long> GetOrderedAreas(IEnumerable<CoordinatePair> containedRectangles)
|
||||
{
|
||||
return containedRectangles
|
||||
.Select(rectangle => GetArea((rectangle.maxX, rectangle.maxY), (rectangle.minX, rectangle.minY)))
|
||||
.Select(rectangle => GetArea(new Coordinate(rectangle.maxX, rectangle.maxY), new Coordinate(rectangle.minX, rectangle.minY)))
|
||||
.OrderDescending();
|
||||
}
|
||||
|
||||
@@ -71,7 +66,7 @@ public class Day09 : IPuzzleSolver<long>
|
||||
|
||||
private CoordinatePair AsPair(Coordinate a, Coordinate b)
|
||||
{
|
||||
return (Math.Min(a.x, b.x), Math.Min(a.y, b.y), Math.Max(a.x, b.x), Math.Max(a.y, b.y));
|
||||
return (Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Max(a.X, b.X), Math.Max(a.Y, b.Y));
|
||||
}
|
||||
|
||||
private bool RectangleCrossesBorder(CoordinatePair rectangle, CoordinatePair borderSegment)
|
||||
@@ -82,7 +77,7 @@ public class Day09 : IPuzzleSolver<long>
|
||||
|
||||
private long GetArea(Coordinate tileA, Coordinate tileB)
|
||||
{
|
||||
return (Math.Abs(tileA.x - tileB.x) + 1) * (Math.Abs(tileA.y - tileB.y) + 1);
|
||||
return (Math.Abs(tileA.X - tileB.X) + 1) * (Math.Abs(tileA.Y - tileB.Y) + 1);
|
||||
}
|
||||
|
||||
private IEnumerable<(Coordinate a, Coordinate b)> GetBorders(Coordinate[] tiles)
|
||||
|
||||
Reference in New Issue
Block a user