1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- const Computer = require("../IntComp/Computer");
- const input = [1, 12, 0, 3, 1, 1, 2, 3, 1, 3, 4, 3, 1, 5, 0, 3, 2, 1, 13, 19, 1, 9, 19, 23, 1, 6, 23, 27, 2, 27, 9, 31, 2, 6, 31, 35, 1, 5, 35, 39, 1, 10, 39, 43, 1, 43, 13, 47, 1, 47, 9, 51, 1, 51, 9, 55, 1, 55, 9, 59, 2, 9, 59, 63, 2, 9, 63, 67, 1, 5, 67, 71, 2, 13, 71, 75, 1, 6, 75, 79, 1, 10, 79, 83, 2, 6, 83, 87, 1, 87, 5, 91, 1, 91, 9, 95, 1, 95, 10, 99, 2, 9, 99, 103, 1, 5, 103, 107, 1, 5, 107, 111, 2, 111, 10, 115, 1, 6, 115, 119, 2, 10, 119, 123, 1, 6, 123, 127, 1, 127, 5, 131, 2, 9, 131, 135, 1, 5, 135, 139, 1, 139, 10, 143, 1, 143, 2, 147, 1, 147, 5, 0, 99, 2, 0, 14, 0];
- const demos = [
- [1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50],
- [1, 0, 0, 0, 99],
- [2, 3, 0, 3, 99],
- [2, 4, 4, 5, 99, 0],
- [1, 1, 1, 4, 99, 5, 6, 0, 99],
- ];
- function CalculateNounPlusVerb(noun, verb, expected) {
- const freshMemory = JSON.parse(JSON.stringify(input));
- freshMemory[1] = noun;
- freshMemory[2] = verb;
- const comp = new Computer(freshMemory);
- comp.Run();
- return comp.stack.GetAtIndex(0, 1) == expected;
- }
- function LoopNounsAndVerbs() {
- const EXPECTED = 19690720;
- let noun = 0;
- let verb = 0;
- for (noun = 0; noun < 100; noun++) {
- for (verb = 0; verb < 100; verb++) {
- if (CalculateNounPlusVerb(noun, verb, EXPECTED)) {
- return 100 * noun + verb;
- }
- }
- }
- return false;
- }
- const output = LoopNounsAndVerbs();
- if (output !== false) {
- console.log(`Answer: ${output}`);
- }
- else {
- console.log("Couldn't find answer");
- }
- // computer.DumpMemory();
|