aoc 1+2
This commit is contained in:
29
www/statics/aoc/2019/02_solution-1.ts
Normal file
29
www/statics/aoc/2019/02_solution-1.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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];
|
||||
console.log("["+dest+"] <- "+arg1+" {"+op+"} "+arg2)
|
||||
if (op==1) automata[dest] = arg1 + arg2;
|
||||
else if (op==2) automata[dest] = arg1 * arg2;
|
||||
else break;
|
||||
}
|
||||
|
||||
AdventOfCode.output(DAY, PROBLEM, automata[0].toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user