day 10 done
This commit is contained in:
parent
dc2dd99c2a
commit
8e7247a941
86
day10/.gitignore
vendored
Normal file
86
day10/.gitignore
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
node_modules/
|
||||
.node_modules/
|
||||
built/*
|
||||
tests/cases/rwc/*
|
||||
tests/cases/test262/*
|
||||
tests/cases/perf/*
|
||||
!tests/cases/webharness/compilerToString.js
|
||||
test-args.txt
|
||||
~*.docx
|
||||
\#*\#
|
||||
.\#*
|
||||
tests/baselines/local/*
|
||||
tests/baselines/local.old/*
|
||||
tests/services/baselines/local/*
|
||||
tests/baselines/prototyping/local/*
|
||||
tests/baselines/rwc/*
|
||||
tests/baselines/test262/*
|
||||
tests/baselines/reference/projectOutput/*
|
||||
tests/baselines/local/projectOutput/*
|
||||
tests/baselines/reference/testresults.tap
|
||||
tests/services/baselines/prototyping/local/*
|
||||
tests/services/browser/typescriptServices.js
|
||||
src/harness/*.js
|
||||
src/compiler/diagnosticInformationMap.generated.ts
|
||||
src/compiler/diagnosticMessages.generated.json
|
||||
src/parser/diagnosticInformationMap.generated.ts
|
||||
src/parser/diagnosticMessages.generated.json
|
||||
rwc-report.html
|
||||
*.swp
|
||||
build.json
|
||||
*.actual
|
||||
tests/webTestServer.js
|
||||
tests/webTestServer.js.map
|
||||
tests/webhost/*.d.ts
|
||||
tests/webhost/webtsc.js
|
||||
tests/cases/**/*.js
|
||||
!tests/cases/docker/*.js/
|
||||
tests/cases/**/*.js.map
|
||||
*.config
|
||||
scripts/eslint/built/
|
||||
scripts/debug.bat
|
||||
scripts/run.bat
|
||||
scripts/**/*.js
|
||||
scripts/**/*.js.map
|
||||
coverage/
|
||||
internal/
|
||||
**/.DS_Store
|
||||
.settings
|
||||
**/.vs
|
||||
**/.vscode/*
|
||||
!**/.vscode/tasks.json
|
||||
!**/.vscode/settings.template.json
|
||||
!**/.vscode/launch.template.json
|
||||
!**/.vscode/extensions.json
|
||||
!tests/cases/projects/projectOption/**/node_modules
|
||||
!tests/cases/projects/NodeModulesSearch/**/*
|
||||
!tests/baselines/reference/project/nodeModules*/**/*
|
||||
.idea
|
||||
yarn.lock
|
||||
yarn-error.log
|
||||
.parallelperf.*
|
||||
tests/cases/user/*/package-lock.json
|
||||
tests/cases/user/*/node_modules/
|
||||
tests/cases/user/*/**/*.js
|
||||
tests/cases/user/*/**/*.js.map
|
||||
tests/cases/user/*/**/*.d.ts
|
||||
!tests/cases/user/zone.js/
|
||||
!tests/cases/user/bignumber.js/
|
||||
!tests/cases/user/discord.js/
|
||||
tests/baselines/reference/dt
|
||||
.failed-tests
|
||||
TEST-results.xml
|
||||
package-lock.json
|
||||
tests/cases/user/npm/npm
|
||||
tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
|
||||
tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
|
||||
tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
|
||||
tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
|
||||
tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
|
||||
tests/cases/user/create-react-app/create-react-app
|
||||
tests/cases/user/fp-ts/fp-ts
|
||||
tests/cases/user/webpack/webpack
|
||||
tests/cases/user/puppeteer/puppeteer
|
||||
tests/cases/user/axios-src/axios-src
|
||||
tests/cases/user/prettier/prettier
|
||||
.eslintcache
|
1
day10/array.txt
Normal file
1
day10/array.txt
Normal file
@ -0,0 +1 @@
|
||||
[["noop"],["addx","15"],["noop"],["addx","-11"],["noop"],["addx","6"],["noop"],["addx","-3"],["noop"],["addx","5"],["noop"],["addx","-1"],["noop"],["addx","-8"],["noop"],["addx","13"],["noop"],["addx","4"],["noop"],["noop"],["addx","-1"],["noop"],["addx","5"],["noop"],["addx","-1"],["noop"],["addx","5"],["noop"],["addx","-1"],["noop"],["addx","5"],["noop"],["addx","-1"],["noop"],["addx","5"],["noop"],["addx","-1"],["noop"],["addx","-35"],["noop"],["addx","1"],["noop"],["addx","24"],["noop"],["addx","-19"],["noop"],["addx","1"],["noop"],["addx","16"],["noop"],["addx","-11"],["noop"],["noop"],["noop"],["addx","21"],["noop"],["addx","-15"],["noop"],["noop"],["noop"],["addx","-3"],["noop"],["addx","9"],["noop"],["addx","1"],["noop"],["addx","-3"],["noop"],["addx","8"],["noop"],["addx","1"],["noop"],["addx","5"],["noop"],["noop"],["noop"],["noop"],["noop"],["noop"],["addx","-36"],["noop"],["noop"],["addx","1"],["noop"],["addx","7"],["noop"],["noop"],["noop"],["noop"],["addx","2"],["noop"],["addx","6"],["noop"],["noop"],["noop"],["noop"],["noop"],["noop"],["addx","1"],["noop"],["noop"],["noop"],["addx","7"],["noop"],["addx","1"],["noop"],["noop"],["addx","-13"],["noop"],["addx","13"],["noop"],["addx","7"],["noop"],["noop"],["addx","1"],["noop"],["addx","-33"],["noop"],["noop"],["noop"],["noop"],["addx","2"],["noop"],["noop"],["noop"],["noop"],["addx","8"],["noop"],["noop"],["addx","-1"],["noop"],["addx","2"],["noop"],["addx","1"],["noop"],["noop"],["addx","17"],["noop"],["addx","-9"],["noop"],["addx","1"],["noop"],["addx","1"],["noop"],["addx","-3"],["noop"],["addx","11"],["noop"],["noop"],["noop"],["addx","1"],["noop"],["noop"],["addx","1"],["noop"],["noop"],["noop"],["addx","-13"],["noop"],["addx","-19"],["noop"],["addx","1"],["noop"],["addx","3"],["noop"],["addx","26"],["noop"],["addx","-30"],["noop"],["addx","12"],["noop"],["addx","-1"],["noop"],["addx","3"],["noop"],["addx","1"],["noop"],["noop"],["noop"],["noop"],["addx","-9"],["noop"],["addx","18"],["noop"],["addx","1"],["noop"],["addx","2"],["noop"],["noop"],["noop"],["addx","9"],["noop"],["noop"],["noop"],["noop"],["addx","-1"],["noop"],["addx","2"],["noop"],["addx","-37"],["noop"],["addx","1"],["noop"],["addx","3"],["noop"],["noop"],["addx","15"],["noop"],["addx","-21"],["noop"],["addx","22"],["noop"],["addx","-6"],["noop"],["addx","1"],["noop"],["noop"],["addx","2"],["noop"],["addx","1"],["noop"],["noop"],["addx","-10"],["noop"],["noop"],["noop"],["addx","20"],["noop"],["addx","1"],["noop"],["addx","2"],["noop"],["addx","2"],["noop"],["addx","-6"],["noop"],["addx","-11"],["noop"],["noop"],["noop"]]
|
146
day10/inp
Normal file
146
day10/inp
Normal file
@ -0,0 +1,146 @@
|
||||
addx 15
|
||||
addx -11
|
||||
addx 6
|
||||
addx -3
|
||||
addx 5
|
||||
addx -1
|
||||
addx -8
|
||||
addx 13
|
||||
addx 4
|
||||
noop
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx -35
|
||||
addx 1
|
||||
addx 24
|
||||
addx -19
|
||||
addx 1
|
||||
addx 16
|
||||
addx -11
|
||||
noop
|
||||
noop
|
||||
addx 21
|
||||
addx -15
|
||||
noop
|
||||
noop
|
||||
addx -3
|
||||
addx 9
|
||||
addx 1
|
||||
addx -3
|
||||
addx 8
|
||||
addx 1
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -36
|
||||
noop
|
||||
addx 1
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx 6
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 1
|
||||
noop
|
||||
addx -13
|
||||
addx 13
|
||||
addx 7
|
||||
noop
|
||||
addx 1
|
||||
addx -33
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 8
|
||||
noop
|
||||
addx -1
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
addx 17
|
||||
addx -9
|
||||
addx 1
|
||||
addx 1
|
||||
addx -3
|
||||
addx 11
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx -13
|
||||
addx -19
|
||||
addx 1
|
||||
addx 3
|
||||
addx 26
|
||||
addx -30
|
||||
addx 12
|
||||
addx -1
|
||||
addx 3
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -9
|
||||
addx 18
|
||||
addx 1
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
addx 9
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -1
|
||||
addx 2
|
||||
addx -37
|
||||
addx 1
|
||||
addx 3
|
||||
noop
|
||||
addx 15
|
||||
addx -21
|
||||
addx 22
|
||||
addx -6
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
addx -10
|
||||
noop
|
||||
noop
|
||||
addx 20
|
||||
addx 1
|
||||
addx 2
|
||||
addx 2
|
||||
addx -6
|
||||
addx -11
|
||||
noop
|
||||
noop
|
||||
noop
|
141
day10/input
Normal file
141
day10/input
Normal file
@ -0,0 +1,141 @@
|
||||
addx 2
|
||||
addx 3
|
||||
addx 3
|
||||
addx -2
|
||||
addx 4
|
||||
noop
|
||||
addx 1
|
||||
addx 4
|
||||
addx 1
|
||||
noop
|
||||
addx 4
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
addx 5
|
||||
addx -28
|
||||
addx 30
|
||||
noop
|
||||
addx 5
|
||||
addx 1
|
||||
noop
|
||||
addx -38
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx 5
|
||||
addx 3
|
||||
addx 2
|
||||
addx -2
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
addx -2
|
||||
addx 12
|
||||
noop
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx -31
|
||||
addx 32
|
||||
addx 7
|
||||
noop
|
||||
addx -2
|
||||
addx -37
|
||||
addx 1
|
||||
addx 5
|
||||
addx 1
|
||||
noop
|
||||
addx 31
|
||||
addx -25
|
||||
addx -10
|
||||
addx 13
|
||||
noop
|
||||
noop
|
||||
addx 18
|
||||
addx -11
|
||||
addx 3
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
addx 4
|
||||
addx -32
|
||||
addx 15
|
||||
addx 24
|
||||
addx -2
|
||||
noop
|
||||
addx -37
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx 5
|
||||
addx 21
|
||||
addx -20
|
||||
noop
|
||||
addx 6
|
||||
addx 19
|
||||
addx -5
|
||||
addx -8
|
||||
addx -22
|
||||
addx 26
|
||||
addx -22
|
||||
addx 23
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 8
|
||||
addx -10
|
||||
addx -27
|
||||
addx 33
|
||||
addx -27
|
||||
noop
|
||||
addx 34
|
||||
addx -33
|
||||
addx 2
|
||||
addx 19
|
||||
addx -12
|
||||
addx 11
|
||||
addx -20
|
||||
addx 12
|
||||
addx 18
|
||||
addx -11
|
||||
addx -14
|
||||
addx 15
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -33
|
||||
noop
|
||||
addx 1
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 4
|
||||
noop
|
||||
addx 1
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 1
|
||||
noop
|
||||
addx 4
|
||||
addx -17
|
||||
addx 18
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
5
day10/package.json
Normal file
5
day10/package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.10"
|
||||
}
|
||||
}
|
75
day10/solution.ts
Normal file
75
day10/solution.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
const fileString = readFileSync(join(__dirname, "input"), 'utf-8');
|
||||
var rows = fileString.split("\n");
|
||||
|
||||
rows = rows.map(val => {
|
||||
return val.trim();
|
||||
});
|
||||
rows = rows.filter(val => {
|
||||
return val.length > 0;
|
||||
});
|
||||
|
||||
// Parse out the instruction into "micro-ops"
|
||||
|
||||
var cmds = [];
|
||||
|
||||
for (const row of rows) {
|
||||
const inst = row.split(" ");
|
||||
switch(inst[0]) {
|
||||
case "noop":
|
||||
cmds.push(inst);
|
||||
break;
|
||||
case "addx":
|
||||
cmds.push(["noop"]);
|
||||
cmds.push(inst);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(cmds);
|
||||
console.log(cmds.length);
|
||||
|
||||
const breakpoints = [20, 60, 100, 140, 180, 220];
|
||||
|
||||
// Start the VM
|
||||
|
||||
var sums = [];
|
||||
|
||||
var reg_X = 1;
|
||||
var crt_pos = 1;
|
||||
|
||||
for (var i = 0; i < cmds.length; i++) {
|
||||
const cmd = cmds[i];
|
||||
if (breakpoints.indexOf(i + 1) > -1) {
|
||||
sums.push(reg_X * (i + 1));
|
||||
}
|
||||
|
||||
switch(cmd[0]) {
|
||||
case "noop":
|
||||
break;
|
||||
case "addx":
|
||||
reg_X += +cmd[1];
|
||||
break;
|
||||
}
|
||||
// Do TV drawing
|
||||
if (crt_pos > 40) {
|
||||
process.stdout.write("\n");
|
||||
crt_pos = 1;
|
||||
}
|
||||
if (crt_pos >= (reg_X - 1) && (crt_pos <= (reg_X + 1))) {
|
||||
//console.log("cursor: ", crt_pos, " reg ", reg_X, i, cmd);
|
||||
process.stdout.write("#");
|
||||
} else {
|
||||
//console.log("cursor: ", crt_pos, " reg ", reg_X, crt_pos > reg_X - 1, crt_pos < reg_X + 1, cmd);
|
||||
process.stdout.write(".");
|
||||
}
|
||||
|
||||
crt_pos += 1;
|
||||
}
|
||||
process.stdout.write("\n");
|
||||
|
||||
console.log(sums.reduce((a, b) => {
|
||||
return a + b;
|
||||
}));
|
7
day10/tsconfig.json
Normal file
7
day10/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user