From 07510227e94345a0de62e5bddc2261af8a207269 Mon Sep 17 00:00:00 2001 From: Amatsugu Date: Thu, 11 Dec 2025 19:02:40 -0500 Subject: [PATCH] day 9 part 1 --- .../Problems/AOC2025/Day9/MovieTheater.cs | 48 +++++++++++++++++++ AdventOfCode/Utils/Models/Common.cs | 29 +++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 AdventOfCode/Problems/AOC2025/Day9/MovieTheater.cs diff --git a/AdventOfCode/Problems/AOC2025/Day9/MovieTheater.cs b/AdventOfCode/Problems/AOC2025/Day9/MovieTheater.cs new file mode 100644 index 0000000..af9ee67 --- /dev/null +++ b/AdventOfCode/Problems/AOC2025/Day9/MovieTheater.cs @@ -0,0 +1,48 @@ +using AdventOfCode.Utils.Models; + +using System; +using System.Collections.Generic; +using System.Text; + +namespace AdventOfCode.Problems.AOC2025.Day9; + +[ProblemInfo(2025, 9, "Movie Theater")] +internal class MovieTheater : Problem +{ + private Vec2[] _input = []; + + public override void CalculatePart1() + { + for (long i = 0; i < _input.Length; i++) + { + var a = _input[i]; + for (long j = (i + 1); j < _input.Length; j++) + { + var b = _input[j]; + var area = CalculateArea(a, b); + if (area > Part1) + { + Part1 = area; + } + } + } + } + + public static long CalculateArea(Vec2 a, Vec2 b) + { + var rect = (a - b).Abs() + 1; + var area = Math.Abs(rect.X * rect.Y); + //Console.WriteLine($"{a} -> {b} : {rect} = {area}"); + return area; + } + + public override void CalculatePart2() + { + throw new NotImplementedException(); + } + + public override void LoadInput() + { + _input = ReadInputLines("input.txt").Select(l => l.Split(',').Select(long.Parse)).Select(v => new Vec2(v.First(), v.Last())).ToArray(); + } +} diff --git a/AdventOfCode/Utils/Models/Common.cs b/AdventOfCode/Utils/Models/Common.cs index 748b78c..64eeed1 100644 --- a/AdventOfCode/Utils/Models/Common.cs +++ b/AdventOfCode/Utils/Models/Common.cs @@ -18,14 +18,25 @@ public record struct Vec2(T X, T Y) where T : INumber public static Vec2 operator *(T left, Vec2 right) => new Vec2(right.X * left, right.Y * left); public static Vec2 operator /(Vec2 left, T right) => new Vec2(left.X / right, left.Y / right); - public T DistanceSq(Vec2 other) + public static implicit operator Vec2(T value) + { + return new(value, value); + } + + public readonly T DistanceSq(Vec2 other) { var a = other.X - this.X; var b = other.Y - this.Y; return (a * a) + (b * b); } - public override string ToString() + public readonly Vec2 Min(Vec2 other) => new(T.Min(X, other.X), T.Min(Y, other.Y)); + + public readonly Vec2 Max(Vec2 other) => new(T.Max(X, other.X), T.Max(Y, other.Y)); + + public readonly Vec2 Abs() => new(T.Abs(X), T.Abs(Y)); + + public override readonly string ToString() { return $"({X}, {Y})"; } @@ -43,7 +54,12 @@ public record struct Vec3(T X, T Y, T Z) where T : INumber public static Vec3 operator *(T left, Vec3 right) => new Vec3(right.X * left, right.Y * left, right.Z * left); public static Vec3 operator /(Vec3 left, T right) => new Vec3(left.X / right, left.Y / right, left.Z / right); - public T DistanceSq(Vec3 other) + public static implicit operator Vec3(T value) + { + return new(value, value, value); + } + + public readonly T DistanceSq(Vec3 other) { var a = other.X - this.X; var b = other.Y - this.Y; @@ -51,7 +67,12 @@ public record struct Vec3(T X, T Y, T Z) where T : INumber return (a * a) + (b * b) + (c * c); } - public override string ToString() + public readonly Vec3 Min(Vec3 other) => new(T.Min(X, other.X), T.Min(Y, other.Y), T.Min(Z, other.Z)); + + public readonly Vec3 Max(Vec3 other) => new(T.Max(X, other.X), T.Max(Y, other.Y), T.Max(Z, other.Z)); + public readonly Vec3 Abs() => new(T.Abs(X), T.Abs(Y), T.Abs(Z)); + + public override readonly string ToString() { return $"({X}, {Y}, {Z})"; }