2015 day 17
This commit is contained in:
parent
f7a25d42cc
commit
adfbbf1b0a
|
@ -22,6 +22,7 @@ public class Test2015
|
|||
[DataRow(typeof(Day14), "2655", "1059")]
|
||||
[DataRow(typeof(Day15), "222870", "117936")]
|
||||
[DataRow(typeof(Day16), "103", "405")]
|
||||
[DataRow(typeof(Day17), "1304", "18")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
|
|
|
@ -5,15 +5,26 @@ namespace AOC2015;
|
|||
/// </summary>
|
||||
public sealed class Day17 : Day
|
||||
{
|
||||
private List<int>? _containers;
|
||||
private IEnumerable<List<int>>? _combinations;
|
||||
|
||||
public Day17() : base(2015, 17, "No Such Thing as Too Much")
|
||||
{
|
||||
}
|
||||
|
||||
public override void ProcessInput()
|
||||
{
|
||||
_containers = Input.Select(int.Parse).ToList();
|
||||
_combinations = Enumerable.Range(1, (1 << _containers.Count) - 1)
|
||||
.Select(i => _containers.Where((_, index) => ((1 << index) & i) != 0).ToList());
|
||||
}
|
||||
|
||||
public override object Part1() => "";
|
||||
public override object Part1() => _combinations!.Count(c => c.Sum() == 150);
|
||||
|
||||
public override object Part2() => "";
|
||||
public override object Part2()
|
||||
{
|
||||
var successfulCombinations = _combinations!.Where(c => c.Sum() == 150).ToList();
|
||||
var minCount = successfulCombinations.Min(c => c.Count);
|
||||
return successfulCombinations.Count(c => c.Count == minCount);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue