# Perl, score: 2655 <s>2630</s> #!perl -l %p = qw{A 1 B 3 C 3 D 2 E 1 F 4 G 2 H 4 I 1 J 8 K 5 L 1 M 3 N 1 O 1 P 3 Q 10 R 1 S 1 T 1 U 1 V 4 W 4 X 8 Y 4 Z 10 x 0}; /[A-Z]+/,push @R,$& for <>; @R = sort{length($b)<=>length($a)}@R; for(@R) {push@W,$_;push@W,"$`x$'" while /./g;push@O,($_)x(1+length)} $l = "AAAAAAAAABBCCDDDDEEEEEEEEEEEEFFGGGHHIIIIIIIIIJKLLLLMMNNNNNNOOOOOOOOPPQRRRRRRSSSSTTTTTTUUUUVVWWXYYZxx"; @S = map {$r='';for$x(A..Z,'x'){$r.="${x}{".(1*s/$x//g).",}"};"^$r\$"} map{"$_"}@W; sub score{$r=0;$r+=$p{$_}for split'',$rr=pop;$r*length$rr} @X = map{score$_}@W; $f = 'x'; for(;;) { $best = -1; $besti = 0; for ($i=0;$i<@S;$i++) { next if $X[$i] < $best; if ($O[$i]!~/^[$f]/ && $l=~$S[$i]) { $best = $X[$i]; $besti = $i; } } if($best < 0){ $ls = score$l; print "left: $l (-$ls)"; $tot -= $ls; print "total: $tot"; exit; } $l=~s/$_// for $W[$besti]=~/./g; $O[$besti]=~/./; $f .= $&; print "$W[$besti]/$O[$besti] ($X[$besti])"; $tot += $X[$besti]; } Use: $ perl ./scrab.pl <~/sowpods.txt OXYPHENBUTAZONE/OXYPHENBUTAZONE (615) MICROEARTHQUAKE/MICROEARTHQUAKE (525) NONOBJECTIVISMS/NONOBJECTIVISMS (465) DAFFADOWNDILLY/DAFFADOWNDILLY (406) PREINTERVIEWIxG/PREINTERVIEWING (345) LITURGIOLOGxSTS/LITURGIOLOGISTS (240) URDEE/URDEE (30) EE/EE (4) AA/AA (4) left: AA (-4) total: 2630 Use of blanks actually does not give that much while significantly slows down the execution: $ perl ./scrab.pl <~/sowpods.txt OXYPHENBUTAZONE/OXYPHENBUTAZONE (615) MICROEARTHQUAKE/MICROEARTHQUAKE (525) NONOBJECTIVISMS/NONOBJECTIVISMS (465) DAFFADOWNDILLY/DAFFADOWNDILLY (406) PREINTERVIEWED/PREINTERVIEWED (322) LITURGIOLOGISTS/LITURGIOLOGISTS (255) RUGAE/RUGAE (30) EE/EE (4) AA/AA (4) left: Axx (-3) total: 2623 After adding some heuristics: $ time perl ./scrab.pl <~/sowpods.txt OXYPHENBUTAZONE/OXYPHENBUTAZONE (615) MICROEARTHQUAKE/MICROEARTHQUAKE (525) NONOBJECTIVISMS/NONOBJECTIVISMS (465) PREFIGURATIVELY/PREFIGURATIVELY (405) DOWNREGULATIONS/DOWNREGULATIONS (300) FORGEAxILITIES/FORGEABILITIES (238) ADWAxDED/ADWARDED (104) EA/EA (4) left: L (-1) total: 2655 real 3m58.517s user 3m57.832s sys 0m0.512s