ensure no dupe letters when generating hints
This commit is contained in:
parent
eab436f4a0
commit
2c5a9332b1
|
@ -1,5 +1,6 @@
|
||||||
const huffman = require('n-ary-huffman')
|
const huffman = require('n-ary-huffman')
|
||||||
const range = require('lodash.range')
|
const range = require('lodash.range')
|
||||||
|
const uniq = require('lodash.uniq')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const MAX_MATCHES = 200
|
const MAX_MATCHES = 200
|
||||||
|
@ -9,8 +10,6 @@ const exec = promisify(require('child_process').exec)
|
||||||
|
|
||||||
const alphabetsDefinition = require('./alphabets.json')
|
const alphabetsDefinition = require('./alphabets.json')
|
||||||
|
|
||||||
const alphabet = (process.argv[2] || '').split('')
|
|
||||||
|
|
||||||
const ALPHABETS_DIR = path.resolve(__dirname, '../alphabets/')
|
const ALPHABETS_DIR = path.resolve(__dirname, '../alphabets/')
|
||||||
|
|
||||||
const items = range(1, MAX_MATCHES).map((i) => ({
|
const items = range(1, MAX_MATCHES).map((i) => ({
|
||||||
|
@ -35,6 +34,11 @@ async function main() {
|
||||||
Object.keys(alphabetsDefinition).forEach(async alphabetName => {
|
Object.keys(alphabetsDefinition).forEach(async alphabetName => {
|
||||||
const alphabet = alphabetsDefinition[alphabetName].split('')
|
const alphabet = alphabetsDefinition[alphabetName].split('')
|
||||||
|
|
||||||
|
if (alphabet.length !== uniq(alphabet).length) {
|
||||||
|
console.error(`ERROR: ${alphabetName} contains duplicate characters`);
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
const alphabetDir = path.resolve(ALPHABETS_DIR, alphabetName)
|
const alphabetDir = path.resolve(ALPHABETS_DIR, alphabetName)
|
||||||
|
|
||||||
await ensureDir(alphabetDir)
|
await ensureDir(alphabetDir)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash.chunk": "^4.2.0",
|
"lodash.chunk": "^4.2.0",
|
||||||
"lodash.range": "^3.2.0",
|
"lodash.range": "^3.2.0",
|
||||||
|
"lodash.uniq": "^4.5.0",
|
||||||
"n-ary-huffman": "^4.0.0"
|
"n-ary-huffman": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,11 @@ lodash.range@^3.2.0:
|
||||||
resolved "https://registry.yarnpkg.com/lodash.range/-/lodash.range-3.2.0.tgz#f461e588f66683f7eadeade513e38a69a565a15d"
|
resolved "https://registry.yarnpkg.com/lodash.range/-/lodash.range-3.2.0.tgz#f461e588f66683f7eadeade513e38a69a565a15d"
|
||||||
integrity sha1-9GHliPZmg/fq3q3lE+OKaaVloV0=
|
integrity sha1-9GHliPZmg/fq3q3lE+OKaaVloV0=
|
||||||
|
|
||||||
|
lodash.uniq@^4.5.0:
|
||||||
|
version "4.5.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
|
||||||
|
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
|
||||||
|
|
||||||
n-ary-huffman@^4.0.0:
|
n-ary-huffman@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/n-ary-huffman/-/n-ary-huffman-4.0.0.tgz#a1b2efff0becf2d98b6591f31a29e0621b2d8320"
|
resolved "https://registry.yarnpkg.com/n-ary-huffman/-/n-ary-huffman-4.0.0.tgz#a1b2efff0becf2d98b6591f31a29e0621b2d8320"
|
||||||
|
|
Loading…
Reference in New Issue