day 11 done
This commit is contained in:
parent
8e7247a941
commit
e826b6db33
86
day11/.gitignore
vendored
Normal file
86
day11/.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
|
27
day11/inp
Normal file
27
day11/inp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Monkey 0:
|
||||||
|
Starting items: 79, 98
|
||||||
|
Operation: new = old * 19
|
||||||
|
Test: divisible by 23
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 3
|
||||||
|
|
||||||
|
Monkey 1:
|
||||||
|
Starting items: 54, 65, 75, 74
|
||||||
|
Operation: new = old + 6
|
||||||
|
Test: divisible by 19
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 0
|
||||||
|
|
||||||
|
Monkey 2:
|
||||||
|
Starting items: 79, 60, 97
|
||||||
|
Operation: new = old * old
|
||||||
|
Test: divisible by 13
|
||||||
|
If true: throw to monkey 1
|
||||||
|
If false: throw to monkey 3
|
||||||
|
|
||||||
|
Monkey 3:
|
||||||
|
Starting items: 74
|
||||||
|
Operation: new = old + 3
|
||||||
|
Test: divisible by 17
|
||||||
|
If true: throw to monkey 0
|
||||||
|
If false: throw to monkey 1
|
55
day11/input
Normal file
55
day11/input
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
Monkey 0:
|
||||||
|
Starting items: 89, 95, 92, 64, 87, 68
|
||||||
|
Operation: new = old * 11
|
||||||
|
Test: divisible by 2
|
||||||
|
If true: throw to monkey 7
|
||||||
|
If false: throw to monkey 4
|
||||||
|
|
||||||
|
Monkey 1:
|
||||||
|
Starting items: 87, 67
|
||||||
|
Operation: new = old + 1
|
||||||
|
Test: divisible by 13
|
||||||
|
If true: throw to monkey 3
|
||||||
|
If false: throw to monkey 6
|
||||||
|
|
||||||
|
Monkey 2:
|
||||||
|
Starting items: 95, 79, 92, 82, 60
|
||||||
|
Operation: new = old + 6
|
||||||
|
Test: divisible by 3
|
||||||
|
If true: throw to monkey 1
|
||||||
|
If false: throw to monkey 6
|
||||||
|
|
||||||
|
Monkey 3:
|
||||||
|
Starting items: 67, 97, 56
|
||||||
|
Operation: new = old * old
|
||||||
|
Test: divisible by 17
|
||||||
|
If true: throw to monkey 7
|
||||||
|
If false: throw to monkey 0
|
||||||
|
|
||||||
|
Monkey 4:
|
||||||
|
Starting items: 80, 68, 87, 94, 61, 59, 50, 68
|
||||||
|
Operation: new = old * 7
|
||||||
|
Test: divisible by 19
|
||||||
|
If true: throw to monkey 5
|
||||||
|
If false: throw to monkey 2
|
||||||
|
|
||||||
|
Monkey 5:
|
||||||
|
Starting items: 73, 51, 76, 59
|
||||||
|
Operation: new = old + 8
|
||||||
|
Test: divisible by 7
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 1
|
||||||
|
|
||||||
|
Monkey 6:
|
||||||
|
Starting items: 92
|
||||||
|
Operation: new = old + 5
|
||||||
|
Test: divisible by 11
|
||||||
|
If true: throw to monkey 3
|
||||||
|
If false: throw to monkey 0
|
||||||
|
|
||||||
|
Monkey 7:
|
||||||
|
Starting items: 99, 76, 78, 76, 79, 90, 89
|
||||||
|
Operation: new = old + 7
|
||||||
|
Test: divisible by 5
|
||||||
|
If true: throw to monkey 4
|
||||||
|
If false: throw to monkey 5
|
5
day11/package.json
Normal file
5
day11/package.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^18.11.10"
|
||||||
|
}
|
||||||
|
}
|
93
day11/solution.ts
Normal file
93
day11/solution.ts
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
|
||||||
|
const fileString = readFileSync(join(__dirname, "input"), 'utf-8');
|
||||||
|
var rows = fileString.split("Monkey ");
|
||||||
|
|
||||||
|
rows = rows.map(val => {
|
||||||
|
return val.trim();
|
||||||
|
});
|
||||||
|
rows = rows.filter(val => {
|
||||||
|
return val.length > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
var mdata = rows.map(val => {
|
||||||
|
return val.split("\n").map(vval => {
|
||||||
|
return vval.trim();
|
||||||
|
}).filter(vval => {
|
||||||
|
return vval.length >0;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
var monkeys = {}
|
||||||
|
|
||||||
|
for (const monkey of mdata) {
|
||||||
|
const monkeyName = +monkey[0].split(":")[0].trim();
|
||||||
|
const items = monkey[1].split(":")[1].trim().split(",").map(val => {
|
||||||
|
return BigInt(+val);
|
||||||
|
});
|
||||||
|
const op = monkey[2].split(":")[1].trim().split("=")[1].trim();
|
||||||
|
const divisTest = +monkey[3].split("by ")[1].trim();
|
||||||
|
const trueTarget = +monkey[4].split("monkey ")[1].trim();
|
||||||
|
const falseTarget = +monkey[5].split("monkey ")[1].trim();
|
||||||
|
monkeys[monkeyName] = {};
|
||||||
|
|
||||||
|
monkeys[monkeyName]['items'] = items;
|
||||||
|
monkeys[monkeyName]['operation'] = op;
|
||||||
|
monkeys[monkeyName]['test'] = BigInt(divisTest);
|
||||||
|
monkeys[monkeyName]['trueTarget'] = trueTarget;
|
||||||
|
monkeys[monkeyName]['falseTarget'] = falseTarget;
|
||||||
|
monkeys[monkeyName]['inspections'] = BigInt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(monkeys);
|
||||||
|
|
||||||
|
const ROUNDS = 10000;
|
||||||
|
|
||||||
|
var lcms = [];
|
||||||
|
for (const m in monkeys) {
|
||||||
|
lcms.push(monkeys[m]['test']);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lcm = BigInt(lcms.reduce((a, b) => {
|
||||||
|
return a * b;
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (var i = 0; i < ROUNDS; i++) {
|
||||||
|
for (const m in monkeys) {
|
||||||
|
const monkey = monkeys[m];
|
||||||
|
const ilen = monkey['items'].length;
|
||||||
|
for (var j = 0; j < ilen; j++) {
|
||||||
|
var item = BigInt(monkey['items'].shift());
|
||||||
|
|
||||||
|
var opstr = monkey['operation'].replace(/old/gi, item);
|
||||||
|
var opitms = opstr.split(" ");
|
||||||
|
opitms[0] = "BigInt(" + opitms[0] + ")";
|
||||||
|
opitms[2] = "BigInt(" + opitms[2] + ")";
|
||||||
|
opstr = opitms.join(" ");
|
||||||
|
|
||||||
|
item = BigInt(eval(opstr)) % lcm;
|
||||||
|
if ((item % monkey['test']) == BigInt(0)) {
|
||||||
|
monkeys[monkey['trueTarget']]['items'].push(item);
|
||||||
|
} else {
|
||||||
|
monkeys[monkey['falseTarget']]['items'].push(item);
|
||||||
|
}
|
||||||
|
monkey['inspections'] += BigInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(monkeys);
|
||||||
|
|
||||||
|
var insCount = [];
|
||||||
|
for (const m in monkeys) {
|
||||||
|
insCount.push(monkeys[m]['inspections']);
|
||||||
|
}
|
||||||
|
console.log(insCount);
|
||||||
|
insCount = insCount.sort().slice(insCount.length - 2);
|
||||||
|
console.log(insCount);
|
||||||
|
|
||||||
|
console.log(insCount.reduce((a, b) => {
|
||||||
|
return a * b;
|
||||||
|
}));
|
7
day11/tsconfig.json
Normal file
7
day11/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": [
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
86
day12/.gitignore
vendored
Normal file
86
day12/.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
|
0
day12/input
Normal file
0
day12/input
Normal file
5
day12/package.json
Normal file
5
day12/package.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^18.11.10"
|
||||||
|
}
|
||||||
|
}
|
14
day12/solution.ts
Normal file
14
day12/solution.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(rows);
|
7
day12/tsconfig.json
Normal file
7
day12/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": [
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user