Public
Edited
Nov 23, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
function nounVerbProg(prog, noun, verb) {
return new Computer([], prog).poke(1, noun).poke(2, verb).run().mem[0];
}
Insert cell
function part1(input) {
return nounVerbProg(input, 12, 2);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
for (let n = 0; n < 100; n++) {
for (let v = 0; v < 100; v++) {
if (nounVerbProg(puzzleInput, Number(n), Number(v)) === target) {
return n * 100 + v;
}
}
}
return "no match found";
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part2Algebraic(input) {
const [x0y0, x0y1, x1y0] = [
[0, 0],
[0, 1],
[1, 0]
].map(([n, v]) => nounVerbProg(input, n, v));
const dx = x1y0 - x0y0;
const dy = x0y1 - x0y0;
const noun = Math.floor((target - x0y0) / dx);
const verb = Math.floor((target - x0y0 - dx * noun) / dy);
return noun * 100 + verb;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more