Compare commits

..

No commits in common. "main" and "2019" have entirely different histories.
main ... 2019

120 changed files with 1635600 additions and 3896 deletions

3
.gitignore vendored
View file

@ -1,2 +1 @@
node_modules/
yarn-*.cjs
**/node_modules/

View file

@ -0,0 +1,100 @@
74099
50130
81867
55356
73088
73706
55902
113399
129578
78051
117663
137454
66285
115389
50547
51588
115792
91085
118882
109486
135616
107771
90105
101182
54766
86615
91261
104321
121607
82197
68626
111255
136080
87509
70125
91180
75925
53492
96853
115081
121621
87461
116030
67335
61282
112424
106785
142243
110564
56983
131420
116534
117376
147088
117628
53964
73163
106736
76217
128590
116138
66841
109265
106285
64013
78357
125640
145761
139426
127558
135076
130989
68054
134669
144482
125870
112818
60193
107162
112557
115972
50890
148652
89547
120228
85967
103941
130915
129496
66401
87018
149539
105847
60981
82610
134396
121711
142655
104400
103752

View file

@ -0,0 +1,16 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.6",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,20 @@
import * as fs from "fs";
import * as readline from "readline";
async function main() {
const readStream = fs.createReadStream("input");
const lines = readline.createInterface(readStream);
const fuelReqs: number[] = [];
for await (const line of lines) {
const mass = parseInt(line, 10);
if (isNaN(mass)) {
throw new Error(`Invalid value ${mass}`);
}
fuelReqs.push(Math.floor(mass / 3) - 2);
}
return fuelReqs.reduce((x, y, i) => x + y);
}
main().then(console.log);

View file

@ -0,0 +1,25 @@
import * as fs from "fs";
import * as readline from "readline";
async function main() {
const readStream = fs.createReadStream("input");
const lines = readline.createInterface(readStream);
const fuelReqs: number[] = [];
for await (const line of lines) {
let mass = parseInt(line, 10);
if (isNaN(mass)) {
throw new Error(`Invalid value ${mass}`);
}
mass = Math.floor(mass / 3) - 2;
while (mass > 0) {
fuelReqs.push(mass);
mass = Math.floor(mass / 3) - 2;
}
}
return fuelReqs.reduce((x, y) => x + y, 0);
}
main().then(console.log);

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.6":
version "14.14.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,205 @@
// @link https://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations
function gcd(a: number, b: number): number {
if (b === 0) return a;
return gcd(b, a % b);
}
/**
* Given an x,y point, returns an angle 0-360
* such that the top of the circle is 0, and then
* we rotate clockwise.
*
* So in the below ascii circle, if you start at
* point `0`, then you'll visit the points 1, 2, 3,
* etc., in order.
*
* 9 0 1
* 8 2
* 7 3
* 6 5 4
*
* In addition, my plane has negative y's going up
* and positive y's going down.
*
* -y ^
* |
* -x <---+---> +x
* |
* +y v
*/
function coordToAngle([x, y]: [number, number]) {
let deg = (Math.atan2(-y, x) * 180) / Math.PI;
// Pretty sure this can be simplified with a modulus, but can't see it
if (deg <= 90 && deg >= 0) {
deg = Math.abs(deg - 90);
} else if (deg < 0) {
deg = Math.abs(deg) + 90;
} else {
deg = 450 - deg;
}
return deg;
}
export class Grid {
min_x: number;
min_y: number;
max_x: number;
max_y: number;
grid: number[][]; // @TODO
asteroids: [number, number][];
constructor(input: (1|0)[][]) {
// `1` is an asteroid, `0` is open space
this.grid = JSON.parse(JSON.stringify(input));
this.asteroids = this.getAsteroidsList();
this.min_x = 0;
this.min_y = 0;
this.max_x = this.grid[0].length - 1;
this.max_y = this.grid.length - 1;
}
getAsteroidsList() {
let asteroids: [number, number][] = [];
for (let y = 0; y < this.grid.length; y++) {
for (let x = 0; x < this.grid[y].length; x++) {
if (this.grid[y][x]) {
asteroids.push([x, y]);
}
}
}
return asteroids;
}
getVectorsFromPoint(coord: [number, number], sorted_clockwise = false) {
let slopes: Record<string, boolean> = {};
const [x1, y1] = coord;
// This isn't optimized (its O(n^2)) but it works for grids of this size.
for (let y2 = 0; y2 <= this.max_y; y2++) {
for (let x2 = 0; x2 <= this.max_x; x2++) {
if (x1 === x2 && y1 === y2) {
continue;
}
let dy = y2 - y1;
let dx = x2 - x1;
let divisor = Math.abs(gcd(dy, dx));
dy /= divisor;
dx /= divisor;
// Technically I'm storing inverse slopes of `x/y` but that is so my `map` function below spits out `[x, y]` coords
slopes[`${dx}/${dy}`] = true;
}
}
const vectors_to_travel = Object.keys(slopes).map((slope_str) =>
slope_str.split("/").map((v) => parseInt(v, 10))
) as [number, number][];
if (sorted_clockwise) {
vectors_to_travel.sort((p1, p2) => {
let p1_d = coordToAngle(p1);
let p2_d = coordToAngle(p2);
return p1_d - p2_d;
});
}
return vectors_to_travel;
}
// Part one
getAsteroidWithHighestCountInLineOfSight() {
let best_count = -1;
let best_coords = null;
for (let asteroid of this.asteroids) {
let vectors = this.getVectorsFromPoint(asteroid);
let count = vectors
.map((vector) => (this.getCollisionAlongVector(asteroid, vector) ? 1 : 0))
.reduce((a: number, b) => a + b, 0);
if (count > best_count) {
best_count = count;
best_coords = asteroid;
}
}
return {
best_count,
best_coords,
};
}
// Part two
vaporizeAsteroidsFrom(start_from: [number, number] | null): number {
if (!start_from) {
({ best_coords: start_from } = this.getAsteroidWithHighestCountInLineOfSight());
const throw_error = (): [number, number] => {
throw new Error("start_from is null");
};
start_from = start_from ?? throw_error();
}
let total_vaporized = 0;
let vaporized = [];
do {
let clockwise_vectors_from_start = this.getVectorsFromPoint(start_from, true);
for (let vector of clockwise_vectors_from_start) {
let collision_coord = this.getCollisionAlongVector(start_from, vector);
if (collision_coord) {
total_vaporized++;
this.vaporize(collision_coord);
vaporized.push(collision_coord);
}
if (total_vaporized === 200) {
let [x, y] = collision_coord ?? [0, 0];
return x * 100 + y;
}
}
// } while (this.sumAllAsteroids() > 1);
} while (total_vaporized < 200);
return -Infinity;
}
getCollisionAlongVector(from: [number, number], vector: [number, number]) {
let collision_coord: [number, number] | null = null;
const [x, y] = from;
const [vx, vy] = vector;
let new_x = x + vx;
let new_y = y + vy;
while (this.pointInGrid(new_x, new_y)) {
if (this.grid[new_y][new_x]) {
collision_coord = [new_x, new_y];
break;
}
new_x += vx;
new_y += vy;
}
return collision_coord;
}
vaporize([x, y]: [number, number]) {
this.grid[y][x] = 0;
}
pointInGrid(x: number, y: number) {
return x >= this.min_x && x <= this.max_x && y >= this.min_y && y <= this.max_y;
}
sumAllAsteroids() {
let sum = 0;
for (let y = 0; y < this.grid.length; y++) {
for (let x = 0; x < this.grid[y].length; x++) {
sum += this.grid[y][x];
}
}
return sum;
}
}

View file

@ -0,0 +1,36 @@
....#...####.#.#...........#........
#####..#.#.#......#####...#.#...#...
##.##..#.#.#.....#.....##.#.#..#....
...#..#...#.##........#..#.......#.#
#...##...###...###..#...#.....#.....
##.......#.....#.........#.#....#.#.
..#...#.##.##.....#....##..#......#.
..###..##..#..#...#......##...#....#
##..##.....#...#.#...#......#.#.#..#
...###....#..#.#......#...#.......#.
#....#...##.......#..#.......#..#...
#...........#.....#.....#.#...#.##.#
###..#....####..#.###...#....#..#...
##....#.#..#.#......##.......#....#.
..#.#....#.#.#..#...#.##.##..#......
...#.....#......#.#.#.##.....#..###.
..#.#.###.......#..#.#....##.....#..
.#.#.#...#..#.#..##.#..........#...#
.....#.#.#...#..#..#...###.#...#.#..
#..#..#.....#.##..##...##.#.....#...
....##....#.##...#..........#.##....
...#....###.#...##........##.##..##.
#..#....#......#......###...........
##...#..#.##.##..##....#..#..##..#.#
.#....#..##.....#.#............##...
.###.........#....#.##.#..#.#..#.#..
#...#..#...#.#.#.....#....#......###
#...........##.#....#.##......#.#..#
....#...#..#...#.####...#.#..#.##...
......####.....#..#....#....#....#.#
.##.#..###..####...#.......#.#....#.
#.###....#....#..........#.....###.#
...#......#....##...##..#..#...###..
..#...###.###.........#.#..#.#..#...
.#.#.............#.#....#...........
..#...#.###...##....##.#.#.#....#.#.

View file

@ -0,0 +1,16 @@
{
"scripts": {
"lint": "prettier grid.ts solution_a.ts solution_b.ts --write --print-width=120",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.8",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,12 @@
import {Grid} from './grid'
import * as fs from "fs";
const input = fs.readFileSync("input").toString()
.split('\n')
.map(row => row.split('').map(v => (v === '#' ? 1 : 0)));
async function main() {
const grid = new Grid(input)
return grid.getAsteroidWithHighestCountInLineOfSight()
}
main().then(console.log).catch(console.error);

View file

@ -0,0 +1,12 @@
import {Grid} from './grid'
import * as fs from "fs";
const input = fs.readFileSync("input").toString()
.split('\n')
.map(row => row.split('').map(v => (v === '#' ? 1 : 0)));
async function main() {
const grid = new Grid(input)
return grid.vaporizeAsteroidsFrom(grid.getAsteroidWithHighestCountInLineOfSight().best_coords)
}
main().then(console.log).catch(console.error);

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
3,8,1005,8,305,1106,0,11,0,0,0,104,1,104,0,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,29,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,1002,8,1,50,1,104,20,10,1,1102,6,10,1006,0,13,3,8,102,-1,8,10,101,1,10,10,4,10,108,1,8,10,4,10,102,1,8,83,1,1102,0,10,1006,0,96,2,1004,19,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,101,0,8,116,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,1,8,10,4,10,102,1,8,138,1006,0,60,1,1008,12,10,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,0,10,4,10,102,1,8,168,1006,0,14,1006,0,28,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,0,8,10,4,10,101,0,8,195,2,1005,9,10,1006,0,29,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,1002,8,1,224,2,1009,8,10,1,3,5,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,102,1,8,254,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,0,10,4,10,1002,8,1,277,1,1003,18,10,1,1104,1,10,101,1,9,9,1007,9,957,10,1005,10,15,99,109,627,104,0,104,1,21101,0,666681062292,1,21102,322,1,0,1105,1,426,21101,847073883028,0,1,21102,333,1,0,1105,1,426,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21101,0,179356855319,1,21102,1,380,0,1105,1,426,21102,1,179356998696,1,21102,1,391,0,1105,1,426,3,10,104,0,104,0,3,10,104,0,104,0,21101,0,988669698816,1,21101,0,414,0,1106,0,426,21102,1,868494500628,1,21102,425,1,0,1106,0,426,99,109,2,21202,-1,1,1,21102,1,40,2,21102,457,1,3,21102,1,447,0,1105,1,490,109,-2,2105,1,0,0,1,0,0,1,109,2,3,10,204,-1,1001,452,453,468,4,0,1001,452,1,452,108,4,452,10,1006,10,484,1102,0,1,452,109,-2,2105,1,0,0,109,4,1201,-1,0,489,1207,-3,0,10,1006,10,507,21102,0,1,-3,22101,0,-3,1,21202,-2,1,2,21101,1,0,3,21102,1,526,0,1106,0,531,109,-4,2105,1,0,109,5,1207,-3,1,10,1006,10,554,2207,-4,-2,10,1006,10,554,22101,0,-4,-4,1106,0,622,21201,-4,0,1,21201,-3,-1,2,21202,-2,2,3,21102,573,1,0,1106,0,531,21202,1,1,-4,21101,1,0,-1,2207,-4,-2,10,1006,10,592,21102,1,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,614,22101,0,-1,1,21102,614,1,0,105,1,489,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2105,1,0

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,385 @@
import * as fs from "fs";
import { relative } from "path";
const fsPromises = fs.promises;
import * as readline from "readline";
import { factory } from "typescript";
const rl = readline.createInterface(process.stdin, process.stdout);
enum ParameterMode {
position = 0,
immediate = 1,
relative = 2,
}
enum Instruction {
add = 1,
mul = 2,
inp = 3,
out = 4,
jnz = 5,
jz = 6,
lt = 7,
eq = 8,
rel = 9,
end = 99,
}
type Memory = Array<OpCode>;
class OpCode {
private _executable: boolean = false;
private _literalValue: number = 0;
private _instruction?: Instruction;
private _parameterModes?: [a: ParameterMode, b: ParameterMode, c: ParameterMode];
constructor(value: number);
constructor(value: string);
constructor(value: string | number) {
let valueNumber: number;
let valueString: string;
if (typeof value === "number") {
valueNumber = value;
valueString = value.toString();
} else {
valueString = value;
valueNumber = parseInt(value);
}
if (isNaN(valueNumber)) throw new Error(`Invalid value '${value}' for OpCode.`);
valueString = valueString.padStart(5, "0");
this._literalValue = valueNumber;
if (valueNumber >= 0 && valueNumber <= 99999 && valueNumber % 100 in Instruction) {
const parameterModes: [ParameterMode, ParameterMode, ParameterMode] = [
Math.floor(valueNumber / 10000) % 10,
Math.floor(valueNumber / 1000) % 10,
Math.floor(valueNumber / 100) % 10,
];
if (parameterModes.filter((val) => val in ParameterMode).length === 3) {
this._parameterModes = parameterModes;
this._instruction = valueNumber % 100;
} else {
return;
}
this._executable = true;
}
}
get executable() {
if (this._instruction === undefined || this._parameterModes === undefined) {
this._executable = false;
}
return this._executable;
}
get literalValue() {
return this._literalValue;
}
get instruction() {
return this._instruction;
}
get parameterModes() {
return this._parameterModes;
}
toString() {
return this.literalValue.toString();
}
}
class Machine {
private readonly initialMemory: Memory;
private memory: Memory;
constructor(program: Memory) {
this.initialMemory = program;
this.memory = program;
}
parseParam(value: number, mode: ParameterMode, relativeOffset: number) {
switch (mode) {
case ParameterMode.immediate:
return value;
case ParameterMode.position:
return this.memory[value]?.literalValue ?? 0;
case ParameterMode.relative:
return this.memory[value + relativeOffset]?.literalValue ?? 0;
}
}
async run(
inputHandler: (context: Context) => Promise<OpCode>,
outputHandler: (context: Context) => Promise<unknown>,
debug: boolean = false
) {
let index = 0;
let relative = 0;
let debugIteration = 0;
const debugLog = debug ? await fsPromises.open("out.log", "w") : undefined;
let output: number[] = [];
try {
while (index < this.memory.length) {
/*for (let i = 0; i < this.memory.length; i++) {
this.memory[i] = this.memory[i] ?? new OpCode(0);
}*/
if (debug) {
debugLog!.write(
`${(++debugIteration).toString().padStart(5, "0")};${relative
.toString()
.padStart(8, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
const opCode = this.memory[index];
if (!opCode.executable) {
throw new Error(`Tried executing non-executable value ${opCode.literalValue} at index ${index}`);
}
const parameterModes = opCode.parameterModes!;
const valueA = this.memory[index + 1]?.literalValue ?? 0;
const valueB = this.memory[index + 2]?.literalValue ?? 0;
const valueC = this.memory[index + 3]?.literalValue ?? 0;
const paramA = this.parseParam(valueA, parameterModes[2 - 0], relative);
const paramB = this.parseParam(valueB, parameterModes[2 - 1], relative);
const paramC = this.parseParam(valueC, parameterModes[2 - 2], relative);
if (debug) {
console.debug(`${opCode.literalValue}(${valueA}, ${valueB}, ${valueC});${this.memory[1028]?.literalValue}`);
}
const context: Context = {
parameterModes,
valueA,
valueB,
valueC,
paramA,
paramB,
paramC,
debug,
index,
relative,
opCode,
output,
};
switch (opCode.instruction) {
case Instruction.add:
if (debug) {
console.debug(
`Adding ${paramA}+${paramB} and writing ${paramA + paramB} to ${valueC} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA + paramB);
} else {
this.memory[valueC] = new OpCode(paramA + paramB);
}
index += 4;
break;
case Instruction.mul:
if (debug) {
console.debug(
`Multiplying ${paramA}*${paramB} and writing ${paramA * paramB} to ${valueC} - OpCode ${
opCode.literalValue
}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA * paramB);
} else {
this.memory[valueC] = new OpCode(paramA * paramB);
}
index += 4;
break;
case Instruction.inp:
let input = await inputHandler(context);
if (parameterModes[2 - 0] === ParameterMode.relative) {
this.memory[valueA + relative] = input;
} else {
this.memory[valueA] = input;
}
index += 2;
break;
case Instruction.out:
outputHandler(context);
index += 2;
break;
case Instruction.jnz:
if (debug) {
console.debug(`Testing if ${paramA}!=0, if so, jumping to ${paramB} - OpCode ${opCode.literalValue}`);
}
if (paramA !== 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.jz:
if (debug) {
console.debug(`Testing if ${paramA}==0, if so, jumping to ${paramB} - OpCode ${opCode.literalValue}`);
}
if (paramA === 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.lt:
if (debug) {
console.debug(
`Checking if ${paramA}<${paramB} and writing result to ${
parameterModes[2 - 2] === ParameterMode.relative ? valueC + relative : valueC
} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA < paramB ? 1 : 0);
} else {
this.memory[valueC] = new OpCode(paramA < paramB ? 1 : 0);
}
index += 4;
break;
case Instruction.eq:
if (debug) {
console.debug(
`Checking if ${paramA}==${paramB} and writing result to ${
parameterModes[2 - 2] === ParameterMode.relative ? valueC + relative : valueC
} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA === paramB ? 1 : 0);
} else {
this.memory[valueC] = new OpCode(paramA === paramB ? 1 : 0);
}
index += 4;
break;
case Instruction.rel:
if (debug) {
console.debug(
`Adjusting relative offset from ${relative} +${paramA} to ${relative + paramA} - OpCode ${
opCode.literalValue
}`
);
}
relative += paramA;
index += 2;
break;
case Instruction.end:
// console.log("Final output:", output);
return this.memory;
}
}
} catch (e) {
console.debug(`Execution failed at index ${index}. Dumping memory.`);
if (debug) {
debugLog!.write(
`${debugIteration.toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
throw e;
}
// console.log("Final output:", output);
return this.memory;
}
reset() {
this.memory = this.initialMemory;
}
static memdump(memory: Memory) {
return memory.map((op) => op.toString()).join(",");
}
}
interface Context {
parameterModes: [ParameterMode, ParameterMode, ParameterMode];
valueA: number;
valueB: number;
valueC: number;
paramA: number;
paramB: number;
paramC: number;
debug: boolean;
index: number;
relative: number;
opCode: OpCode;
output: number[];
}
async function main(code: string): Promise<[number, string]> {
let painted = new Set<string>();
const memdump: Memory = code.split(",").map((val) => new OpCode(val));
const machine = new Machine(memdump);
async function input(context: Context) {
if (context.debug) {
console.debug("inputting", field[coords[1]][coords[0]] === "⬜" ? 1 : 0);
}
return new OpCode(field[coords[1]][coords[0]] === "⬜" ? 1 : 0);
}
async function output(context: Context) {
if (context.debug) {
console.debug(`Outputting ${context.paramA} - OpCode ${context.opCode.literalValue}`);
}
context.output.push(context.paramA);
if (awaiting === "color") {
awaiting = "turning";
const newColor = context.paramA === 1 ? "⬜" : "⬛";
field[coords[1]][coords[0]] = newColor;
} else {
awaiting = "color";
let turning = context.paramA === 0 ? -1 : context.paramA;
if (!painted.has(`${coords[0]};${coords[1]}`)) {
painted.add(`${coords[0]};${coords[1]}`);
}
facing = ((facing + turning + 4) % 4) as 0 | 1 | 2 | 3;
switch (facing) {
case 0:
coords[1] = coords[1] - 1;
break;
case 1:
coords[0] = coords[0] + 1;
break;
case 2:
coords[1] = coords[1] + 1;
break;
case 3:
coords[0] = coords[0] - 1;
break;
}
}
}
let field: ("⬜" | "⬛")[][] = Array<("⬜" | "⬛")[]>(86)
.fill([])
.map((_) => []);
let coords: [number, number] = [0, 72];
let facing: 0 | 1 | 2 | 3 = 0;
let awaiting: "turning" | "color" = "color";
await machine.run(input, output);
rl.close();
return [painted.size, field.map((line) => line.join("")).join("\n")];
}
const input = fs.readFileSync("input").toString();
main(input)
.then(([count, field]) => {
console.log(count);
// console.log(field);
})
.catch((...args) => {
rl.close();
console.error(args);
});

View file

@ -0,0 +1,386 @@
import * as fs from "fs";
import { relative } from "path";
const fsPromises = fs.promises;
import * as readline from "readline";
import { factory } from "typescript";
const rl = readline.createInterface(process.stdin, process.stdout);
enum ParameterMode {
position = 0,
immediate = 1,
relative = 2,
}
enum Instruction {
add = 1,
mul = 2,
inp = 3,
out = 4,
jnz = 5,
jz = 6,
lt = 7,
eq = 8,
rel = 9,
end = 99,
}
type Memory = Array<OpCode>;
class OpCode {
private _executable: boolean = false;
private _literalValue: number = 0;
private _instruction?: Instruction;
private _parameterModes?: [a: ParameterMode, b: ParameterMode, c: ParameterMode];
constructor(value: number);
constructor(value: string);
constructor(value: string | number) {
let valueNumber: number;
let valueString: string;
if (typeof value === "number") {
valueNumber = value;
valueString = value.toString();
} else {
valueString = value;
valueNumber = parseInt(value);
}
if (isNaN(valueNumber)) throw new Error(`Invalid value '${value}' for OpCode.`);
valueString = valueString.padStart(5, "0");
this._literalValue = valueNumber;
if (valueNumber >= 0 && valueNumber <= 99999 && valueNumber % 100 in Instruction) {
const parameterModes: [ParameterMode, ParameterMode, ParameterMode] = [
Math.floor(valueNumber / 10000) % 10,
Math.floor(valueNumber / 1000) % 10,
Math.floor(valueNumber / 100) % 10,
];
if (parameterModes.filter((val) => val in ParameterMode).length === 3) {
this._parameterModes = parameterModes;
this._instruction = valueNumber % 100;
} else {
return;
}
this._executable = true;
}
}
get executable() {
if (this._instruction === undefined || this._parameterModes === undefined) {
this._executable = false;
}
return this._executable;
}
get literalValue() {
return this._literalValue;
}
get instruction() {
return this._instruction;
}
get parameterModes() {
return this._parameterModes;
}
toString() {
return this.literalValue.toString();
}
}
class Machine {
private readonly initialMemory: Memory;
private memory: Memory;
constructor(program: Memory) {
this.initialMemory = program;
this.memory = program;
}
parseParam(value: number, mode: ParameterMode, relativeOffset: number) {
switch (mode) {
case ParameterMode.immediate:
return value;
case ParameterMode.position:
return this.memory[value]?.literalValue ?? 0;
case ParameterMode.relative:
return this.memory[value + relativeOffset]?.literalValue ?? 0;
}
}
async run(
inputHandler: (context: Context) => Promise<OpCode>,
outputHandler: (context: Context) => Promise<unknown>,
debug: boolean = false
) {
let index = 0;
let relative = 0;
let debugIteration = 0;
const debugLog = debug ? await fsPromises.open("out.log", "w") : undefined;
let output: number[] = [];
try {
while (index < this.memory.length) {
/*for (let i = 0; i < this.memory.length; i++) {
this.memory[i] = this.memory[i] ?? new OpCode(0);
}*/
if (debug) {
debugLog!.write(
`${(++debugIteration).toString().padStart(5, "0")};${relative
.toString()
.padStart(8, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
const opCode = this.memory[index];
if (!opCode.executable) {
throw new Error(`Tried executing non-executable value ${opCode.literalValue} at index ${index}`);
}
const parameterModes = opCode.parameterModes!;
const valueA = this.memory[index + 1]?.literalValue ?? 0;
const valueB = this.memory[index + 2]?.literalValue ?? 0;
const valueC = this.memory[index + 3]?.literalValue ?? 0;
const paramA = this.parseParam(valueA, parameterModes[2 - 0], relative);
const paramB = this.parseParam(valueB, parameterModes[2 - 1], relative);
const paramC = this.parseParam(valueC, parameterModes[2 - 2], relative);
if (debug) {
console.debug(`${opCode.literalValue}(${valueA}, ${valueB}, ${valueC});${this.memory[1028]?.literalValue}`);
}
const context: Context = {
parameterModes,
valueA,
valueB,
valueC,
paramA,
paramB,
paramC,
debug,
index,
relative,
opCode,
output,
};
switch (opCode.instruction) {
case Instruction.add:
if (debug) {
console.debug(
`Adding ${paramA}+${paramB} and writing ${paramA + paramB} to ${valueC} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA + paramB);
} else {
this.memory[valueC] = new OpCode(paramA + paramB);
}
index += 4;
break;
case Instruction.mul:
if (debug) {
console.debug(
`Multiplying ${paramA}*${paramB} and writing ${paramA * paramB} to ${valueC} - OpCode ${
opCode.literalValue
}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA * paramB);
} else {
this.memory[valueC] = new OpCode(paramA * paramB);
}
index += 4;
break;
case Instruction.inp:
let input = await inputHandler(context);
if (parameterModes[2 - 0] === ParameterMode.relative) {
this.memory[valueA + relative] = input;
} else {
this.memory[valueA] = input;
}
index += 2;
break;
case Instruction.out:
outputHandler(context);
index += 2;
break;
case Instruction.jnz:
if (debug) {
console.debug(`Testing if ${paramA}!=0, if so, jumping to ${paramB} - OpCode ${opCode.literalValue}`);
}
if (paramA !== 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.jz:
if (debug) {
console.debug(`Testing if ${paramA}==0, if so, jumping to ${paramB} - OpCode ${opCode.literalValue}`);
}
if (paramA === 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.lt:
if (debug) {
console.debug(
`Checking if ${paramA}<${paramB} and writing result to ${
parameterModes[2 - 2] === ParameterMode.relative ? valueC + relative : valueC
} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA < paramB ? 1 : 0);
} else {
this.memory[valueC] = new OpCode(paramA < paramB ? 1 : 0);
}
index += 4;
break;
case Instruction.eq:
if (debug) {
console.debug(
`Checking if ${paramA}==${paramB} and writing result to ${
parameterModes[2 - 2] === ParameterMode.relative ? valueC + relative : valueC
} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA === paramB ? 1 : 0);
} else {
this.memory[valueC] = new OpCode(paramA === paramB ? 1 : 0);
}
index += 4;
break;
case Instruction.rel:
if (debug) {
console.debug(
`Adjusting relative offset from ${relative} +${paramA} to ${relative + paramA} - OpCode ${
opCode.literalValue
}`
);
}
relative += paramA;
index += 2;
break;
case Instruction.end:
// console.log("Final output:", output);
return this.memory;
}
}
} catch (e) {
console.debug(`Execution failed at index ${index}. Dumping memory.`);
if (debug) {
debugLog!.write(
`${debugIteration.toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
throw e;
}
// console.log("Final output:", output);
return this.memory;
}
reset() {
this.memory = this.initialMemory;
}
static memdump(memory: Memory) {
return memory.map((op) => op.toString()).join(",");
}
}
interface Context {
parameterModes: [ParameterMode, ParameterMode, ParameterMode];
valueA: number;
valueB: number;
valueC: number;
paramA: number;
paramB: number;
paramC: number;
debug: boolean;
index: number;
relative: number;
opCode: OpCode;
output: number[];
}
async function main(code: string): Promise<[number, string]> {
let painted = new Set<string>();
const memdump: Memory = code.split(",").map((val) => new OpCode(val));
const machine = new Machine(memdump);
async function input(context: Context) {
if (context.debug) {
console.debug("inputting", field[coords[1]][coords[0]] === "⬜" ? 1 : 0);
}
return new OpCode(field[coords[1]][coords[0]] === "⬜" ? 1 : 0);
}
async function output(context: Context) {
if (context.debug) {
console.debug(`Outputting ${context.paramA} - OpCode ${context.opCode.literalValue}`);
}
context.output.push(context.paramA);
if (awaiting === "color") {
awaiting = "turning";
const newColor = context.paramA === 1 ? "⬜" : "⬛";
field[coords[1]][coords[0]] = newColor;
} else {
awaiting = "color";
let turning = context.paramA === 0 ? -1 : context.paramA;
if (!painted.has(`${coords[0]};${coords[1]}`)) {
painted.add(`${coords[0]};${coords[1]}`);
}
facing = ((facing + turning + 4) % 4) as 0 | 1 | 2 | 3;
switch (facing) {
case 0:
coords[1] = coords[1] - 1;
break;
case 1:
coords[0] = coords[0] + 1;
break;
case 2:
coords[1] = coords[1] + 1;
break;
case 3:
coords[0] = coords[0] - 1;
break;
}
}
}
let field: ("⬜" | "⬛")[][] = Array<("⬜" | "⬛")[]>(7)
.fill([])
.map((_) => Array(43).fill("⬛"));
let coords: [number, number] = [0, 1];
let facing: 0 | 1 | 2 | 3 = 0;
let awaiting: "turning" | "color" = "color";
field[coords[1]][coords[0]] = "⬜"
await machine.run(input, output);
rl.close();
return [painted.size, field.map((line) => line.join("")).join("\n")];
}
const input = fs.readFileSync("input").toString();
main(input)
.then(([count, field]) => {
console.log(count);
console.log(field);
})
.catch((...args) => {
rl.close();
console.error(args);
});

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

View file

@ -0,0 +1 @@
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,10,1,19,1,5,19,23,1,23,5,27,2,27,10,31,1,5,31,35,2,35,6,39,1,6,39,43,2,13,43,47,2,9,47,51,1,6,51,55,1,55,9,59,2,6,59,63,1,5,63,67,2,67,13,71,1,9,71,75,1,75,9,79,2,79,10,83,1,6,83,87,1,5,87,91,1,6,91,95,1,95,13,99,1,10,99,103,2,6,103,107,1,107,5,111,1,111,13,115,1,115,13,119,1,13,119,123,2,123,13,127,1,127,6,131,1,131,9,135,1,5,135,139,2,139,6,143,2,6,143,147,1,5,147,151,1,151,2,155,1,9,155,0,99,2,14,0,0

View file

@ -0,0 +1,16 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.6",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,47 @@
import * as fs from 'fs';
const input = fs.readFileSync("input").toString().split(",").map(num => parseInt(num));
async function main() {
let memory = input.slice();
// Restore integrity
memory[1] = 12
memory[2] = 2
//
let index = 0;
let [a,b,x] = [0,0,0];
while(index < memory.length && memory[index] !== 99) {
switch(memory[index]){
case 1:
// .add
[a, b, x] = memory.slice(index+1, index+4);
memory[x] = memory[a] + memory[b];
index += 4;
break;
case 2:
// .mul
[a, b, x] = memory.slice(index+1, index+4);
memory[x] = memory[a] * memory[b];
index += 4;
break;
case 99:
// .end
return memory[0];
default:
// .hcf
throw new Error("Halt and catch fire");
}
}
console.warn("Reached end of code without halting instruction!")
return memory[0]
}
main().then(console.log);

View file

@ -0,0 +1,64 @@
import * as fs from 'fs';
const input = fs.readFileSync("input").toString().split(",").map(num => parseInt(num));
async function run(noun: number, verb: number) {
let memory = input.slice();
// Restore integrity
memory[1] = noun
memory[2] = verb
//
let index = 0;
let [a,b,x] = [0,0,0];
while(index < memory.length && memory[index] !== 99) {
switch(memory[index]){
case 1:
// .add
[a, b, x] = memory.slice(index+1, index+4);
memory[x] = memory[a] + memory[b];
index += 4;
break;
case 2:
// .mul
[a, b, x] = memory.slice(index+1, index+4);
memory[x] = memory[a] * memory[b];
index += 4;
break;
case 99:
// .end
return memory[0];
default:
// .hcf
throw new Error("Halt and catch fire");
}
}
return memory[0]
}
async function main(){
let noun = 0;
let verb = 0;
while(noun < 99) {
while(verb < 99) {
console.log(`Testing [${noun}, ${verb}]`)
if(await run(noun,verb) === 19690720) {
console.log("Success!")
return 100*noun+verb
}
verb++;
}
noun++;
verb = 0;
}
throw new Error("Found no solution!")
}
main().then(console.log);

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.6":
version "14.14.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

View file

@ -0,0 +1,2 @@
R999,D467,L84,D619,L49,U380,R287,U80,R744,D642,L340,U738,R959,U710,R882,U861,L130,D354,L579,D586,R798,D735,L661,D453,L828,U953,R604,D834,R921,D348,R620,U775,R364,U552,L221,U119,R590,U29,L267,D745,L128,U468,L978,D717,R883,D227,R691,D330,L33,U520,L862,D132,R99,U400,L455,U737,L603,U220,L689,U131,R158,D674,R617,D287,R422,U734,L73,U327,L525,D245,R849,D692,R114,U136,R762,D5,R329,U429,L849,U748,R816,U556,R614,D412,R416,D306,R307,U826,R880,U936,L164,U984,L689,D934,R790,D14,R561,D736,L3,D442,R301,D520,L451,U76,R844,D307,L144,D800,L462,D138,R956,U225,L393,D186,L924,D445,L86,D640,L920,D877,L197,U191,L371,D701,R826,D282,R856,D412,L788,D417,R69,D678,R978,D268,L268,U112,L69,U164,L748,U191,R227,D227,R59,U749,R134,U779,R865,U247,R55,D567,R821,U799,R937,D942,L445,D571,R685,D111,R107,D769,R269,D968,R102,U335,R538,U125,L725,D654,R451,D242,R777,U813,R799,D786,L804,U313,L322,U771,R219,U316,L973,U963,R84,D289,R825,D299,L425,D49,R995,D486,R550,D789,R735,D501,R966,U955,R432,U635,L353,D600,R675,D236,R864,U322,R719,D418,L877,U833,R839,D634,L533,D438,L734,U130,L578,U498,L984,D413,L615,U40,L699,U656,L653,U419,R856,U882,R30,D266,R386,D692,L210,U802,L390,U753,L406,U338,R743,D320,L125,U204,R391,U537,R887,D194,L302,U400,R510,U92,L310,D382,R597,U498,R851,D357,L568,U800,R918,D106,R673,D735,L86,D67,R398,D677,R355,D501,L909,D133,R729,D293,L498,U222,R832,U671,R751,U36,R422,U840,L636,D476,L292,D105,L239,U199,R669,U736,L345,D911,L277,U452,L979,D153,R882,U604,R602,U495,L311,U453,L215,D713,R873
L996,U773,L865,D472,L988,D570,L388,U458,L87,U885,L115,U55,R75,U582,R695,U883,R83,U285,R96,D244,L647,D359,R136,U107,R912,U871,L844,U395,L63,U899,L205,D137,R549,U221,L859,D429,L809,U127,R304,U679,L511,U144,R926,U95,L805,U811,R42,D248,L546,D644,L551,D897,R368,D391,L224,U164,L490,D991,L146,D615,R536,U247,R10,U998,L957,D233,R706,D926,R760,U438,R270,D983,R134,U738,L262,U301,L480,D635,L702,D715,R479,U500,R19,D291,R368,U203,R305,D999,R106,U355,L683,D298,R90,U968,L254,D936,R89,U496,R253,U688,R99,U637,L783,D451,R673,D762,R997,D50,L488,U551,L871,U388,R949,D371,R584,D908,L880,U523,R557,U436,R520,U587,L56,U18,R397,U541,R660,D444,R51,U187,R221,U902,R726,U303,R97,D817,R185,D218,L240,D67,L259,U334,R821,U629,R21,D970,R282,U155,R555,D678,L99,D570,R863,D405,R941,U584,L303,D109,L871,U180,R595,D226,L670,D943,L127,U647,R452,D570,R75,D284,R414,U404,R515,U993,R408,U488,R890,D318,L415,U969,R769,D976,L732,U1,R489,U655,R930,U638,R649,D254,R161,U287,L659,D26,L477,D821,L124,U538,R17,D711,L203,U888,R904,U648,L908,D65,L215,U283,R698,U28,R72,U214,R499,D89,R489,D58,R949,D91,L710,U960,L755,D402,L27,D873,R61,U607,R57,D548,R369,U622,L244,U19,R61,D606,R928,D968,R10,D988,R816,U500,R915,D400,R546,D283,L627,D919,L259,U337,R374,U795,L355,D989,L224,D77,L872,U901,R476,U765,L320,U768,L937,D437,R141,D822,L326,D324,L498,U994,L518,D857,R973,D681,L710,D590,L879,U499,R488,D151,L242,U988,L944,U683,L24,U491,R823,D246,R872,D654,R28,U581,L142,U31,R435,D686,L147,D102,R952,D607,L959,D929,L46

View file

@ -0,0 +1,16 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.6",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,61 @@
import * as fs from "fs";
const input = fs
.readFileSync("input")
.toString()
.split("\n")
.map((inp) => inp.split(","));
async function trace(ops: string[]) {
let board: boolean[][] = [];
let x = 0;
let y = 0;
for (const op of ops) {
const dir = op.substring(0, 1);
let len = parseInt(op.substring(1));
switch (dir) {
case "R":
while (len-- > 0) {
(board[y] ?? (board[y] = []))[++x] = true;
}
break;
case "L":
while (len-- > 0) {
(board[y] ?? (board[y] = []))[--x] = true;
}
break;
case "U":
while (len-- > 0) {
y++;
(board[y] ?? (board[y] = []))[x] = true;
}
break;
case "D":
while (len-- > 0) {
y--;
(board[y] ?? (board[y] = []))[x] = true;
}
break;
}
}
return board;
}
async function main() {
const [wireA, wireB] = [await trace(input[0]), await trace(input[1])];
const crossings: [number, number][] = [];
for (let y = 0; y < Math.min(wireA.length, wireB.length); y++) {
for (let x = 0; x < Math.min(wireA[y].length, wireB[y].length); x++) {
if (wireA[y][x] && wireB[y][x]) {
crossings.push([y, x]);
}
}
}
return crossings;
}
main().then((crossings) =>
console.log(Math.min(...crossings.map((coords) => coords[0] + coords[1])))
);

View file

@ -0,0 +1,74 @@
import * as fs from "fs";
const input = fs
.readFileSync("input")
.toString()
.split("\n")
.map((inp) => inp.split(","));
async function trace(ops: string[]) {
let board: number[][] = [];
let steps = 0;
let x = 0;
let y = 0;
for (const op of ops) {
const dir = op.substring(0, 1);
let len = parseInt(op.substring(1));
switch (dir) {
case "R":
while (len-- > 0) {
(board[y] ?? (board[y] = []))[++x] = Math.min(
board[y][x] ?? Infinity,
++steps
);
}
break;
case "L":
while (len-- > 0) {
(board[y] ?? (board[y] = []))[--x] = Math.min(
board[y][x] ?? Infinity,
++steps
);
}
break;
case "U":
while (len-- > 0) {
y++;
(board[y] ?? (board[y] = []))[x] = Math.min(
board[y][x] ?? Infinity,
++steps
);
}
break;
case "D":
while (len-- > 0) {
y--;
(board[y] ?? (board[y] = []))[x] = Math.min(
board[y][x] ?? Infinity,
++steps
);
}
break;
}
}
return board;
}
async function main() {
const [wireA, wireB] = [await trace(input[0]), await trace(input[1])];
const crossings: [y: number, x: number, val: number][] = [];
for (let y = 0; y < Math.min(wireA.length, wireB.length); y++) {
for (let x = 0; x < Math.min(wireA[y].length, wireB[y].length); x++) {
if (wireA[y][x] > 0 && wireB[y][x] > 0) {
crossings.push([y, x, wireA[y][x] + wireB[y][x]]);
}
}
}
return crossings.sort(
(crossingA, crossingB) => crossingA[2] - crossingB[2]
)[0];
}
main().then(console.log);

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "Node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.6":
version "14.14.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

View file

@ -0,0 +1 @@
153517-630395

View file

@ -0,0 +1,16 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.6",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,43 @@
import * as fs from "fs";
const input = fs.readFileSync("input").toString();
function verifyNotDecreasing(pass: string) {
const digits = pass.split("").map((digit) => parseInt(digit));
for (let i = 0; i < digits.length - 1; i++) {
if (digits[i + 1] < digits[i]) {
return false;
}
}
return true;
}
function verifyHasDouble(pass: string) {
const digits = pass.split("").map((digit) => parseInt(digit));
for (let i = 0; i < digits.length - 1; i++) {
if (digits[i + 1] === digits[i]) {
return true;
}
}
return false;
}
function verifyPass(pass: number) {
return (
!pass.toString().startsWith("0") &&
verifyNotDecreasing(pass.toString()) &&
verifyHasDouble(pass.toString())
);
}
async function main() {
const [min, max] = input.split("-").map((val) => parseInt(val));
let results = 0;
for (let i = min; i <= max; i++) {
if (verifyPass(i)) {
results++;
}
}
return results;
}
main().then(console.log);

View file

@ -0,0 +1,47 @@
import * as fs from "fs";
const input = fs.readFileSync("input").toString();
function verifyNotDecreasing(pass: string) {
const digits = pass.split("").map((digit) => parseInt(digit));
for (let i = 0; i < digits.length - 1; i++) {
if (digits[i + 1] < digits[i]) {
return false;
}
}
return true;
}
function verifyHasDoubleButNotMore(pass: string) {
const digits = pass.split("").map((digit) => parseInt(digit));
for (let i = 0; i < digits.length; i++) {
if (
digits[i] === digits[i + 1] &&
digits[i] !== digits[i + 2] &&
digits[i] !== digits[i - 1]
) {
return true;
}
}
return false;
}
function verifyPass(pass: number) {
return (
pass >= 1e5 &&
verifyNotDecreasing(pass.toString()) &&
verifyHasDoubleButNotMore(pass.toString())
);
}
async function main() {
const [min, max] = input.split("-").map((val) => parseInt(val));
let results = 0;
for (let i = min; i <= max; i++) {
if (verifyPass(i)) {
results++;
}
}
return results;
}
main().then(console.log);

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.6":
version "14.14.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

View file

@ -0,0 +1 @@
3,225,1,225,6,6,1100,1,238,225,104,0,1101,40,27,224,101,-67,224,224,4,224,1002,223,8,223,1001,224,2,224,1,224,223,223,1101,33,38,225,1102,84,60,225,1101,65,62,225,1002,36,13,224,1001,224,-494,224,4,224,1002,223,8,223,1001,224,3,224,1,223,224,223,1102,86,5,224,101,-430,224,224,4,224,1002,223,8,223,101,6,224,224,1,223,224,223,1102,23,50,225,1001,44,10,224,101,-72,224,224,4,224,102,8,223,223,101,1,224,224,1,224,223,223,102,47,217,224,1001,224,-2303,224,4,224,102,8,223,223,101,2,224,224,1,223,224,223,1102,71,84,225,101,91,40,224,1001,224,-151,224,4,224,1002,223,8,223,1001,224,5,224,1,223,224,223,1101,87,91,225,1102,71,19,225,1,92,140,224,101,-134,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,2,170,165,224,1001,224,-1653,224,4,224,1002,223,8,223,101,5,224,224,1,223,224,223,1101,49,32,225,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,1107,226,677,224,1002,223,2,223,1006,224,329,101,1,223,223,8,226,226,224,1002,223,2,223,1005,224,344,101,1,223,223,1007,677,226,224,102,2,223,223,1005,224,359,101,1,223,223,8,226,677,224,102,2,223,223,1005,224,374,101,1,223,223,1107,677,677,224,1002,223,2,223,1005,224,389,1001,223,1,223,108,226,677,224,102,2,223,223,1005,224,404,1001,223,1,223,108,677,677,224,1002,223,2,223,1006,224,419,101,1,223,223,107,677,677,224,102,2,223,223,1006,224,434,101,1,223,223,108,226,226,224,1002,223,2,223,1006,224,449,1001,223,1,223,8,677,226,224,1002,223,2,223,1005,224,464,101,1,223,223,1108,226,677,224,1002,223,2,223,1006,224,479,1001,223,1,223,1108,677,677,224,1002,223,2,223,1005,224,494,101,1,223,223,7,677,677,224,1002,223,2,223,1005,224,509,101,1,223,223,1007,677,677,224,1002,223,2,223,1005,224,524,101,1,223,223,7,677,226,224,1002,223,2,223,1005,224,539,101,1,223,223,1107,677,226,224,102,2,223,223,1006,224,554,101,1,223,223,107,226,677,224,1002,223,2,223,1005,224,569,101,1,223,223,107,226,226,224,1002,223,2,223,1005,224,584,101,1,223,223,1108,677,226,224,102,2,223,223,1006,224,599,1001,223,1,223,1008,677,677,224,102,2,223,223,1006,224,614,101,1,223,223,7,226,677,224,102,2,223,223,1005,224,629,101,1,223,223,1008,226,677,224,1002,223,2,223,1006,224,644,101,1,223,223,1007,226,226,224,1002,223,2,223,1005,224,659,1001,223,1,223,1008,226,226,224,102,2,223,223,1006,224,674,1001,223,1,223,4,223,99,226

View file

@ -0,0 +1,17 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=120",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.8",
"readline": "^1.3.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,207 @@
import * as fs from "fs";
const fsPromises = fs.promises;
import * as readline from "readline";
const rl = readline.createInterface(process.stdin, process.stdout);
enum ParameterMode {
position = 0,
immediate = 1,
}
enum Instruction {
add = 1,
mul = 2,
inp = 3,
out = 4,
end = 99,
}
type Memory = Array<OpCode>;
class OpCode {
private _executable: boolean = false;
private _literalValue: number = 0;
private _instruction?: Instruction;
private _parameterModes?: [a: ParameterMode, b: ParameterMode, c: ParameterMode];
constructor(value: number);
constructor(value: string);
constructor(value: string | number) {
let valueNumber: number;
let valueString: string;
if (typeof value === "number") {
valueNumber = value;
valueString = value.toString();
} else {
valueString = value;
valueNumber = parseInt(value);
}
if (isNaN(valueNumber)) throw new Error(`Invalid value '${value}' for OpCode.`);
valueString = valueString.padStart(5, "0");
this._literalValue = valueNumber;
if (valueNumber >= 0 && valueNumber <= 99999 && valueNumber % 100 in Instruction) {
const parameterModes: [ParameterMode, ParameterMode, ParameterMode] = [
Math.floor(valueNumber / 10000) % 10,
Math.floor(valueNumber / 1000) % 10,
Math.floor(valueNumber / 100) % 10,
];
if (parameterModes.filter((val) => val in ParameterMode).length === 3) {
this._parameterModes = parameterModes;
this._instruction = valueNumber % 100;
} else {
return;
}
this._executable = true;
}
}
get executable() {
if (this._instruction === undefined || this._parameterModes === undefined) {
this._executable = false;
}
return this._executable;
}
get literalValue() {
return this._literalValue;
}
get instruction() {
return this._instruction;
}
get parameterModes() {
return this._parameterModes;
}
toString() {
return this.literalValue.toString();
}
}
class Machine {
private readonly initialMemory: Memory;
private memory: Memory;
constructor(program: Memory) {
this.initialMemory = program;
this.memory = program;
}
async run(debug: boolean = false) {
let index = 0;
let debugIteration = 0;
const debugLog = await fsPromises.open("out.log", "w");
let output: number[] = [];
try {
while (index < this.memory.length) {
/*for (let i = 0; i < this.memory.length; i++) {
this.memory[i] = this.memory[i] ?? new OpCode(0);
}*/
if (debug) {
debugLog.write(
`${(++debugIteration).toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
const opCode = this.memory[index];
if (!opCode.executable) {
throw new Error(`Tried executing non-executable value ${this.memory[index]} at index ${index}`);
}
const parameterModes = opCode.parameterModes!;
const valueA = this.memory[index + 1]?.literalValue ?? 0;
const valueB = this.memory[index + 2]?.literalValue ?? 0;
const valueC = this.memory[index + 3]?.literalValue ?? 0;
const paramA = parameterModes[2] === ParameterMode.immediate ? valueA : this.memory[valueA]?.literalValue ?? 0;
const paramB = parameterModes[1] === ParameterMode.immediate ? valueB : this.memory[valueB]?.literalValue ?? 0;
const paramC = parameterModes[0] === ParameterMode.immediate ? valueC : this.memory[valueC]?.literalValue ?? 0;
/*console.debug(
opCode,
this.memory.slice(index, index + 4).map((val) => val.literalValue)
);*/
switch (opCode.instruction) {
case Instruction.add:
if (debug) {
console.debug(`Adding ${paramA}+${paramB} and writing ${paramA + paramB} to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA + paramB);
index += 4;
break;
case Instruction.mul:
if (debug) {
console.debug(`Multiplying ${paramA}*${paramB} and writing ${paramA * paramB} to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA * paramB);
index += 4;
break;
case Instruction.inp:
this.memory[valueA] = await new Promise<OpCode>((resolve, reject) => {
rl.question(`[${index.toString().padStart(5, "0")}]> `, (answer) => {
try {
const op = new OpCode(answer);
if (debug) {
console.debug(`Writing opCode with value ${op.literalValue} to ${valueA}`);
}
resolve(op);
} catch (e) {
reject(e);
}
});
});
index += 2;
break;
case Instruction.out:
if (debug) {
console.debug(`Outputting ${paramA}`);
}
output.push(paramA);
index += 2;
break;
case Instruction.end:
console.log("Final output:", output);
return this.memory;
}
}
} catch (e) {
console.debug(`Execution failed at index ${index}. Dumping memory.`);
debugLog.write(
`${debugIteration.toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
throw e;
}
console.log("Final output:", output);
return this.memory;
}
reset() {
this.memory = this.initialMemory;
}
static memdump(memory: Memory) {
return memory.map((op) => op.toString()).join(",");
}
}
async function main(code: string) {
const memdump: Memory = code.split(",").map((val) => new OpCode(val));
const machine = new Machine(memdump);
const result = await machine.run();
rl.close();
return; // result ? Machine.memdump(result) : result;
}
const input = fs.readFileSync("input").toString();
main(input)
.then(console.log)
.catch((...args) => {
rl.close();
console.error(args);
});

View file

@ -0,0 +1,247 @@
import * as fs from "fs";
const fsPromises = fs.promises;
import * as readline from "readline";
const rl = readline.createInterface(process.stdin, process.stdout);
enum ParameterMode {
position = 0,
immediate = 1,
}
enum Instruction {
add = 1,
mul = 2,
inp = 3,
out = 4,
jnz = 5,
jz = 6,
lt = 7,
eq = 8,
end = 99,
}
type Memory = Array<OpCode>;
class OpCode {
private _executable: boolean = false;
private _literalValue: number = 0;
private _instruction?: Instruction;
private _parameterModes?: [a: ParameterMode, b: ParameterMode, c: ParameterMode];
constructor(value: number);
constructor(value: string);
constructor(value: string | number) {
let valueNumber: number;
let valueString: string;
if (typeof value === "number") {
valueNumber = value;
valueString = value.toString();
} else {
valueString = value;
valueNumber = parseInt(value);
}
if (isNaN(valueNumber)) throw new Error(`Invalid value '${value}' for OpCode.`);
valueString = valueString.padStart(5, "0");
this._literalValue = valueNumber;
if (valueNumber >= 0 && valueNumber <= 99999 && valueNumber % 100 in Instruction) {
const parameterModes: [ParameterMode, ParameterMode, ParameterMode] = [
Math.floor(valueNumber / 10000) % 10,
Math.floor(valueNumber / 1000) % 10,
Math.floor(valueNumber / 100) % 10,
];
if (parameterModes.filter((val) => val in ParameterMode).length === 3) {
this._parameterModes = parameterModes;
this._instruction = valueNumber % 100;
} else {
return;
}
this._executable = true;
}
}
get executable() {
if (this._instruction === undefined || this._parameterModes === undefined) {
this._executable = false;
}
return this._executable;
}
get literalValue() {
return this._literalValue;
}
get instruction() {
return this._instruction;
}
get parameterModes() {
return this._parameterModes;
}
toString() {
return this.literalValue.toString();
}
}
class Machine {
private readonly initialMemory: Memory;
private memory: Memory;
constructor(program: Memory) {
this.initialMemory = program;
this.memory = program;
}
async run(debug: boolean = false) {
let index = 0;
let debugIteration = 0;
const debugLog = debug ? await fsPromises.open("out.log", "w") : undefined;
let output: number[] = [];
try {
while (index < this.memory.length) {
/*for (let i = 0; i < this.memory.length; i++) {
this.memory[i] = this.memory[i] ?? new OpCode(0);
}*/
if (debug) {
debugLog!.write(
`${(++debugIteration).toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
const opCode = this.memory[index];
if (!opCode.executable) {
throw new Error(`Tried executing non-executable value ${this.memory[index]} at index ${index}`);
}
const parameterModes = opCode.parameterModes!;
const valueA = this.memory[index + 1]?.literalValue ?? 0;
const valueB = this.memory[index + 2]?.literalValue ?? 0;
const valueC = this.memory[index + 3]?.literalValue ?? 0;
const paramA = parameterModes[2] === ParameterMode.immediate ? valueA : this.memory[valueA]?.literalValue ?? 0;
const paramB = parameterModes[1] === ParameterMode.immediate ? valueB : this.memory[valueB]?.literalValue ?? 0;
const paramC = parameterModes[0] === ParameterMode.immediate ? valueC : this.memory[valueC]?.literalValue ?? 0;
/*console.debug(
opCode,
this.memory.slice(index, index + 4).map((val) => val.literalValue)
);*/
switch (opCode.instruction) {
case Instruction.add:
if (debug) {
console.debug(`Adding ${paramA}+${paramB} and writing ${paramA + paramB} to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA + paramB);
index += 4;
break;
case Instruction.mul:
if (debug) {
console.debug(`Multiplying ${paramA}*${paramB} and writing ${paramA * paramB} to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA * paramB);
index += 4;
break;
case Instruction.inp:
this.memory[valueA] = await new Promise<OpCode>((resolve, reject) => {
rl.question(`[${index.toString().padStart(5, "0")}]> `, (answer) => {
try {
const op = new OpCode(answer);
if (debug) {
console.debug(`Writing opCode with value ${op.literalValue} to ${valueA}`);
}
resolve(op);
} catch (e) {
reject(e);
}
});
});
index += 2;
break;
case Instruction.out:
if (debug) {
console.debug(`Outputting ${paramA}`);
}
output.push(paramA);
index += 2;
break;
case Instruction.jnz:
if (debug) {
console.debug(`Testing if ${paramA}!=0, if so, jumping to ${paramB}`);
}
if (paramA !== 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.jz:
if (debug) {
console.debug(`Testing if ${paramA}==0, if so, jumping to ${paramB}`);
}
if (paramA === 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.lt:
if (debug) {
console.debug(`Testing if ${paramA}<${paramB}, writing result to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA < paramB ? 1 : 0);
index += 4;
break;
case Instruction.eq:
if (debug) {
console.debug(`Testing if ${paramA}==${paramB}, writing result to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA === paramB ? 1 : 0);
index += 4;
break;
case Instruction.end:
console.log("Final output:", output);
return this.memory;
}
}
} catch (e) {
console.debug(`Execution failed at index ${index}. Dumping memory.`);
if (debug) {
debugLog!.write(
`${debugIteration.toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
throw e;
}
console.log("Final output:", output);
return this.memory;
}
reset() {
this.memory = this.initialMemory;
}
static memdump(memory: Memory) {
return memory.map((op) => op.toString()).join(",");
}
}
async function main(code: string) {
const memdump: Memory = code.split(",").map((val) => new OpCode(val));
const machine = new Machine(memdump);
const result = await machine.run();
rl.close();
return; // result ? Machine.memdump(result) : result;
}
const input = fs.readFileSync("input").toString();
main(input)
.then(console.log)
.catch((...args) => {
rl.close();
console.error(args);
});

View file

@ -0,0 +1,72 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.8":
version "14.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
readline@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/readline/-/readline-1.3.0.tgz#c580d77ef2cfc8752b132498060dc9793a7ac01c"
integrity sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,38 @@
import * as fs from "fs";
const input = fs.readFileSync("input").toString();
async function main() {
let orbits = new Map<string, string>();
input.split("\r\n").forEach((line) => orbits.set(line.split(")")[1], line.split(")")[0]));
let distanceToYou = new Map<string, number>();
let orbit = orbits.get("YOU")!;
let distance = 0;
while (true) {
distanceToYou.set(orbit, distance);
const newOrbit = orbits.get(orbit);
if (newOrbit !== undefined) {
orbit = newOrbit;
distance++;
} else {
break;
}
}
orbit = orbits.get("SAN")!;
distance = 0;
while (true) {
let pathValue = distanceToYou.get(orbit);
if (pathValue !== undefined) {
distance += pathValue;
break;
}
orbit = orbits.get(orbit)!;
distance++;
}
return distance;
}
main().then(console.log).catch(console.error);

View file

@ -0,0 +1,6 @@
import * as fs from "fs";
const input = fs.readFileSync("input");
async function main() {}
main().then(console.log).catch(console.error);

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

View file

@ -0,0 +1 @@
3,8,1001,8,10,8,105,1,0,0,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99

View file

@ -0,0 +1,8 @@
00001;00000;[3,8,1001,8,10,8,105,1,19,1,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]
00002;00002;[3,8,1001,8,10,8,105,1,9,1,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]
00003;00006;[3,8,1001,8,10,8,105,1,19,1,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]
00004;00422;[3,8,1001,8,10,8,105,1,19,1,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]
00005;00424;[3,8,1001,8,10,8,105,1,19,0,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]
00006;00428;[3,8,1001,8,10,8,105,1,19,1,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]
00007;00430;[3,8,1001,8,10,8,105,1,19,1,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]
00007;00430;[3,8,1001,8,10,8,105,1,19,1,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99]

View file

@ -0,0 +1,17 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=120",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.8",
"readline": "^1.3.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,287 @@
import * as fs from "fs";
const fsPromises = fs.promises;
import * as readline from "readline";
const rl = readline.createInterface(process.stdin, process.stdout);
enum ParameterMode {
position = 0,
immediate = 1,
}
enum Instruction {
add = 1,
mul = 2,
inp = 3,
out = 4,
jnz = 5,
jz = 6,
lt = 7,
eq = 8,
end = 99,
}
type Memory = Array<OpCode>;
class OpCode {
private _executable: boolean = false;
private _literalValue: number = 0;
private _instruction?: Instruction;
private _parameterModes?: [a: ParameterMode, b: ParameterMode, c: ParameterMode];
constructor(value: number);
constructor(value: string);
constructor(value: string | number) {
let valueNumber: number;
let valueString: string;
if (typeof value === "number") {
valueNumber = value;
valueString = value.toString();
} else {
valueString = value;
valueNumber = parseInt(value);
}
if (isNaN(valueNumber)) throw new Error(`Invalid value '${value}' for OpCode.`);
valueString = valueString.padStart(5, "0");
this._literalValue = valueNumber;
if (valueNumber >= 0 && valueNumber <= 99999 && valueNumber % 100 in Instruction) {
const parameterModes: [ParameterMode, ParameterMode, ParameterMode] = [
Math.floor(valueNumber / 10000) % 10,
Math.floor(valueNumber / 1000) % 10,
Math.floor(valueNumber / 100) % 10,
];
if (parameterModes.filter((val) => val in ParameterMode).length === 3) {
this._parameterModes = parameterModes;
this._instruction = valueNumber % 100;
} else {
return;
}
this._executable = true;
}
}
get executable() {
if (this._instruction === undefined || this._parameterModes === undefined) {
this._executable = false;
}
return this._executable;
}
get literalValue() {
return this._literalValue;
}
get instruction() {
return this._instruction;
}
get parameterModes() {
return this._parameterModes;
}
toString() {
return this.literalValue.toString();
}
}
class Machine {
private readonly initialMemory: Memory;
private memory: Memory;
constructor(program: Memory) {
this.initialMemory = program;
this.memory = program;
}
async run(simulatedInput: string[], debug: boolean = false) {
let index = 0;
let debugIteration = 0;
const debugLog = debug ? await fsPromises.open("out.log", "w") : undefined;
let output: number[] = [];
try {
while (index < this.memory.length) {
/*for (let i = 0; i < this.memory.length; i++) {
this.memory[i] = this.memory[i] ?? new OpCode(0);
}*/
if (debug) {
debugLog!.write(
`${(++debugIteration).toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
const opCode = this.memory[index];
if (!opCode.executable) {
throw new Error(`Tried executing non-executable value ${this.memory[index]} at index ${index}`);
}
const parameterModes = opCode.parameterModes!;
const valueA = this.memory[index + 1]?.literalValue ?? 0;
const valueB = this.memory[index + 2]?.literalValue ?? 0;
const valueC = this.memory[index + 3]?.literalValue ?? 0;
const paramA = parameterModes[2] === ParameterMode.immediate ? valueA : this.memory[valueA]?.literalValue ?? 0;
const paramB = parameterModes[1] === ParameterMode.immediate ? valueB : this.memory[valueB]?.literalValue ?? 0;
const paramC = parameterModes[0] === ParameterMode.immediate ? valueC : this.memory[valueC]?.literalValue ?? 0;
/*console.debug(
opCode,
this.memory.slice(index, index + 4).map((val) => val.literalValue)
);*/
switch (opCode.instruction) {
case Instruction.add:
if (debug) {
console.debug(`Adding ${paramA}+${paramB} and writing ${paramA + paramB} to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA + paramB);
index += 4;
break;
case Instruction.mul:
if (debug) {
console.debug(`Multiplying ${paramA}*${paramB} and writing ${paramA * paramB} to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA * paramB);
index += 4;
break;
case Instruction.inp:
/*this.memory[valueA] = await new Promise<OpCode>((resolve, reject) => {
rl.question(`[${index.toString().padStart(5, "0")}]> `, (answer) => {
try {
const op = new OpCode(answer);
resolve(op);
} catch (e) {
reject(e);
}
});
});*/
if (simulatedInput.length === 0) throw new Error("Asked for more input than was given!");
if (debug) console.debug(simulatedInput, simulatedInput[0]);
let inputValue = simulatedInput.shift()!;
if (debug) {
console.debug(`Writing opCode with value ${inputValue} to ${valueA}`);
}
this.memory[valueA] = new OpCode(inputValue);
index += 2;
break;
case Instruction.out:
if (debug) {
console.debug(`Outputting ${paramA}`);
}
output.push(paramA);
index += 2;
break;
case Instruction.jnz:
if (debug) {
console.debug(`Testing if ${paramA}!=0, if so, jumping to ${paramB}`);
}
if (paramA !== 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.jz:
if (debug) {
console.debug(`Testing if ${paramA}==0, if so, jumping to ${paramB}`);
}
if (paramA === 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.lt:
if (debug) {
console.debug(`Testing if ${paramA}<${paramB}, writing result to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA < paramB ? 1 : 0);
index += 4;
break;
case Instruction.eq:
if (debug) {
console.debug(`Testing if ${paramA}==${paramB}, writing result to ${valueC}`);
}
this.memory[valueC] = new OpCode(paramA === paramB ? 1 : 0);
index += 4;
break;
case Instruction.end:
return output;
default:
throw new Error(`HCF: Not implemented <${opCode.instruction}>`);
}
}
} catch (e) {
// console.debug(`Execution failed at index ${index}. Dumping memory.`);
if (debug) {
debugLog!.write(
`${debugIteration.toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
throw e;
}
return output;
}
reset() {
this.memory = this.initialMemory;
}
static memdump(memory: Memory) {
return memory.map((op) => op.toString()).join(",");
}
}
function permute<T>(inputArr: T[]) {
let result: T[][] = [];
function _permute(arr: T[], m: T[] = []) {
if (arr.length === 0) {
result.push(m);
} else {
for (let i = 0; i < arr.length; i++) {
let curr = arr.slice();
let next = curr.splice(i, 1);
_permute(curr.slice(), m.concat(next));
}
}
}
_permute(inputArr);
return result;
}
async function main(code: string) {
const memdump: Memory = code.split(",").map((val) => new OpCode(val));
const machine = new Machine(memdump);
let maxResult: number = -Infinity;
const permutations = permute([4, 3, 2, 1, 0].map((n) => n.toString()));
for (const value of permutations) {
try {
let curResult = 0;
let result: number = -Infinity;
for (const setting of value) {
result = (await machine.run([setting, curResult.toString()], maxResult === -Infinity))[0];
curResult = result;
}
maxResult = Math.max(result, maxResult);
machine.reset();
console.debug("Testing", value, "got", result);
} catch {
console.error(value);
}
}
rl.close();
return maxResult;
}
const input = fs.readFileSync("input").toString();
main(input)
.then(console.log)
.catch((...args) => {
rl.close();
console.error(args);
});

View file

@ -0,0 +1,2 @@
// DNF
// USED https://www.philipp-doblhofer.at/en/blog/advent-of-code-2019-day-7/

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,72 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.8":
version "14.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
readline@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/readline/-/readline-1.3.0.tgz#c580d77ef2cfc8752b132498060dc9793a7ac01c"
integrity sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=180",
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=120",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},

View file

@ -0,0 +1,17 @@
import * as fs from "fs";
const input = fs.readFileSync("input").toString();
async function main() {
let layers = input.replace(/(.{150})/g, "$1,").split(",");
let layers2: [number, number, number, string][] = layers.map((layer) => [
layer.match(/0/g)?.length ?? 0,
layer.match(/1/g)?.length ?? 0,
layer.match(/2/g)?.length ?? 0,
layer,
]);
let selected = layers2.sort((a, b) => a[0] - b[0])[1];
return [selected, selected[0] + selected[1] + selected[2], selected[1] * selected[2]];
}
main().then(console.log).catch(console.error);

View file

@ -0,0 +1,19 @@
import * as fs from "fs";
const input = fs.readFileSync("input").toString();
async function main() {
let image: string[] = Array(6 * 25).fill("2"); //Array(6).map(_=>Array(25))
let layers = input.replace(/(.{150})/g, "$1,").split(",");
for (const layer of layers) {
for (let i = 0; i < layer.length; i++) {
if(image[i] === "2") {
image[i] = layer[i]
}
}
}
return image.join("").replace(/(.{25})/g, "$1\n");
}
main().then(console.log).catch(console.error);

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.8":
version "14.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

View file

@ -0,0 +1 @@
1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1102,3,1,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1101,0,31,1019,1101,25,0,1008,1102,35,1,1009,1102,422,1,1029,1102,1,21,1005,1102,1,734,1027,1102,29,1,1000,1101,32,0,1018,1102,28,1,1016,1101,0,38,1015,1101,0,378,1023,1101,30,0,1017,1102,1,381,1022,1101,0,37,1006,1102,1,1,1021,1101,0,24,1011,1102,1,23,1002,1101,0,0,1020,1101,0,20,1007,1101,427,0,1028,1101,26,0,1014,1101,27,0,1010,1101,0,39,1001,1101,34,0,1012,1102,1,36,1013,1101,0,33,1003,1101,804,0,1025,1101,737,0,1026,1102,1,809,1024,1102,1,22,1004,109,9,1201,-7,0,63,1008,63,20,63,1005,63,205,1001,64,1,64,1106,0,207,4,187,1002,64,2,64,109,2,21102,40,1,1,1008,1012,40,63,1005,63,233,4,213,1001,64,1,64,1106,0,233,1002,64,2,64,109,4,1208,-7,25,63,1005,63,255,4,239,1001,64,1,64,1106,0,255,1002,64,2,64,109,-24,1207,10,38,63,1005,63,271,1105,1,277,4,261,1001,64,1,64,1002,64,2,64,109,25,21107,41,40,-3,1005,1013,293,1105,1,299,4,283,1001,64,1,64,1002,64,2,64,109,5,1205,-1,311,1106,0,317,4,305,1001,64,1,64,1002,64,2,64,109,-23,1202,6,1,63,1008,63,22,63,1005,63,339,4,323,1105,1,343,1001,64,1,64,1002,64,2,64,109,1,2101,0,2,63,1008,63,37,63,1005,63,367,1001,64,1,64,1106,0,369,4,349,1002,64,2,64,109,29,2105,1,-5,1106,0,387,4,375,1001,64,1,64,1002,64,2,64,109,-26,2101,0,0,63,1008,63,23,63,1005,63,409,4,393,1106,0,413,1001,64,1,64,1002,64,2,64,109,26,2106,0,0,4,419,1106,0,431,1001,64,1,64,1002,64,2,64,109,-17,21108,42,42,6,1005,1017,453,4,437,1001,64,1,64,1106,0,453,1002,64,2,64,109,7,21101,43,0,-8,1008,1010,44,63,1005,63,477,1001,64,1,64,1105,1,479,4,459,1002,64,2,64,109,-7,1206,10,495,1001,64,1,64,1106,0,497,4,485,1002,64,2,64,109,-5,2108,36,0,63,1005,63,513,1106,0,519,4,503,1001,64,1,64,1002,64,2,64,109,3,2102,1,-5,63,1008,63,22,63,1005,63,541,4,525,1105,1,545,1001,64,1,64,1002,64,2,64,109,3,1207,-6,38,63,1005,63,567,4,551,1001,64,1,64,1105,1,567,1002,64,2,64,109,-15,2107,20,8,63,1005,63,585,4,573,1106,0,589,1001,64,1,64,1002,64,2,64,109,-1,1208,5,36,63,1005,63,609,1001,64,1,64,1106,0,611,4,595,1002,64,2,64,109,30,21101,44,0,-7,1008,1019,44,63,1005,63,633,4,617,1106,0,637,1001,64,1,64,1002,64,2,64,109,-25,1201,0,0,63,1008,63,39,63,1005,63,659,4,643,1105,1,663,1001,64,1,64,1002,64,2,64,109,27,1206,-8,677,4,669,1106,0,681,1001,64,1,64,1002,64,2,64,109,-28,2108,29,0,63,1005,63,703,4,687,1001,64,1,64,1106,0,703,1002,64,2,64,109,5,21107,45,46,7,1005,1012,725,4,709,1001,64,1,64,1106,0,725,1002,64,2,64,109,30,2106,0,-8,1105,1,743,4,731,1001,64,1,64,1002,64,2,64,109,-22,21102,46,1,4,1008,1017,44,63,1005,63,767,1001,64,1,64,1105,1,769,4,749,1002,64,2,64,109,-15,1202,10,1,63,1008,63,23,63,1005,63,793,1001,64,1,64,1106,0,795,4,775,1002,64,2,64,109,19,2105,1,7,4,801,1105,1,813,1001,64,1,64,1002,64,2,64,109,6,1205,-2,827,4,819,1106,0,831,1001,64,1,64,1002,64,2,64,109,-20,2107,22,2,63,1005,63,851,1001,64,1,64,1106,0,853,4,837,1002,64,2,64,109,20,21108,47,44,-8,1005,1015,869,1105,1,875,4,859,1001,64,1,64,1002,64,2,64,109,-22,2102,1,4,63,1008,63,23,63,1005,63,899,1001,64,1,64,1106,0,901,4,881,4,64,99,21101,0,27,1,21102,915,1,0,1106,0,922,21201,1,28703,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21101,0,942,0,1106,0,922,22101,0,1,-1,21201,-2,-3,1,21101,957,0,0,1105,1,922,22201,1,-1,-2,1105,1,968,21201,-2,0,-2,109,-3,2105,1,0

View file

@ -0,0 +1,16 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=120",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.8",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,316 @@
import * as fs from "fs";
import { relative } from "path";
const fsPromises = fs.promises;
import * as readline from "readline";
const rl = readline.createInterface(process.stdin, process.stdout);
enum ParameterMode {
position = 0,
immediate = 1,
relative = 2,
}
enum Instruction {
add = 1,
mul = 2,
inp = 3,
out = 4,
jnz = 5,
jz = 6,
lt = 7,
eq = 8,
rel = 9,
end = 99,
}
type Memory = Array<OpCode>;
class OpCode {
private _executable: boolean = false;
private _literalValue: number = 0;
private _instruction?: Instruction;
private _parameterModes?: [a: ParameterMode, b: ParameterMode, c: ParameterMode];
constructor(value: number);
constructor(value: string);
constructor(value: string | number) {
let valueNumber: number;
let valueString: string;
if (typeof value === "number") {
valueNumber = value;
valueString = value.toString();
} else {
valueString = value;
valueNumber = parseInt(value);
}
if (isNaN(valueNumber)) throw new Error(`Invalid value '${value}' for OpCode.`);
valueString = valueString.padStart(5, "0");
this._literalValue = valueNumber;
if (valueNumber >= 0 && valueNumber <= 99999 && valueNumber % 100 in Instruction) {
const parameterModes: [ParameterMode, ParameterMode, ParameterMode] = [
Math.floor(valueNumber / 10000) % 10,
Math.floor(valueNumber / 1000) % 10,
Math.floor(valueNumber / 100) % 10,
];
if (parameterModes.filter((val) => val in ParameterMode).length === 3) {
this._parameterModes = parameterModes;
this._instruction = valueNumber % 100;
} else {
return;
}
this._executable = true;
}
}
get executable() {
if (this._instruction === undefined || this._parameterModes === undefined) {
this._executable = false;
}
return this._executable;
}
get literalValue() {
return this._literalValue;
}
get instruction() {
return this._instruction;
}
get parameterModes() {
return this._parameterModes;
}
toString() {
return this.literalValue.toString();
}
}
class Machine {
private readonly initialMemory: Memory;
private memory: Memory;
constructor(program: Memory) {
this.initialMemory = program;
this.memory = program;
}
parseParam(value: number, mode: ParameterMode, relativeOffset: number) {
switch (mode) {
case ParameterMode.immediate:
return value;
case ParameterMode.position:
return this.memory[value]?.literalValue ?? 0;
case ParameterMode.relative:
return this.memory[value + relativeOffset]?.literalValue ?? 0;
}
}
async run(debug: boolean = false) {
let index = 0;
let relative = 0;
let debugIteration = 0;
const debugLog = debug ? await fsPromises.open("out.log", "w") : undefined;
let output: number[] = [];
try {
while (index < this.memory.length) {
/*for (let i = 0; i < this.memory.length; i++) {
this.memory[i] = this.memory[i] ?? new OpCode(0);
}*/
if (debug) {
debugLog!.write(
`${(++debugIteration).toString().padStart(5, "0")};${relative
.toString()
.padStart(8, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
const opCode = this.memory[index];
if (!opCode.executable) {
throw new Error(`Tried executing non-executable value ${opCode.literalValue} at index ${index}`);
}
const parameterModes = opCode.parameterModes!;
const valueA = this.memory[index + 1]?.literalValue ?? 0;
const valueB = this.memory[index + 2]?.literalValue ?? 0;
const valueC = this.memory[index + 3]?.literalValue ?? 0;
const paramA = this.parseParam(valueA, parameterModes[2 - 0], relative);
const paramB = this.parseParam(valueB, parameterModes[2 - 1], relative);
const paramC = this.parseParam(valueC, parameterModes[2 - 2], relative);
if (debug) {
console.debug(`${opCode.literalValue}(${valueA}, ${valueB}, ${valueC});${this.memory[1028]?.literalValue}`);
}
switch (opCode.instruction) {
case Instruction.add:
if (debug) {
console.debug(
`Adding ${paramA}+${paramB} and writing ${paramA + paramB} to ${valueC} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA + paramB);
} else {
this.memory[valueC] = new OpCode(paramA + paramB);
}
index += 4;
break;
case Instruction.mul:
if (debug) {
console.debug(
`Multiplying ${paramA}*${paramB} and writing ${paramA * paramB} to ${valueC} - OpCode ${
opCode.literalValue
}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA * paramB);
} else {
this.memory[valueC] = new OpCode(paramA * paramB);
}
index += 4;
break;
case Instruction.inp:
let input = await new Promise<OpCode>((resolve, reject) => {
rl.question(`[${index.toString().padStart(5, "0")}]> `, (answer) => {
try {
const op = new OpCode(answer);
if (debug) {
console.debug(
`Writing opCode with value ${op.literalValue} to ${
parameterModes[2 - 0] === ParameterMode.relative ? valueA + relative : valueA
} - OpCode ${opCode.literalValue}`
);
}
resolve(op);
} catch (e) {
reject(e);
}
});
});
if (parameterModes[2 - 0] === ParameterMode.relative) {
this.memory[valueA + relative] = input;
} else {
this.memory[valueA] = input;
}
index += 2;
break;
case Instruction.out:
if (debug) {
console.debug(`Outputting ${paramA} - OpCode ${opCode.literalValue}`);
}
output.push(paramA);
index += 2;
break;
case Instruction.jnz:
if (debug) {
console.debug(`Testing if ${paramA}!=0, if so, jumping to ${paramB} - OpCode ${opCode.literalValue}`);
}
if (paramA !== 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.jz:
if (debug) {
console.debug(`Testing if ${paramA}==0, if so, jumping to ${paramB} - OpCode ${opCode.literalValue}`);
}
if (paramA === 0) {
index = paramB;
} else {
index += 3;
}
break;
case Instruction.lt:
if (debug) {
console.debug(
`Checking if ${paramA}<${paramB} and writing result to ${
parameterModes[2 - 2] === ParameterMode.relative ? valueC + relative : valueC
} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA < paramB ? 1 : 0);
} else {
this.memory[valueC] = new OpCode(paramA < paramB ? 1 : 0);
}
index += 4;
break;
case Instruction.eq:
if (debug) {
console.debug(
`Checking if ${paramA}==${paramB} and writing result to ${
parameterModes[2 - 2] === ParameterMode.relative ? valueC + relative : valueC
} - OpCode ${opCode.literalValue}`
);
}
if (parameterModes[2 - 2] === ParameterMode.relative) {
this.memory[valueC + relative] = new OpCode(paramA === paramB ? 1 : 0);
} else {
this.memory[valueC] = new OpCode(paramA === paramB ? 1 : 0);
}
index += 4;
break;
case Instruction.rel:
if (debug) {
console.debug(
`Adjusting relative offset from ${relative} +${paramA} to ${relative + paramA} - OpCode ${
opCode.literalValue
}`
);
}
relative += paramA;
index += 2;
break;
case Instruction.end:
console.log("Final output:", output);
return this.memory;
}
}
} catch (e) {
console.debug(`Execution failed at index ${index}. Dumping memory.`);
if (debug) {
debugLog!.write(
`${debugIteration.toString().padStart(5, "0")};${index.toString().padStart(5, "0")};[${this.memory
.map((op) => op.literalValue)
.join(",")}]\n`
);
}
throw e;
}
console.log("Final output:", output);
return this.memory;
}
reset() {
this.memory = this.initialMemory;
}
static memdump(memory: Memory) {
return memory.map((op) => op.toString()).join(",");
}
}
async function main(code: string) {
const memdump: Memory = code.split(",").map((val) => new OpCode(val));
const machine = new Machine(memdump);
const result = await machine.run();
rl.close();
return; // result ? Machine.memdump(result) : result;
}
const input = fs.readFileSync("input").toString();
main(input)
.then(console.log)
.catch((...args) => {
rl.close();
console.error(args);
});

View file

@ -0,0 +1 @@
// Same as solution_a but with input 2 instead of 1

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.8":
version "14.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
yarn-path ".yarn/releases/yarn-1.22.10.cjs"

View file

@ -0,0 +1,16 @@
{
"scripts": {
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=120",
"a": "ts-node solution_a.ts",
"b": "ts-node solution_b.ts"
},
"devDependencies": {
"prettier": "^2.1.2"
},
"dependencies": {
"@types/node": "^14.14.8",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"license": "WTFPL"
}

View file

@ -0,0 +1,69 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^14.14.8":
version "14.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
prettier@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

Some files were not shown because too many files have changed in this diff Show more