day17 part1
continuous-integration/drone/push Build was killed
Details
continuous-integration/drone/push Build was killed
Details
This commit is contained in:
parent
4c8483fe7a
commit
c66d1d6b33
2
Day15.cs
2
Day15.cs
|
@ -7,8 +7,8 @@ namespace aoc2019
|
||||||
{
|
{
|
||||||
internal sealed class Day15 : Day
|
internal sealed class Day15 : Day
|
||||||
{
|
{
|
||||||
private readonly IntCodeVM vm;
|
|
||||||
private readonly bool verbose = false;
|
private readonly bool verbose = false;
|
||||||
|
private readonly IntCodeVM vm;
|
||||||
|
|
||||||
public Day15()
|
public Day15()
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using aoc2019.lib;
|
||||||
|
|
||||||
|
namespace aoc2019
|
||||||
|
{
|
||||||
|
internal sealed class Day17 : Day
|
||||||
|
{
|
||||||
|
private const bool Verbose = false;
|
||||||
|
|
||||||
|
private readonly IntCodeVM vm;
|
||||||
|
|
||||||
|
public Day17()
|
||||||
|
{
|
||||||
|
vm = new IntCodeVM(Input.First());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int DayNumber => 17;
|
||||||
|
|
||||||
|
protected override string Part1()
|
||||||
|
{
|
||||||
|
vm.Reset();
|
||||||
|
vm.Run();
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
while (vm.output.Any())
|
||||||
|
sb.Append((char) vm.Result);
|
||||||
|
if (Verbose) Console.Write(sb);
|
||||||
|
var grid = sb.ToString().Trim().Split().Select(s => s.ToCharArray()).ToArray();
|
||||||
|
|
||||||
|
var sum = 0;
|
||||||
|
for (var y = 1; y < grid.Length - 1; y++)
|
||||||
|
for (var x = 1; x < grid[y].Length - 1; x++)
|
||||||
|
if (grid[y][x] == '#' &&
|
||||||
|
grid[y - 1][x] == '#' &&
|
||||||
|
grid[y + 1][x] == '#' &&
|
||||||
|
grid[y][x - 1] == '#' &&
|
||||||
|
grid[y][x + 1] == '#')
|
||||||
|
sum += x * y;
|
||||||
|
|
||||||
|
return $"{sum}";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Part2()
|
||||||
|
{
|
||||||
|
vm.Reset();
|
||||||
|
vm.memory[0] = 2;
|
||||||
|
var halt = IntCodeVM.HaltType.Waiting;
|
||||||
|
while (halt == IntCodeVM.HaltType.Waiting)
|
||||||
|
{
|
||||||
|
halt = vm.Run();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,11 @@ namespace aoc2019.lib
|
||||||
output.Clear();
|
output.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddInput(params long[] values)
|
||||||
|
{
|
||||||
|
foreach (var v in values) AddInput(v);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddInput(long value)
|
public void AddInput(long value)
|
||||||
{
|
{
|
||||||
input.Enqueue(value);
|
input.Enqueue(value);
|
||||||
|
|
Loading…
Reference in New Issue