Published
Edited
Dec 3, 2019
1 fork
1 star
Insert cell
Insert cell
part2 = 100 * 67 + 18
Insert cell
attempt(67, 18)
Insert cell
19690720
Insert cell
function attempt(noun, verb) {
const program = input.slice();
program[1] = noun;
program[2] = verb;
return run(program)[0];
}
Insert cell
part1 = attempt(12, 2)
Insert cell
function run(memory) {
let ip = 0,
opcode;
while ((opcode = memory[ip]) !== 99) {
const instruction = instructions[opcode];
if (instruction) {
const length = instruction.length + 1;
instruction.apply(memory, memory.slice(ip + 1, ip + length));
ip += length;
} else {
return ["illegal opcode", opcode, ip];
}
}
return memory;
}
Insert cell
instructions = ({
1(lhs, rhs, dest) {
this[dest] = this[lhs] + this[rhs];
},
2(lhs, rhs, dest) {
this[dest] = this[lhs] * this[rhs];
}
})
Insert cell
run(`1,1,1,4,99,5,6,0,99`.split(',').map(Number))
Insert cell
input = `1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,6,19,23,2,23,6,27,1,5,27,31,1,10,31,35,2,6,35,39,1,39,13,43,1,43,9,47,2,47,10,51,1,5,51,55,1,55,10,59,2,59,6,63,2,6,63,67,1,5,67,71,2,9,71,75,1,75,6,79,1,6,79,83,2,83,9,87,2,87,13,91,1,10,91,95,1,95,13,99,2,13,99,103,1,103,10,107,2,107,10,111,1,111,9,115,1,115,2,119,1,9,119,0,99,2,0,14,0`
.split(',')
.map(Number)
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