day 19
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Ben Harris 2020-12-16 20:54:26 -05:00
parent 98f3016b47
commit 34d27fd823
Signed by: ben
GPG Key ID: 4E0AF802FFF7960C
2 changed files with 24 additions and 10 deletions

View File

@ -26,7 +26,7 @@ namespace aoc2019.test
[DataRow(typeof(Day15), "280", "400")]
[DataRow(typeof(Day16), "90744714", "82994322")]
[DataRow(typeof(Day17), "2804", "")]
[DataRow(typeof(Day19), "", "")]
[DataRow(typeof(Day19), "114", "10671712")]
public void TestAllDays(Type dayType, string part1, string part2)
{
// create day instance

View File

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using aoc2019.lib;
namespace aoc2019
@ -6,30 +7,43 @@ namespace aoc2019
public sealed class Day19 : Day
{
private readonly IntCodeVM vm;
private readonly long[,] grid;
public Day19() : base(19, "Tractor Beam")
{
vm = new IntCodeVM(Input.First());
grid = new long[50, 50];
}
public override string Part1()
{
var count = 0;
for (var x = 0; x < 50; x++)
for (var y = 0; y < 50; y++)
{
vm.AddInput(x, y);
vm.Run();
if (vm.Result == 1) count++;
vm.Reset();
vm.Run(x, y);
grid[x, y] = vm.Result;
}
return $"{count}";
return $"{grid.Cast<long>().Sum()}";
}
public override string Part2()
{
return "";
for (int x = 101, y = 0;; x++)
{
while (true)
{
vm.Reset();
vm.Run(x, y);
if (vm.Result == 1) break;
y++;
}
vm.Reset();
vm.Run(x - 99, y + 99);
if (vm.Result == 1)
return $"{(x - 99) * 1e4 + y}";
}
}
}
}