A few rounds of testing suggested that adding a “required” list of letters would be helpful. These are letters for which the position is unknown, but Wordle has identified as correct.
The usage pattern is:
wordle-solver.pl ...er wat ulc
Also, the world list gets additional prefiltering. No words with capitals or apostrophes are considered.
#!/usr/bin/env perl
use strict;
use warnings;
sub main {
my ($pattern, $exclude, $required) = @ARGV;
if (!$pattern) {
die("$0 [PATTERN] [EXCLUDE] [REQUIRED]");
}
if (length($pattern) != 5) {
die("Pattern must be 5 characters\n");
}
$exclude //= "";
$required //= "";
my @required;
if ($required) {
@required = split //, $required;
}
open my $wordsFH, "<", "/usr/share/dict/words" or die("words: $!");
NEXT_WORD:
while (my $word = readline($wordsFH)) {
chomp ($word);
next NEXT_WORD if length($word) != 5;
next NEXT_WORD if $word =~ /['A-Z]/;
if ($word =~ /^$pattern$/i) {
for my $r (@required) {
if ($word !~ /$r/) {
next NEXT_WORD;
}
}
if ($exclude) {
if ($word =~ /[$exclude]/) {
next NEXT_WORD;
}
}
print "$word\n";
}
}
close $wordsFH;
}
main();
I am thinking about making this functionality available through a web app. Drop me a note if you think this is a good idea.