Skip to content

Instantly share code, notes, and snippets.

@nin-jin
Last active May 19, 2016 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nin-jin/4fea1514b73a28165032b29ec592f761 to your computer and use it in GitHub Desktop.
Save nin-jin/4fea1514b73a28165032b29ec592f761 to your computer and use it in GitHub Desktop.
'use strict'
imports:
var fs = require('fs')
var zlib = require('zlib')
var solution = require('./solution') // { init : dict => void , test : word => boolean }
dictionary_generation:
var dict = '';
fs.readFileSync( 'unique.txt' ).toString()
.split( '\n' )
.forEach( word => {
// fill dict
} )
var gzOptions = { chunkSize : 1024*1024 , level : 9 , strategy : 3 }
fs.writeFileSync( 'dict.bin.gz' , zlib.gzipSync( dict , gzOptions ) )
solution_testion:
solution.init( zlib.gunzipSync( fs.readFileSync( 'dict.bin.gz' ) ) )
var stat = {
'true' : { 'true' : 0 , 'false' : 0 } ,
'false' : { 'true' : 0 , 'false' : 0 }
}
var words = {
'true' : fs.readFileSync( 'words.txt' ).toString().toLowerCase().trim().split('\n') ,
'false' : fs.readFileSync( 'nowords.txt' ).toString().toLowerCase().trim().split('\n')
}
var wordsIndex = {}
words[true].forEach( word => {
wordsIndex[ word ] = true
})
var test = { __proto__ : null }
for( var i = 0 ; i < 1000000 ; ++i ) {
var isWord = Math.random() >= .5
var word = words[ isWord ][ Math.floor( Math.random() * words[ isWord ].length ) ]
test[ word ] = wordsIndex[ word ] || false
}
for( var word in test ) ++ stat[ test[ word ] ][ solution.test( word ) ]
console.log( stat )
console.log( ( stat[true][true] + stat[false][false] ) * 100 / Object.keys( test ).length )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment