Created
December 2, 2020 17:36
-
-
Save slashinfty/cb86239c848abbd6e73cbddc9902ece4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const input = [1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,9,1,19,1,9,19,23,1,23,5,27,2,27,10,31,1,6,31,35,1,6,35,39,2,9,39,43,1,6,43,47,1,47,5,51,1,51,13,55,1,55,13,59,1,59,5,63,2,63,6,67,1,5,67,71,1,71,13,75,1,10,75,79,2,79,6,83,2,9,83,87,1,5,87,91,1,91,5,95,2,9,95,99,1,6,99,103,1,9,103,107,2,9,107,111,1,111,6,115,2,9,115,119,1,119,6,123,1,123,9,127,2,127,13,131,1,131,9,135,1,10,135,139,2,139,10,143,1,143,5,147,2,147,6,151,1,151,5,155,1,2,155,159,1,6,159,0,99,2,0,14,0]; | |
const a = [...input]; | |
a[1] = 12; | |
a[2] = 2; | |
let i = 0; | |
do { | |
if (a[i] === 1) a[a[i + 3]] = a[a[i + 1]] + a[a[i + 2]]; | |
else if (a[i] === 2) a[a[i + 3]] = a[a[i + 1]] * a[a[i + 2]]; | |
else if (a[i] === 99) break; | |
i += 4; | |
} while (true); | |
console.log(a[0]); | |
let noun, verb; | |
out: for (let n = 0; n < 100; n++) { | |
for (let v = 0; v < 100; v++) { | |
const b = [...input]; | |
b[1] = n; | |
b[2] = v; | |
let j = 0; | |
do { | |
if (b[j] === 1) b[b[j + 3]] = b[b[j + 1]] + b[b[j + 2]]; | |
else if (b[j] === 2) b[b[j + 3]] = b[b[j + 1]] * b[b[j + 2]]; | |
else if (b[j] === 99) break; | |
j += 4; | |
} while (true); | |
if (b[0] === 19690720) { | |
noun = n; | |
verb = v; | |
break out; | |
} | |
} | |
} | |
console.log(100 * noun + verb); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment