Published
Edited
Dec 23, 2018
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
part1 = {
let register = [0, 0, 0, 0, 0, 0];

while (register[IP_REGISTER] < INSTRUCTIONS.length && register[IP_REGISTER] >= 0) {
if (register[IP_REGISTER] === 28) {
return register[5];
}

const [currentInstruction, a, b, c] = INSTRUCTIONS[register[IP_REGISTER]];
calculate[currentInstruction](register, a, b, c);
register[IP_REGISTER]++;
}
}
Insert cell
Insert cell
part2 = {
// Too slow to run in browser without reverse engineering the ElfCode
let B, E;
let prev;
let seen = new Set();
B = 65536;
E = 7571367;

while (true) {
E += B & 255;
E &= 16777215;
E *= 65899;
E &= 16777215;

if (B < 256) {
// Find the last new value of E during instruction 28 before it cycles
// That will be the last hit, so setting r[0] to its value results
// in the most instructions among all possible terminating values.
if (seen.has(E)) {
return prev;
} else {
seen.add(E);
prev = E;
}
B = E | 65536;
E = 7571367;
} else {
B = Math.floor(B / 256);
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more