Created
December 5, 2019 16:53
-
-
Save lovasoa/8a4c3f1bf7b617b0e3085f409e5fb916 to your computer and use it in GitHub Desktop.
Advent of code 2019 VM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exec(a,b){ | |
let pgm = document.body.innerText.split(',').map(x=>parseInt(x)); | |
pgm[1] = a; pgm[2] = b; | |
for(let p=0; ; p+= 4){ | |
if(pgm[p]==1) pgm[pgm[p+3]] = pgm[pgm[p+1]] + pgm[pgm[p+2]]; | |
else if(pgm[p]==2) pgm[pgm[p+3]] = pgm[pgm[p+1]] * pgm[pgm[p+2]]; | |
else if(pgm[p]==99) break; | |
else throw new Error("invalid opcode "+pgm[p]); | |
} | |
return pgm[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment