71 lines
1.6 KiB
C#
71 lines
1.6 KiB
C#
using System.Runtime.InteropServices;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace adventOfCode.day9;
|
|
|
|
record Point(long X, long Y)
|
|
{
|
|
public static Point ParseLine(string line)
|
|
{
|
|
var x = line.Split(",");
|
|
return new Point(long.Parse(x[0]), long.Parse(x[1]));
|
|
}
|
|
|
|
|
|
public static long Dist(Point p1, Point p2)
|
|
{
|
|
return (Math.Abs(p1.X - p2.X) + 1) * (Math.Abs(p1.Y - p2.Y) + 1);
|
|
}
|
|
}
|
|
|
|
record Rectangle(Point C1, Point C2)
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public class Day9
|
|
{
|
|
static List<Point> ParseInput(string document)
|
|
{
|
|
return (from line in document.Split("\n") select Point.ParseLine(line)).ToList();
|
|
}
|
|
|
|
static IEnumerable<Tuple<Point, Point>> AllPairs(List<Point> points)
|
|
{
|
|
for (var i = 0; i < points.Count; i++)
|
|
{
|
|
for (var j = i + 1; j < points.Count; j++)
|
|
{
|
|
yield return new Tuple<Point, Point>(points[i], points[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
static long Question9A(string document)
|
|
{
|
|
var points = ParseInput(document);
|
|
return (from pair in AllPairs(points) select Point.Dist(pair.Item1, pair.Item2)).Max();
|
|
}
|
|
|
|
static long Question9B(string document)
|
|
{
|
|
var points = ParseInput(document);
|
|
var pairs = from pair in AllPairs(points) orderby Point.Dist(pair.Item1, pair.Item2) descending select pair;
|
|
foreach (var pair in pairs)
|
|
{
|
|
// if
|
|
|
|
}
|
|
return 23;
|
|
|
|
}
|
|
|
|
public static void Main_()
|
|
{
|
|
Console.WriteLine($"Answer to question 9a is: {Question9A(Inputs.Input)}");
|
|
|
|
}
|
|
} |