day 9 part 1
This commit is contained in:
48
AdventOfCode/Problems/AOC2025/Day9/MovieTheater.cs
Normal file
48
AdventOfCode/Problems/AOC2025/Day9/MovieTheater.cs
Normal file
@@ -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<long, long>
|
||||||
|
{
|
||||||
|
private Vec2<long>[] _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<long> a, Vec2<long> 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<long>(v.First(), v.Last())).ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,14 +18,25 @@ public record struct Vec2<T>(T X, T Y) where T : INumber<T>
|
|||||||
public static Vec2<T> operator *(T left, Vec2<T> right) => new Vec2<T>(right.X * left, right.Y * left);
|
public static Vec2<T> operator *(T left, Vec2<T> right) => new Vec2<T>(right.X * left, right.Y * left);
|
||||||
public static Vec2<T> operator /(Vec2<T> left, T right) => new Vec2<T>(left.X / right, left.Y / right);
|
public static Vec2<T> operator /(Vec2<T> left, T right) => new Vec2<T>(left.X / right, left.Y / right);
|
||||||
|
|
||||||
public T DistanceSq(Vec2<T> other)
|
public static implicit operator Vec2<T>(T value)
|
||||||
|
{
|
||||||
|
return new(value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly T DistanceSq(Vec2<T> other)
|
||||||
{
|
{
|
||||||
var a = other.X - this.X;
|
var a = other.X - this.X;
|
||||||
var b = other.Y - this.Y;
|
var b = other.Y - this.Y;
|
||||||
return (a * a) + (b * b);
|
return (a * a) + (b * b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public readonly Vec2<T> Min(Vec2<T> other) => new(T.Min(X, other.X), T.Min(Y, other.Y));
|
||||||
|
|
||||||
|
public readonly Vec2<T> Max(Vec2<T> other) => new(T.Max(X, other.X), T.Max(Y, other.Y));
|
||||||
|
|
||||||
|
public readonly Vec2<T> Abs() => new(T.Abs(X), T.Abs(Y));
|
||||||
|
|
||||||
|
public override readonly string ToString()
|
||||||
{
|
{
|
||||||
return $"({X}, {Y})";
|
return $"({X}, {Y})";
|
||||||
}
|
}
|
||||||
@@ -43,7 +54,12 @@ public record struct Vec3<T>(T X, T Y, T Z) where T : INumber<T>
|
|||||||
public static Vec3<T> operator *(T left, Vec3<T> right) => new Vec3<T>(right.X * left, right.Y * left, right.Z * left);
|
public static Vec3<T> operator *(T left, Vec3<T> right) => new Vec3<T>(right.X * left, right.Y * left, right.Z * left);
|
||||||
public static Vec3<T> operator /(Vec3<T> left, T right) => new Vec3<T>(left.X / right, left.Y / right, left.Z / right);
|
public static Vec3<T> operator /(Vec3<T> left, T right) => new Vec3<T>(left.X / right, left.Y / right, left.Z / right);
|
||||||
|
|
||||||
public T DistanceSq(Vec3<T> other)
|
public static implicit operator Vec3<T>(T value)
|
||||||
|
{
|
||||||
|
return new(value, value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly T DistanceSq(Vec3<T> other)
|
||||||
{
|
{
|
||||||
var a = other.X - this.X;
|
var a = other.X - this.X;
|
||||||
var b = other.Y - this.Y;
|
var b = other.Y - this.Y;
|
||||||
@@ -51,7 +67,12 @@ public record struct Vec3<T>(T X, T Y, T Z) where T : INumber<T>
|
|||||||
return (a * a) + (b * b) + (c * c);
|
return (a * a) + (b * b) + (c * c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public readonly Vec3<T> Min(Vec3<T> other) => new(T.Min(X, other.X), T.Min(Y, other.Y), T.Min(Z, other.Z));
|
||||||
|
|
||||||
|
public readonly Vec3<T> Max(Vec3<T> other) => new(T.Max(X, other.X), T.Max(Y, other.Y), T.Max(Z, other.Z));
|
||||||
|
public readonly Vec3<T> Abs() => new(T.Abs(X), T.Abs(Y), T.Abs(Z));
|
||||||
|
|
||||||
|
public override readonly string ToString()
|
||||||
{
|
{
|
||||||
return $"({X}, {Y}, {Z})";
|
return $"({X}, {Y}, {Z})";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user