Add day 25

This commit is contained in:
2025-01-24 10:19:13 +01:00
parent d647742ca0
commit 69a941d34d
2 changed files with 4110 additions and 0 deletions

111
Days/Day25.cs Normal file
View File

@@ -0,0 +1,111 @@
using System.Collections.Frozen;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics.X86;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.VisualBasic;
using Spectre.Console;
namespace AdventOfCode.Days;
public class Day25 : Day
{
public override int Number => 25;
public override string Name => "Code Chronicle";
public override void RunPart1(bool display = true)
{
var (locks, keys) = ParseInput();
var workingPairs = 0;
foreach (var lockToTest in locks)
{
foreach (var key in keys)
{
if (lockToTest.Height1 + key.Height1 < 6 &&
lockToTest.Height2 + key.Height2 < 6 &&
lockToTest.Height3 + key.Height3 < 6 &&
lockToTest.Height4 + key.Height4 < 6 &&
lockToTest.Height5 + key.Height5 < 6)
{
workingPairs++;
}
}
}
if (display)
{
AnsiConsole.MarkupLine($"[green]Amont of unique key/lock pairs that fit: [yellow]{workingPairs}[/][/]");
}
}
public override void RunPart2(bool display = true)
{
}
private (List<Lock> Locks, List<Key> Keys) ParseInput()
{
var locks = new List<Lock>();
var keys = new List<Key>();
Span<int> itemHeights = stackalloc int[5];
var input = Input.AsSpan();
foreach (var itemRange in input.Split($"{Environment.NewLine}{Environment.NewLine}"))
{
var item = input[itemRange];
var lines = item.EnumerateLines();
var isKey = false;
// Reset item heights
itemHeights[0] = -1;
itemHeights[1] = -1;
itemHeights[2] = -1;
itemHeights[3] = -1;
itemHeights[4] = -1;
for (var height = 0; height <= 6; height++)
{
lines.MoveNext();
var line = lines.Current;
if (height is 0)
{
isKey = line is ".....";
continue;
}
for (var i = 0; i < 5; i++)
{
if (isKey && line[i] is '#' && itemHeights[i] is -1)
{
itemHeights[i] = 6 - height;
}
else if (!isKey && line[i] is '.' && itemHeights[i] is -1)
{
itemHeights[i] = height - 1;
}
}
}
if (isKey)
{
keys.Add(new Key(itemHeights[0], itemHeights[1], itemHeights[2], itemHeights[3], itemHeights[4]));
}
else
{
locks.Add(new Lock(itemHeights[0], itemHeights[1], itemHeights[2], itemHeights[3], itemHeights[4]));
}
}
return (locks, keys);
}
private readonly record struct Lock(int Height1, int Height2, int Height3, int Height4, int Height5);
private readonly record struct Key(int Height1, int Height2, int Height3, int Height4, int Height5);
}

3999
Inputs/Day25.txt Normal file

File diff suppressed because it is too large Load Diff