I'm a little rusty, but this looked fun and I took a stab at it. Here's a convaluted, winding, unoptimized memory hog that generates a high scoring solution, but not always the highest possible score given arbitrary lines of input...
#!/usr/bin/perl -w use strict; my @lines=<DATA>; my %hash = (); my %highscores = (); my @final_words = (); my $final_score = 0; my $longword = ''; for my $letter ( "a" .. "z" ) { my $line = ''; for (@lines) { $line = $_; my @words = split; for my $word (@words) { my $tmp = scalar grep {/$letter/} split (//,$word); if (!$hash{$line}{$letter}{highscore} || $hash{$line}{$letter}{high +score} < $tmp) { $hash{$letter}{$line}{highscore} = $tmp; $hash{$letter}{$line}{word} = $word; $hash{$line}{$letter}{highscore} = $tmp; $hash{$line}{$letter}{word} = $word; } } } $highscores{$letter} = 0; $highscores{$letter} += $hash{$letter}{$_}{highscore} for keys %{$has +h{$letter}}; if (!$highscores{bigletter}{score} || $highscores{bigletter}{score} < + $highscores{$letter}) { $highscores{bigletter}{score} = $highscores{$letter}; $highscores{bigletter}{letter} = $letter; } } my $bl = $highscores{bigletter}{letter}; print "Letter with highest score is \"$bl\" with $highscores{bigletter +}{score} occurrences\n"; for my $line (keys %{$hash{$bl}}) { push @final_words,$hash{$line}{$bl}{word}; } print "\nWords chosen:\n"; print "$_\n" for @final_words; $longword .= $_ for @final_words; my @final_letters = split (//,$longword); for my $letter ( "a" .. "z" ) { my $count = grep {/$letter/} @final_letters; $final_score += ($count * $count + $count) / 2; } print "\nFinal score: $final_score\n"; __DATA__ alabama arkansas alaska delaware hawaii indiana kansas montana delawar +e sazerac sangrita radiator gastank engine heater fender wheel detent battery clutch mirr +or window alloy amalgam vanadium copper steel rutabaga limabean cress carrot sorrel squash cabbage pepper lettuce be +et leek celery endive rhubarb parsnip pumpkin azalia camellia dahlia gardenia gentian vervain canna hepatica bluebel +l anemone oleander lasagna macaroni pastina gnocchi tortelli alfabeto mascagni britten menotti unamas tacotime pizzahut tacobell panago tacomayo edojapan hardees caramel marzipan taiglach taffy brittle fondant toffee dragee __OUTPUT__ Letter with highest score is "a" with 26 occurrences Words chosen: alabama unamas sazerac radiator lasagna amalgam caramel azalia mascagni rutabaga Final score: 457
Note the score is less than the shown maximum of 474 for this data set.

In reply to Re: Challenge: Letter Power Revisited by delirium
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.