In the browser!
function process(one, two) { let pretext = document.getElementsByTagName('pre')[0].innerHTML; let instructions = pretext.split(',').map(i => parseInt(i, 10)); instructions[1] = one; instructions[2] = two; for(let i = 0; i < instructions.length; i += 4) { let inst = instructions[i]; if(inst == 99) { break; } let answerPos = instructions[i+3]; let ai = instructions[i+1]; let bi = instructions[i+2]; if(inst == 1) { instructions[answerPos] = instructions[ai] + instructions[bi]; } else if(inst == 2) { instructions[answerPos] = instructions[ai] * instructions[bi]; } } return instructions[0]; } /* part 2 */ let done = false; for(let a = 0; a < 100 && !done; a++) { for(let b = 0; b < 100; b++) { let n = process(a, b); if(n == 19690720) { console.log(a, b) done = true; break; } } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a blogging-forward open source social network where we learn from one another
In the browser!