Win Popcapbookworm forever
Bookworm is a good game. if you don't know it, you can search for it in the app store. I used php to write a program that will always spell out the highest score. Hey, I am good or bad.
Fullwordlist.txt is a dictionary. if the file is too long, it will not be pasted out. if you are interested, you can search for one on the Internet.
-
-
- // Author: huangfeng aiwujia
- If (empty ($ _ POST) die;
- // Receives and processes raw input data. w represents the character, and v represents the corresponding score.
- $ Data = array ();
- For ($ I = 1; $ I <= 24; $ I ++ ){
- Array_push ($ data, array ('W' => strtoupper (trim ($ _ POST ['W '. $ I]), 'V' => trim ($ _ POST ['V '. $ I]);
- }
- // Deduplicate to calculate the sum score
- $ Data_unduplicated = array ();
- Foreach ($ data as $ key => $ value ){
- $ Data_unduplicated [] = implode (',', $ value );
- }
- $ Data_unduplicated = array_unique ($ data_unduplicated );
- // Calculate the occurrence frequency of each character
- $ Data_frequency = array ();
- Foreach ($ data as $ arr ){
- $ Data_frequency [] = $ arr ['w'];
- }
- $ Data_frequency_result = array_count_values ($ data_frequency );
- // Read the vocabulary file into the array
- $ Words = file ('./fullwordlist.txt', FILE_IGNORE_NEW_LINES );
- // Convert all the vocabulary into uppercase English
- $ Words = array_map (function ($ word ){
- Return strtoupper ($ word );
- }, $ Words );
- // Determine the frequency of each word
- $ Result = array ();
- Foreach ($ words as $ k => $ word ){
- // Skip a word containing'
- If (strpos ($ word, "'")> 0) continue;
- // Disassemble $ word to determine the occurrence frequency of each letter
- $ Word_arr = str_split ($ word );
- $ Word_arr_frequency = array_count_values ($ word_arr );
- $ Pass = true;
- Foreach ($ word_arr_frequency as $ character => $ frequency ){
- If (! Array_key_exists ($ character, $ data_frequency_result) | ($ data_frequency_result [$ character] <$ frequency )){
- $ Pass = false;
- }
- }
- // Perform the score calculation operation on the filtered $ word
- If ($ pass ){
- $ Word_value = 0;
- Foreach ($ word_arr as $ wkey => $ wchar ){
- Foreach ($ data_unduplicated as $ data_item ){
- $ Data_item = explode (',', $ data_item );
- // Var_dump ($ data_item); array 0 => string 'A' (length = 1) 1 => string '3' (length = 1)
- If ($ wchar! = $ Data_item [0]) continue;
- $ Word_value + = $ data_item [1];
- }
- }
- $ Result [] = array ('W' => $ word, 'V' => $ word_value );
- }
- }
- // Finally, only the highest score is selected.
- $ K = 0;
- $ Highest = 0;
- Foreach ($ result as $ key => $ item ){
- If (intval ($ item ['V']) >=$ highest ){
- $ Highest = $ item ['V'];
- $ K = $ key;
- }
- }
- Echo 'the highest score is :'. $ result [$ k] ['w']. '('. $ result [$ k] ['V']. ')';;
|