Skip to content
Myr

Improve alphabet bruteforcer

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrey Sitnik · committed by Andrey Sitnik · parent 21b99f7 · Browse files · 3 files+18 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−26 removed

  • tests:+16 added−25 removed
  • other:+2 added−1 removed

3 files+18 added−26 removed

modified:test/alphabet+7 added-22 removed
33 unmodified lines
34}3536var newline = false3738var all = js.length * js.length * js.length38var all = js.length * (js.length + 1) * (js.length + 1)39var step = 040var lastPart = 04142function print (str) {43 process.stdout.write(str)44 newline = true45}4647function printLine (str) {48 if (newline) process.stdout.write('\n')49 newline = false43 process.stdout.write(str + '\n')44}4546new Promise(function (resolve) {
10 unmodified lines
57 worker.on('message', function (data) {58 if (data.finished) {59 finished += 160 if (finished === WORKERS) {68 printLine(69 chalk.bold(step) + ' variants were checked. The best alphabet:\n' +70 chalk.green(best.alphabet)71 )61 print('The best alphabet:\n' + chalk.bold.green(best.alphabet))62 resolve()63 }64 } else {75 if (data.size && data.size < best.size) {65 if (data.size < best.size) {66 if (newline) process.stdout.write('\n')67 newline = false68 best = data79 printLine(best.alphabet)69 print(best.alphabet)70 }81 step += 182 var part = Math.floor(80 * 100 * step / all)71 step += data.steps72 var part = Math.floor(100 * step / all)73 if (part > lastPart) {74 lastPart = part85 if (part % 80 === 0) {86 print(chalk.gray('.'))75 print(chalk.gray(part + '%'))87 printLine(chalk.gray((part / 80) + '%'))88 } else {89 print(chalk.gray('.'))90 }76 }77 }78 })79 worker.on('error', function (e) {
4 unmodified lines
modified:test/alphabet-worker.js+9 added-3 removed
modified:package.json+2 added-1 removed
30 unmodified lines
31 "eslint-plugin-node": "^7.0.1",32 "eslint-plugin-promise": "^4.0.1",33 "eslint-plugin-security": "^1.4.0",34 "eslint-plugin-standard": "^4.0.0",35 "gzip-size": "^5.0.0",36 "html-webpack-plugin": "^3.2.0",37 "jest": "^23.6.0",38 "jsdoc": "^3.5.5",39 "lint-staged": "^7.3.0",
14 unmodified lines
54 "lint-staged": "lint-staged",55 "spellcheck": "yarn docs && yaspeller-ci *.md docs/*.html",56 "clean": "rimraf docs/ coverage/",57 "docs": "jsdoc -d docs *.js async/*.js",57 "lint": "eslint-ci *.js async/*.js test/{benchmark,bruteforce} test/*.js test/**/*.js",58 "lint": "eslint-ci *.js async/*.js test/{benchmark,alphabet} test/*.js test/**/*.js",59 "test": "jest --coverage && yarn lint && size-limit && yarn spellcheck",60 "start": "webpack-dev-server --config test/demo/webpack.config"61 },62 "size-limit": [
115 unmodified lines