From e826b6db338e316465ed4b8e31a59ef99c993c55 Mon Sep 17 00:00:00 2001 From: Tanishq Dubey Date: Sun, 11 Dec 2022 23:51:59 -0500 Subject: [PATCH] day 11 done --- day11/.gitignore | 86 +++++++++++++++++++++++++++++++++++++++++ day11/inp | 27 +++++++++++++ day11/input | 55 +++++++++++++++++++++++++++ day11/package.json | 5 +++ day11/solution.ts | 93 +++++++++++++++++++++++++++++++++++++++++++++ day11/tsconfig.json | 7 ++++ day12/.gitignore | 86 +++++++++++++++++++++++++++++++++++++++++ day12/inp | 0 day12/input | 0 day12/package.json | 5 +++ day12/solution.ts | 14 +++++++ day12/tsconfig.json | 7 ++++ 12 files changed, 385 insertions(+) create mode 100644 day11/.gitignore create mode 100644 day11/inp create mode 100644 day11/input create mode 100644 day11/package.json create mode 100644 day11/solution.ts create mode 100644 day11/tsconfig.json create mode 100644 day12/.gitignore create mode 100644 day12/inp create mode 100644 day12/input create mode 100644 day12/package.json create mode 100644 day12/solution.ts create mode 100644 day12/tsconfig.json diff --git a/day11/.gitignore b/day11/.gitignore new file mode 100644 index 0000000..409c9e1 --- /dev/null +++ b/day11/.gitignore @@ -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 diff --git a/day11/inp b/day11/inp new file mode 100644 index 0000000..30e09e5 --- /dev/null +++ b/day11/inp @@ -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 diff --git a/day11/input b/day11/input new file mode 100644 index 0000000..6085097 --- /dev/null +++ b/day11/input @@ -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 diff --git a/day11/package.json b/day11/package.json new file mode 100644 index 0000000..29c5523 --- /dev/null +++ b/day11/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "@types/node": "^18.11.10" + } +} diff --git a/day11/solution.ts b/day11/solution.ts new file mode 100644 index 0000000..f048abb --- /dev/null +++ b/day11/solution.ts @@ -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; +})); diff --git a/day11/tsconfig.json b/day11/tsconfig.json new file mode 100644 index 0000000..80c821c --- /dev/null +++ b/day11/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "types": [ + "node" + ] + } +} diff --git a/day12/.gitignore b/day12/.gitignore new file mode 100644 index 0000000..409c9e1 --- /dev/null +++ b/day12/.gitignore @@ -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 diff --git a/day12/inp b/day12/inp new file mode 100644 index 0000000..e69de29 diff --git a/day12/input b/day12/input new file mode 100644 index 0000000..e69de29 diff --git a/day12/package.json b/day12/package.json new file mode 100644 index 0000000..29c5523 --- /dev/null +++ b/day12/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "@types/node": "^18.11.10" + } +} diff --git a/day12/solution.ts b/day12/solution.ts new file mode 100644 index 0000000..1bf3911 --- /dev/null +++ b/day12/solution.ts @@ -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); diff --git a/day12/tsconfig.json b/day12/tsconfig.json new file mode 100644 index 0000000..80c821c --- /dev/null +++ b/day12/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "types": [ + "node" + ] + } +}