about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2019-12-09 14:10:13 -0500
committerBen Harris <ben@tilde.team>2019-12-09 14:10:13 -0500
commit663d31564adf3d0714247a091021743ba0876e27 (patch)
tree2fb23ccd5687dcafe907bb8e9acefed3603341a8
parenteb284a98c6febe943c81dc529d881f2a9752ee74 (diff)
move input parsing into vm class
-rw-r--r--Day7.cs3
-rw-r--r--Day9.cs2
-rw-r--r--lib/IntCodeVM.cs6
3 files changed, 5 insertions, 6 deletions
diff --git a/Day7.cs b/Day7.cs
index 9391bdb..af66d03 100644
--- a/Day7.cs
+++ b/Day7.cs
@@ -12,8 +12,7 @@ namespace aoc2019
         private readonly IntCodeVM[] Amplifiers = new IntCodeVM[5];
         public Day7()
         {
-            var input = Input.First().Split(',').Select(long.Parse);
-            for (var i = 0; i < 5; i++) Amplifiers[i] = new IntCodeVM(input);
+            for (var i = 0; i < 5; i++) Amplifiers[i] = new IntCodeVM(Input.First());
         }
 
         
diff --git a/Day9.cs b/Day9.cs
index 3f76256..8f21e3d 100644
--- a/Day9.cs
+++ b/Day9.cs
@@ -12,7 +12,7 @@ namespace aoc2019
 
         public Day9()
         {
-            vm = new IntCodeVM(Input.First().Split(',').Select(long.Parse));
+            vm = new IntCodeVM(Input.First());
         }
 
         public override string Part1()
diff --git a/lib/IntCodeVM.cs b/lib/IntCodeVM.cs
index f7699c6..b42a907 100644
--- a/lib/IntCodeVM.cs
+++ b/lib/IntCodeVM.cs
@@ -12,12 +12,12 @@ namespace aoc2019.lib
         private readonly long[] program;
         public Queue<long> input, output;
 
-        public IntCodeVM(IEnumerable<long> tape)
+        public IntCodeVM(string tape)
         {
             i = 0;
             relbase = 0;
-            program = tape.ToArray();
-            memory = tape.ToArray();
+            program = tape.Split(',').Select(long.Parse).ToArray();
+            memory = program;
             input = new Queue<long>();
             output = new Queue<long>();
         }