about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-12-16 20:10:05 -0500
committerBen Harris <ben@tilde.team>2020-12-16 20:10:20 -0500
commit98f3016b477077a8478895b67ee37af71ae68717 (patch)
treea16c16b187caa6843a2d23fc632f391ccede2faa
parentdbd228d96d1b65ba71f0def1be0c28084bd82c27 (diff)
start on day 19
-rw-r--r--README.md (renamed from aoc2019/README.md)0
-rw-r--r--aoc2019.test/Tests.cs1
-rw-r--r--aoc2019/Day19.cs35
-rw-r--r--aoc2019/lib/IntCodeVM.cs12
4 files changed, 42 insertions, 6 deletions
diff --git a/aoc2019/README.md b/README.md
index 0e6fdc8..0e6fdc8 100644
--- a/aoc2019/README.md
+++ b/README.md
diff --git a/aoc2019.test/Tests.cs b/aoc2019.test/Tests.cs
index 8e8d0f9..61f9093 100644
--- a/aoc2019.test/Tests.cs
+++ b/aoc2019.test/Tests.cs
@@ -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
diff --git a/aoc2019/Day19.cs b/aoc2019/Day19.cs
new file mode 100644
index 0000000..73d3e22
--- /dev/null
+++ b/aoc2019/Day19.cs
@@ -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 "";
+        }
+    }
+}
diff --git a/aoc2019/lib/IntCodeVM.cs b/aoc2019/lib/IntCodeVM.cs
index 2190579..4fb196f 100644
--- a/aoc2019/lib/IntCodeVM.cs
+++ b/aoc2019/lib/IntCodeVM.cs
@@ -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: