ben
/
aoc
1
0
Fork 0

2015 day 20
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Ben Harris 2023-09-20 16:57:52 -04:00
parent b87e05fff0
commit e8b6d5026c
2 changed files with 37 additions and 2 deletions

View File

@ -25,6 +25,7 @@ public class Test2015
[DataRow(typeof(Day17), "1304", "18")]
[DataRow(typeof(Day18), "1061", "1006")]
[DataRow(typeof(Day19), "576", "207")]
[DataRow(typeof(Day20), "665280", "705600")]
public void CheckAllDays(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2);

View File

@ -5,11 +5,45 @@ namespace AOC2015;
/// </summary>
public sealed class Day20() : Day(2015, 20, "Infinite Elves and Infinite Houses")
{
private int _input;
public override void ProcessInput()
{
_input = int.Parse(Input.First());
}
public override object Part1() => "";
public override object Part1()
{
var houses = new int[1_000_000];
for (var i = 1; i < houses.Length; i++)
{
for (var j = i; j < houses.Length; j += i)
{
houses[j] += i * 10;
}
}
public override object Part2() => "";
for (var i = 1; i < houses.Length; i++)
{
if (houses[i] >= _input) return i;
}
return "";
}
public override object Part2()
{
var min = int.MaxValue;
var houses = new int[1_000_000];
for (var i = 1; i < houses.Length; i++)
{
for (int j = i, c = 0; j < houses.Length && c < 50; j += i, c++)
{
if ((houses[j] += i * 11) >= _input)
min = Math.Min(min, j);
}
}
return min;
}
}