2019 day 2 + some other stuff
This commit is contained in:
parent
6facbd56de
commit
12d0551bb4
5 changed files with 70 additions and 13 deletions
27
2019/02/part2.js
Normal file
27
2019/02/part2.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const fs = require("fs");
|
||||
const text = fs.readFileSync("./input.txt", "utf-8");
|
||||
|
||||
for (let noun = 0; noun < text.split(',').length; noun++){
|
||||
|
||||
for (let verb = 0; verb < text.split(',').length; verb++){
|
||||
|
||||
let memory = text.split(',').map(opcode => parseInt(opcode));
|
||||
|
||||
memory[1] = noun;
|
||||
memory[2] = verb;
|
||||
|
||||
for (let i = 0; i < memory.length; i+=4) {
|
||||
if (memory[i] == 1) {
|
||||
memory[memory[i+3]] = memory[memory[i+1]] + memory[memory[i+2]];
|
||||
} else if (memory[i] == 2) {
|
||||
memory[memory[i+3]] = memory[memory[i+1]] * memory[memory[i+2]];
|
||||
} else if (memory[i] == 99) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (memory[0] == 19690720){
|
||||
console.log(noun, verb);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue