#!/usr/bin/perl # https://perlmonks.org/?node_id=1224403 use strict; use warnings; use Path::Tiny; use List::Util 'sum'; use Getopt::Long; GetOptions( 'dl=i' => \my @dl, 'tl=i' => \my @tl, 'dw' => \my $dw, 'tw' => \my $tw, ); my %worth = ( 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 => 2, w => 2, x => 8, y => 4, z => 10, ); my $input = shift // die "No Input!\n"; my $length = length $input; my $pattern = qr/@{[ join '', map "$_?", sort split '', $input ]}/; my @best; push @{ $best[score($_)] }, $_ for my @legalwords = grep { length() <= $length and join('', sort split //) =~ /^$pattern$/ } path( '/usr/share/dict/words' )->lines({chomp => 1}); print < $_ and $eachvalue[$_ - 1] *= 2 for @dl; @eachvalue > $_ and $eachvalue[$_ - 1] *= 3 for @tl; my $value = sum @eachvalue, @chars == 7 && 50; $value *= ($dw ? 2 : 1) * ($tw ? 3 : 1); }