#!/usr/bin/env php 7) { continue; } $retval[] = $word; $count++; if ($count > 7776) { break; } } // // Put the words in alphabetical order for my own sanity. // sort($retval); fclose($fp); return($retval); } // End of readWordListPeterNorvig() /** * Create our Javascript, but as an array * * @param array $words Our array of words * * @return string Javascript which defines an array of those words */ function getJsArray($words) { $retval = "" . "//\n" . "// Our wordlist.\n" . "//\n" . "// Originally obtained from http://norvig.com/ngrams/\n" . "//\n" . "var wordlist = [\n" ; $beenhere = false; foreach ($words as $key => $value) { if ($beenhere) { $retval .= ",\n"; } $retval .= "\t\"${value}\""; $beenhere = true; } $retval .= "\n" . "];\n" . "\n" ; return($retval); } // End of getJsArray() /** * Our main entry point. */ function main() { // // Read our file // $filename = "count_1w.txt"; $words = readWordListPeterNorvig($filename); //print_r($words); // Debugging // // Match words to dicerolls // //$rolls = getDiceRolls($words); // // Get our Javascript // $js = getJsArray($words); print $js; } // End of main() main();