-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbestword.js
More file actions
41 lines (33 loc) · 1.08 KB
/
Copy pathbestword.js
File metadata and controls
41 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import fs from 'fs'
fs.readFile('./dict.json', 'utf8', (err, jsonString) => {
const dict = JSON.parse(jsonString)
const wordLength = 7
const NLetterWords = dict.filter((w)=> w.length == wordLength && !w.includes('การ') && !w.includes('ความ'))
console.log('there are ', NLetterWords.length, ' words to play with.')
let results = []
let id = 1
for(const solution of NLetterWords) {
const set = new Set(solution)
if(set.size < wordLength)
continue
let object = {
id,
word: solution
}
results = [...results, object]
id ++
if(id%100 == 0)
console.log('at ', id, 'words')
}
console.log('Found ', results.length, ' pangrams of ', wordLength, ' letters.')
fs.writeFile(`./spellingbee${wordLength}letters.json`, JSON.stringify(results), err=>{})
})
export function splitWord(word) {
const alphas = word.split("")
const out = []
alphas.forEach((a) => {
if (a.match(/[ก-ฮ]/) || a.match(/[ใเแโไาำะๆฯฤา]/))
out.push(a)
})
return out
}