1
0
www.mikescher.com/www/statics/aoc/2019/02_solution-1.ts

30 lines
694 B
TypeScript
Raw Permalink Normal View History

2019-12-02 14:27:20 +01:00
namespace AdventOfCode2019_02_1
{
const DAY = 2;
const PROBLEM = 1;
export async function run()
{
let input = await AdventOfCode.getInput(DAY);
let automata = input.split(",").map(p => parseInt(p));
automata[1] = 12;
automata[2] = 2;
for(let i=0; i < automata.length; i+=4)
{
const op = automata[i+0];
const arg1 = automata[automata[i+1]];
const arg2 = automata[automata[i+2]];
const dest = automata[i+3];
2019-12-16 14:47:03 +01:00
AdventOfCode.outputConsole("["+dest+"] <- "+arg1+" {"+op+"} "+arg2)
2019-12-02 14:27:20 +01:00
if (op==1) automata[dest] = arg1 + arg2;
else if (op==2) automata[dest] = arg1 * arg2;
else break;
}
AdventOfCode.output(DAY, PROBLEM, automata[0].toString());
}
}