-
Notifications
You must be signed in to change notification settings - Fork 0
/
09.ts
32 lines (28 loc) · 826 Bytes
/
09.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {IntcodeComputer} from './intcode';
import {parseIntcode} from './utils';
/*
https://adventofcode.com/2020/day/1
*/
export const part1 = (program: Array<number>): number => {
const computer = new IntcodeComputer([...program]);
computer.addInput(1);
const outputs = [];
while (!computer.isHalted()) {
outputs.push(computer.run());
}
return outputs[outputs.length - 1]!;
};
export const part2 = (program: Array<number>): number => {
const computer = new IntcodeComputer([...program]);
computer.addInput(2);
const outputs = [];
while (!computer.isHalted()) {
outputs.push(computer.run());
}
return outputs[outputs.length - 1]!;
};
/**
* Parse the puzzle input file ready for processing
*/
/* istanbul ignore next */
export const parse = (): Promise<Array<number>> => parseIntcode(9);