Add Day12 implementation with puzzle-solving logic and tests
This commit is contained in:
parent
938f836e1f
commit
10b5648b9a
|
|
@ -0,0 +1,47 @@
|
|||
using AdvenOfCode.Contracts;
|
||||
|
||||
namespace AoC_2025.Tests;
|
||||
|
||||
public class Day12Test
|
||||
{
|
||||
private IPuzzleSolver<long> _sut;
|
||||
private static readonly string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
private readonly string TestInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Test\day12.txt";
|
||||
private readonly string ProdInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Prod\day12.txt";
|
||||
|
||||
public Day12Test()
|
||||
{
|
||||
_sut = new Day12();
|
||||
}
|
||||
[Fact]
|
||||
public void Part01_Test_equals_2()
|
||||
{
|
||||
var actual = _sut.SolvePart1(TestInputPath);
|
||||
|
||||
Assert.Equal(2, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part01_Prod_equals_460()
|
||||
{
|
||||
var actual = _sut.SolvePart1(ProdInputPath);
|
||||
|
||||
Assert.Equal(460, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02_Test2_equals_0()
|
||||
{
|
||||
var actual = _sut.SolvePart2(TestInputPath);
|
||||
|
||||
Assert.Equal(0, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02_Prod_equals_0()
|
||||
{
|
||||
var actual = _sut.SolvePart2(ProdInputPath);
|
||||
|
||||
Assert.Equal(0, actual);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using AdvenOfCode.Contracts;
|
||||
|
||||
namespace AoC_2025;
|
||||
|
||||
public class Day12 : IPuzzleSolver<long>
|
||||
{
|
||||
private (int[] presentSizes, (int area, int[] presentCounts)[] regions) ParsePuzzleInput(string path)
|
||||
{
|
||||
var puzzleInput = File.ReadAllText(path)
|
||||
.Split($"{Environment.NewLine}{Environment.NewLine}", StringSplitOptions.TrimEntries)
|
||||
.ToList();
|
||||
var presentSizes = puzzleInput[..^1]
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s))
|
||||
.Select(s => s.Count(c => c == '#'))
|
||||
.ToArray();
|
||||
var regions = puzzleInput[^1]
|
||||
.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Select(s => s.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
.Select(s =>
|
||||
(s[0].Split('x').Select(int.Parse).Aggregate((x, y) => x * y),
|
||||
s[1].Split(' ').Select(int.Parse).ToArray()))
|
||||
.ToArray();
|
||||
return (presentSizes, regions);
|
||||
}
|
||||
|
||||
public long SolvePart1(string pathToPuzzleInput)
|
||||
{
|
||||
var (presentSizes, regions) = ParsePuzzleInput(pathToPuzzleInput);
|
||||
var everythingFits =
|
||||
regions.Count(region => region.area >= GetMinTotalPresentArea(region.presentCounts, presentSizes));
|
||||
return everythingFits;
|
||||
}
|
||||
|
||||
private static int GetMinTotalPresentArea(int[] presentCounts, int[] presentSizes)
|
||||
{
|
||||
return presentCounts
|
||||
.Select((presentCount, index) => presentCount * presentSizes[index])
|
||||
.Sum();
|
||||
}
|
||||
|
||||
public long SolvePart2(string pathToPuzzleInput)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue