about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Day15.cs2
-rw-r--r--Day17.cs57
-rw-r--r--lib/IntCodeVM.cs5
3 files changed, 63 insertions, 1 deletions
diff --git a/Day15.cs b/Day15.cs
index 367b1fc..f10b547 100644
--- a/Day15.cs
+++ b/Day15.cs
@@ -7,8 +7,8 @@ namespace aoc2019
 {
     internal sealed class Day15 : Day
     {
-        private readonly IntCodeVM vm;
         private readonly bool verbose = false;
+        private readonly IntCodeVM vm;
 
         public Day15()
         {
diff --git a/Day17.cs b/Day17.cs
new file mode 100644
index 0000000..f9da08a
--- /dev/null
+++ b/Day17.cs
@@ -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 "";
+        }
+    }
+}
\ No newline at end of file
diff --git a/lib/IntCodeVM.cs b/lib/IntCodeVM.cs
index d35444b..2190579 100644
--- a/lib/IntCodeVM.cs
+++ b/lib/IntCodeVM.cs
@@ -39,6 +39,11 @@ namespace aoc2019.lib
             output.Clear();
         }
 
+        public void AddInput(params long[] values)
+        {
+            foreach (var v in values) AddInput(v);
+        }
+
         public void AddInput(long value)
         {
             input.Enqueue(value);