Browse Source

Upload final solution

ApisNecros 1 year ago
parent
commit
5157c65456
1 changed files with 14 additions and 9 deletions
  1. 14 9
      7/7_1.js

+ 14 - 9
7/7_1.js

@@ -1,6 +1,7 @@
 const Computer = require("../IntComp/Computer");
+const InputModes = require("../IntComp/InputModes");
 
-const input = [];
+const input = [3, 8, 1001, 8, 10, 8, 105, 1, 0, 0, 21, 46, 55, 68, 89, 110, 191, 272, 353, 434, 99999, 3, 9, 1002, 9, 3, 9, 1001, 9, 3, 9, 102, 4, 9, 9, 101, 4, 9, 9, 1002, 9, 5, 9, 4, 9, 99, 3, 9, 102, 3, 9, 9, 4, 9, 99, 3, 9, 1001, 9, 5, 9, 102, 4, 9, 9, 4, 9, 99, 3, 9, 1001, 9, 5, 9, 1002, 9, 2, 9, 1001, 9, 5, 9, 1002, 9, 3, 9, 4, 9, 99, 3, 9, 101, 3, 9, 9, 102, 3, 9, 9, 101, 3, 9, 9, 1002, 9, 4, 9, 4, 9, 99, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1001, 9, 2, 9, 4, 9, 3, 9, 1001, 9, 2, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 1001, 9, 2, 9, 4, 9, 99, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 99, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 99, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 1001, 9, 2, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 99, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 101, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 99];
 
 const demos = [
     [3, 15, 3, 16, 1002, 16, 10, 16, 1, 16, 15, 15, 4, 15, 99, 0, 0],
@@ -12,8 +13,9 @@ const demos = [
 const AMPLIFIER_COUNT = 5;
 const amplifierArray = [];
 for (let i = 0; i < AMPLIFIER_COUNT; i++) {
-    amplifierArray.push(new Computer(demos[0]));
+    amplifierArray.push(new Computer(input, { inputModeMap: [InputModes.INPUT_FROM_RUNTIME_STACK, InputModes.INPUT_FROM_RUNTIME_STACK] }));
 }
+// amplifierArray[4].options.outputToConsole = true;
 
 const amplifierConfigurations = permute([...Array(5).keys()]);
 
@@ -21,15 +23,20 @@ let maxOutput = -999;
 for (const configuration of amplifierConfigurations) {
     amplifierArray.forEach((comp) => comp.Reset());
 
-    for (let i = 0; i < AMPLIFIER_COUNT - 1; i++) {
-        amplifierArray[configuration[i]].outputComputer = amplifierArray[configuration[i - 1]];
-    }
+    let amplifierOutput = 0;
+    for (let i = 0; i < AMPLIFIER_COUNT; i++) {
+        amplifierArray[i].RunWithInput([configuration[i], amplifierOutput]);
 
-    amplifierArray[configuration[0]].RunWithInput();
+        amplifierOutput = amplifierArray[i].FetchOutputValue();
+    }
 
-    const finalOutput = amplifierArray[AMPLIFIER_COUNT - 1].FetchOutputValue();
+    if (amplifierOutput > maxOutput) {
+        maxOutput = amplifierOutput;
+    }
 }
 
+console.log(`Largest output: ${maxOutput}`);
+
 /**
  * Create an array of all permutations of another array
  *
@@ -61,5 +68,3 @@ function permute(permutation) {
     }
     return result;
 }
-
-console.log(amplifierConfigurations);