Published
Edited
Dec 3, 2019
1 star
Insert cell
Insert cell
Insert cell
Insert cell
answer(12,2)
Insert cell
answer = function (noun, verb) {
let input = puzzleInput.split(",");
input[1] = noun;
input[2] = verb;
return intcomp(input)[0]
}
Insert cell
function intcomp (a) {
let out = a.map(v=>v*1.0);
let v, x, y1, y2, p, i;
for (i=0; i<a.length; i += 4) {
v = out[i];
if (v == 99) break
y1 = out[out[i+1]]; y2 = out[out[i+2]]; p = out[i+3];
if (v == 1) x = y1 + y2;
else if (v == 2) x = y1 * y2;
else x = -999;
out[p] = x;
}
return out
}
Insert cell
intcomp('1,0,0,0,99'.split(","))
Insert cell
function sum (a) { return a.reduce((a,b)=>a+b,0) }
Insert cell
Insert cell
find = {
let verb, noun;
for (verb = 0; verb < 100; verb++) {
for (noun = 0; noun < 100; noun++) {
if (answer(noun, verb) == 19690720) return 100 * noun + verb;
}
}
return 'not found'
}
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