start on day 19
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
dbd228d96d
commit
98f3016b47
|
@ -26,6 +26,7 @@ namespace aoc2019.test
|
||||||
[DataRow(typeof(Day15), "280", "400")]
|
[DataRow(typeof(Day15), "280", "400")]
|
||||||
[DataRow(typeof(Day16), "90744714", "82994322")]
|
[DataRow(typeof(Day16), "90744714", "82994322")]
|
||||||
[DataRow(typeof(Day17), "2804", "")]
|
[DataRow(typeof(Day17), "2804", "")]
|
||||||
|
[DataRow(typeof(Day19), "", "")]
|
||||||
public void TestAllDays(Type dayType, string part1, string part2)
|
public void TestAllDays(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
// create day instance
|
// create day instance
|
||||||
|
|
|
@ -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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,12 +16,12 @@ namespace aoc2019.lib
|
||||||
private long i;
|
private long i;
|
||||||
public Queue<long> input, output;
|
public Queue<long> input, output;
|
||||||
public long[] memory;
|
public long[] memory;
|
||||||
private long relbase;
|
private long relativeBase;
|
||||||
|
|
||||||
public IntCodeVM(string tape)
|
public IntCodeVM(string tape)
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
relbase = 0;
|
relativeBase = 0;
|
||||||
program = tape.Split(',').Select(long.Parse).ToArray();
|
program = tape.Split(',').Select(long.Parse).ToArray();
|
||||||
memory = program;
|
memory = program;
|
||||||
input = new Queue<long>();
|
input = new Queue<long>();
|
||||||
|
@ -33,7 +33,7 @@ namespace aoc2019.lib
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
relbase = 0;
|
relativeBase = 0;
|
||||||
memory = program;
|
memory = program;
|
||||||
input.Clear();
|
input.Clear();
|
||||||
output.Clear();
|
output.Clear();
|
||||||
|
@ -77,7 +77,7 @@ namespace aoc2019.lib
|
||||||
{
|
{
|
||||||
case 0: return MemGet(param);
|
case 0: return MemGet(param);
|
||||||
case 1: return param;
|
case 1: return param;
|
||||||
case 2: return MemGet(relbase + param);
|
case 2: return MemGet(relativeBase + param);
|
||||||
default: throw new Exception("invalid parameter mode");
|
default: throw new Exception("invalid parameter mode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ namespace aoc2019.lib
|
||||||
break;
|
break;
|
||||||
case 1: throw new Exception("cannot set in immediate mode");
|
case 1: throw new Exception("cannot set in immediate mode");
|
||||||
case 2:
|
case 2:
|
||||||
MemSet(relbase + param, val);
|
MemSet(relativeBase + param, val);
|
||||||
break;
|
break;
|
||||||
default: throw new Exception("invalid parameter mode");
|
default: throw new Exception("invalid parameter mode");
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ namespace aoc2019.lib
|
||||||
i += 4;
|
i += 4;
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
relbase += Get(1);
|
relativeBase += Get(1);
|
||||||
i += 2;
|
i += 2;
|
||||||
break;
|
break;
|
||||||
case 99:
|
case 99:
|
||||||
|
|
Loading…
Reference in New Issue