start on day 19
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Ben Harris 2020-12-16 20:10:05 -05:00
parent dbd228d96d
commit 98f3016b47
4 changed files with 42 additions and 6 deletions

View File

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

35
aoc2019/Day19.cs Normal file
View File

@ -0,0 +1,35 @@
using System.Linq;
using aoc2019.lib;
namespace aoc2019
{
public sealed class Day19 : Day
{
private readonly IntCodeVM vm;
public Day19() : base(19, "Tractor Beam")
{
vm = new IntCodeVM(Input.First());
}
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++;
}
return $"{count}";
}
public override string Part2()
{
return "";
}
}
}

View File

@ -16,12 +16,12 @@ namespace aoc2019.lib
private long i;
public Queue<long> input, output;
public long[] memory;
private long relbase;
private long relativeBase;
public IntCodeVM(string tape)
{
i = 0;
relbase = 0;
relativeBase = 0;
program = tape.Split(',').Select(long.Parse).ToArray();
memory = program;
input = new Queue<long>();
@ -33,7 +33,7 @@ namespace aoc2019.lib
public void Reset()
{
i = 0;
relbase = 0;
relativeBase = 0;
memory = program;
input.Clear();
output.Clear();
@ -77,7 +77,7 @@ namespace aoc2019.lib
{
case 0: return MemGet(param);
case 1: return param;
case 2: return MemGet(relbase + param);
case 2: return MemGet(relativeBase + param);
default: throw new Exception("invalid parameter mode");
}
}
@ -92,7 +92,7 @@ namespace aoc2019.lib
break;
case 1: throw new Exception("cannot set in immediate mode");
case 2:
MemSet(relbase + param, val);
MemSet(relativeBase + param, val);
break;
default: throw new Exception("invalid parameter mode");
}
@ -144,7 +144,7 @@ namespace aoc2019.lib
i += 4;
break;
case 9:
relbase += Get(1);
relativeBase += Get(1);
i += 2;
break;
case 99: