Compare commits
No commits in common. "b60db3c78aa2bd2ead0c911bcda19b44749a3742" and "62f46aff7d26b0ea30c2fbae74afab17a0bb3e3f" have entirely different histories.
b60db3c78a
...
62f46aff7d
|
|
@ -44,24 +44,4 @@ public class Day07Test
|
|||
|
||||
Assert.Equal(53916299384254, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02Again_Test_equals_40()
|
||||
{
|
||||
var sut = _sut as Day07;
|
||||
|
||||
var actual = sut.SolvePart2Again(TestInputPath);
|
||||
|
||||
Assert.Equal(40, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02Again_Prod_equals_53916299384254()
|
||||
{
|
||||
var sut = _sut as Day07;
|
||||
|
||||
var actual = sut.SolvePart2Again(ProdInputPath);
|
||||
|
||||
Assert.Equal(53916299384254, actual);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
using AdvenOfCode.Contracts;
|
||||
|
||||
namespace AoC_2025.Tests;
|
||||
|
||||
public class Day08Test
|
||||
{
|
||||
private readonly Day08 _sut;
|
||||
private static readonly string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
private readonly string TestInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Test\day08.txt";
|
||||
private readonly string ProdInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Prod\day08.txt";
|
||||
|
||||
public Day08Test()
|
||||
{
|
||||
_sut = new Day08();
|
||||
}
|
||||
[Fact]
|
||||
public void Part01_Test_equals_40()
|
||||
{
|
||||
var actual = _sut.SolvePart1(TestInputPath, 10);
|
||||
|
||||
Assert.Equal(40, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part01_Prod_equals_42840()
|
||||
{
|
||||
var actual = _sut.SolvePart1(ProdInputPath, 1000);
|
||||
|
||||
Assert.Equal(42840, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02_Test_equals_25272()
|
||||
{
|
||||
var actual = _sut.SolvePart2(TestInputPath);
|
||||
|
||||
Assert.Equal(25272, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02_Prod_equals_170629052()
|
||||
{
|
||||
var actual = _sut.SolvePart2(ProdInputPath);
|
||||
|
||||
Assert.Equal(170629052, actual);
|
||||
}
|
||||
}
|
||||
|
|
@ -29,15 +29,8 @@ public class Day07 : IPuzzleSolver<long>
|
|||
{
|
||||
var grid = ParsePuzzleInput(pathToPuzzleInput);
|
||||
var start = GetStart(grid);
|
||||
var nodesWithCount = GetNodesTraversedWitTimelineCount(grid, start, [], []);
|
||||
return nodesWithCount[start];
|
||||
}
|
||||
|
||||
public long SolvePart2Again(string pathToPuzzleInput)
|
||||
{
|
||||
var grid = ParsePuzzleInput(pathToPuzzleInput);
|
||||
var nodesWithCount = GetNodesTraversedWitTimelineCount(grid);
|
||||
return nodesWithCount.Sum();
|
||||
var count = GetNodesTraversedWitTimelineCount(grid, start, [], []);
|
||||
return count[start];
|
||||
}
|
||||
|
||||
private Coordinate GetStart(string[] grid)
|
||||
|
|
@ -106,34 +99,4 @@ public class Day07 : IPuzzleSolver<long>
|
|||
|
||||
return nodeCountVisited;
|
||||
}
|
||||
|
||||
private long[] GetNodesTraversedWitTimelineCount(string[] grid)
|
||||
{
|
||||
var numbersGrid = grid
|
||||
.Select(line => line.Select(c => 0L).ToArray())
|
||||
.ToArray();
|
||||
|
||||
for (var x = 1; x < numbersGrid.Length; x++)
|
||||
{
|
||||
for (var y = 0; y < numbersGrid[x].Length; y++)
|
||||
{
|
||||
var gridValue = grid[x - 1][y];
|
||||
switch (gridValue)
|
||||
{
|
||||
case 'S':
|
||||
numbersGrid[x][y] = 1;
|
||||
break;
|
||||
case '.':
|
||||
numbersGrid[x][y] += numbersGrid[x - 1][y];
|
||||
break;
|
||||
case '^':
|
||||
numbersGrid[x][y - 1] += numbersGrid[x - 1][y];
|
||||
numbersGrid[x][y + 1] += numbersGrid[x - 1][y];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return numbersGrid[^1];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using AdvenOfCode.Contracts;
|
||||
using Coordinate = (int x, int y, int z);
|
||||
|
||||
namespace AoC_2025;
|
||||
|
||||
public class Day08
|
||||
{
|
||||
private Coordinate[] ParsePuzzleInput(string path)
|
||||
{
|
||||
var puzzleInput = File.ReadAllLines(path)
|
||||
.Where(line => !string.IsNullOrWhiteSpace(line))
|
||||
.Select(line => line.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(str => int.Parse(str)).ToArray())
|
||||
.Select(numbers => (numbers[0], numbers[1], numbers[2]))
|
||||
.ToArray();
|
||||
return puzzleInput;
|
||||
}
|
||||
|
||||
public long SolvePart1(string pathToPuzzleInput, int amountToConnect)
|
||||
{
|
||||
var points = ParsePuzzleInput(pathToPuzzleInput);
|
||||
|
||||
var pointPairs = GetAllCombinationsSortedByDistance(points);
|
||||
|
||||
var circuits = CombineCircuits(amountToConnect, points, pointPairs);
|
||||
|
||||
return circuits
|
||||
.Select(circuit => circuit.Count)
|
||||
.OrderDescending()
|
||||
.Take(3)
|
||||
.Aggregate((acc, next) => acc * next);
|
||||
}
|
||||
|
||||
public long SolvePart2(string pathToPuzzleInput)
|
||||
{
|
||||
var points = ParsePuzzleInput(pathToPuzzleInput);
|
||||
|
||||
var pointPairs = GetAllCombinationsSortedByDistance(points);
|
||||
|
||||
var lastConnected = LastCombinedConnectAllCircuits(points, pointPairs);
|
||||
|
||||
return lastConnected.a.x * lastConnected.b.x;
|
||||
}
|
||||
|
||||
private List<List<Coordinate>> CombineCircuits(int amountToConnect, Coordinate[] points,
|
||||
(Coordinate pointA, Coordinate pointB)[] pointPairs)
|
||||
{
|
||||
var circuits = points.Select(p => new List<Coordinate>() { p }).ToList();
|
||||
for (var i = 0; i < amountToConnect; i++)
|
||||
{
|
||||
var next = pointPairs[i];
|
||||
circuits = AddToCircuits(next.pointA, next.pointB, circuits);
|
||||
}
|
||||
|
||||
return circuits;
|
||||
}
|
||||
|
||||
private (Coordinate a, Coordinate b) LastCombinedConnectAllCircuits(Coordinate[] points,
|
||||
(Coordinate pointA, Coordinate pointB)[] pointPairs)
|
||||
{
|
||||
var circuits = points.Select(p => new List<Coordinate>() { p }).ToList();
|
||||
(Coordinate a, Coordinate b) lastConnected = ((0, 0, 0), (0, 0, 0));
|
||||
var i = 0;
|
||||
while(circuits.Count > 1)
|
||||
{
|
||||
var next = pointPairs[i++];
|
||||
circuits = AddToCircuits(next.pointA, next.pointB, circuits);
|
||||
lastConnected = (next.pointA, next.pointB);
|
||||
}
|
||||
|
||||
return lastConnected;
|
||||
}
|
||||
|
||||
private double GetDistance(Coordinate a, Coordinate b)
|
||||
{
|
||||
return Math.Sqrt(Math.Pow(a.x - b.x, 2) + Math.Pow(a.y - b.y, 2) + Math.Pow(a.z - b.z, 2));
|
||||
}
|
||||
|
||||
private List<List<Coordinate>> AddToCircuits(Coordinate a, Coordinate b, List<List<Coordinate>> circuits)
|
||||
{
|
||||
var circuitToAddBTo = circuits.FirstOrDefault(circuit => circuit.Contains(a));
|
||||
var circuitToAddATo = circuits.FirstOrDefault(circuit => circuit.Contains(b));
|
||||
if (circuitToAddATo == null && circuitToAddBTo == null)
|
||||
{
|
||||
circuits.Add([a, b]);
|
||||
return circuits;
|
||||
}
|
||||
|
||||
if (circuitToAddATo == circuitToAddBTo)
|
||||
{
|
||||
return circuits;
|
||||
}
|
||||
|
||||
if (circuitToAddATo != null && circuitToAddBTo != null)
|
||||
{
|
||||
circuits.Remove(circuitToAddATo);
|
||||
circuits.Remove(circuitToAddBTo);
|
||||
circuits.Add([..circuitToAddATo, ..circuitToAddBTo]);
|
||||
return circuits;
|
||||
}
|
||||
|
||||
if (circuitToAddATo != null)
|
||||
{
|
||||
circuitToAddATo.Add(a);
|
||||
}
|
||||
else
|
||||
{
|
||||
circuitToAddBTo!.Add(b);
|
||||
}
|
||||
|
||||
return circuits;
|
||||
}
|
||||
|
||||
private (Coordinate pointA, Coordinate pointB)[] GetAllCombinationsSortedByDistance(Coordinate[] coordinates)
|
||||
{
|
||||
var combinations = Combinations(coordinates)
|
||||
.OrderBy(x => GetDistance(x.a, x.b))
|
||||
.ToArray();
|
||||
return combinations;
|
||||
}
|
||||
|
||||
private IEnumerable<(TValue a, TValue b)> Combinations<TValue>(IEnumerable<TValue> values)
|
||||
{
|
||||
var enumerated = values.ToArray();
|
||||
return enumerated
|
||||
.SelectMany((valueA, ix) => enumerated.Skip(ix + 1).Select(valueB => (valueA, valueB)));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue