All,
Here is my brute force C implementation which on my medicore machine can do over 10 million guesses per second if compiled with gcc -O3 -funroll-loops brute_force.c I never bothered to learn C properly so please excuse my infantile attempt:
#include <stdio.h> int main () { char *cat1[] = { "enter", "the", "words", "like", "this", NULL }; char *cat2[] = { NULL }; char *cat3[] = { NULL }; char *cat4[] = { NULL }; char *cat5[] = { NULL }; char *cat6[] = { NULL }; char *cat7[] = { NULL }; char *cat8[] = { NULL }; char *cat9[] = { NULL }; char *cat10[] = { NULL }; int i; int max = 0; int count[127]; int score[500]; for (i = 0; i < 128; i++) { count[i] = 0; } for (i = 0; i < 501; i++) { score[i] = (i * i + i) / 2; } char **cat1_p = cat1; while (*cat1_p) { char *cat1_char_p = *cat1_p; while (*cat1_char_p) { count[(int) *cat1_char_p]++; cat1_char_p++; } char **cat2_p = cat2; while (*cat2_p) { char *cat2_char_p = *cat2_p; while (*cat2_char_p) { count[(int) *cat2_char_p]++; cat2_char_p++; } char **cat3_p = cat3; while (*cat3_p) { char *cat3_char_p = *cat3_p; while (*cat3_char_p) { count[(int) *cat3_char_p]++; cat3_char_p++; } char **cat4_p = cat4; while (*cat4_p) { char *cat4_char_p = *cat4_p; while (*cat4_char_p) { count[(int) *cat4_char_p]++; cat4_char_p++; } char **cat5_p = cat5; while (*cat5_p) { char *cat5_char_p = *cat5_p; while (*cat5_char_p) { count[(int) *cat5_char_p]++; cat5_char_p++; } char **cat6_p = cat6; while (*cat6_p) { char *cat6_char_p = *cat6_p; while (*cat6_char_p) { count[(int) *cat6_char_p]++; cat6_char_p++; } char **cat7_p = cat7; while (*cat7_p) { char *cat7_char_p = *cat7_p; while (*cat7_char_p) { count[(int) *cat7_char_p]++; cat7_char_p++; } char **cat8_p = cat8; while (*cat8_p) { char *cat8_char_p = *cat8_p; while (*cat8_char_p) { count[(int) *cat8_char_p]++; cat8_char_p++; } char **cat9_p = cat9; while (*cat9_p) { char *cat9_char_p = *cat9_p; while (*cat9_char_p) { count[(int) *cat9_char_p]+ ++; cat9_char_p++; } char **cat10_p = cat10; while (*cat10_p) { char *cat10_char_p = *cat1 +0_p; while (*cat10_char_p) { count[(int) *cat10_cha +r_p]++; cat10_char_p++; } /* Get Score */ int tot = 0; for (i = 97; i < 123; i++) + { tot += score[count[i]] +; } /* New High Score */ if (tot > max) { max = tot; printf( "%i : [ %s %s %s % +s %s %s %s %s %s %s ]\n", tot, *cat1_p, *cat +2_p, *cat3_p, *cat4_p, *cat5_p, *cat6_p, *cat7_p, *cat8_p, *cat9_p, * +cat10_p ); } /* Subtract Char Counts Be +fore Trying New Word */ char *cat10_sub_p = *cat10 +_p; while (*cat10_sub_p) { count[(int) *cat10_sub +_p]--; cat10_sub_p++; } cat10_p++; } /* Subtract Char Counts Before + Trying New Word */ char *cat9_sub_p = *cat9_p; while (*cat9_sub_p) { count[(int) *cat9_sub_p]-- +; cat9_sub_p++; } cat9_p++; } /* Subtract Char Counts Before Try +ing New Word */ char *cat8_sub_p = *cat8_p; while (*cat8_sub_p) { count[(int) *cat8_sub_p]--; cat8_sub_p++; } cat8_p++; } /* Subtract Char Counts Before Trying +New Word */ char *cat7_sub_p = *cat7_p; while (*cat7_sub_p) { count[(int) *cat7_sub_p]--; cat7_sub_p++; } cat7_p++; } /* Subtract Char Counts Before Trying New +Word */ char *cat6_sub_p = *cat6_p; while (*cat6_sub_p) { count[(int) *cat6_sub_p]--; cat6_sub_p++; } cat6_p++; } /* Subtract Char Counts Before Trying New Word + */ char *cat5_sub_p = *cat5_p; while (*cat5_sub_p) { count[(int) *cat5_sub_p]--; cat5_sub_p++; } cat5_p++; } /* Subtract Char Counts Before Trying New Word */ char *cat4_sub_p = *cat4_p; while (*cat4_sub_p) { count[(int) *cat4_sub_p]--; cat4_sub_p++; } cat4_p++; } /* Subtract Char Counts Before Trying New Word */ char *cat3_sub_p = *cat3_p; while (*cat3_sub_p) { count[(int) *cat3_sub_p]--; cat3_sub_p++; } cat3_p++; } /* Subtract Char Counts Before Trying New Word */ char *cat2_sub_p = *cat2_p; while (*cat2_sub_p) { count[(int) *cat2_sub_p]--; cat2_sub_p++; } cat2_p++; } /* Subtract Char Counts Before Trying New Word */ char *cat1_sub_p = *cat1_p; while (*cat1_sub_p) { count[(int) *cat1_sub_p]--; cat1_sub_p++; } cat1_p++; } return(0); }

Cheers - L~R


In reply to Challenge: Letter Power Revisited (Brute Force) by Limbic~Region
in thread Challenge: Letter Power Revisited by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.