Last active
July 11, 2024 16:37
-
-
Save WebDragon/fe7b6a4823191fb8f4080c0788a22dfb to your computer and use it in GitHub Desktop.
a stab at a commandline wordle helper in the absence of an actual list of wordle words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use v5.18; | |
use Getopt::Long; | |
my ($exact, $letterlist, $not, @letters, @miss); | |
GetOptions ( | |
"exact|e=s" => \$exact, | |
"letters|l=s{1,5}" => \@letters, | |
"miss|m=s{1,}" => \@miss, | |
"not|n=s" => \$not, | |
) or die ("Error in command line arguments\n"); | |
@letters = split(//, join(',', @letters)); | |
@miss = split(/,/, join(',', @miss)); | |
my $exactmatch = $exact ? qr/$exact/ : undef; | |
foreach my $letter (@letters) { | |
$letterlist .= "(?=.*$letter)"; | |
} | |
my $letters = $letterlist ? qr/\A$letterlist/s : undef; | |
my $misses = join('|', @miss) if @miss; | |
my $miss = $misses ? qr/$misses/ : undef; | |
my $nots = $not ? qr/[$not]/ : undef; | |
open (my $words, '<', '/usr/share/dict/words') or die "Cannot open words file: $!"; | |
my @wordlist; | |
while ( <$words> ) { | |
next unless m/^[a-z]{5}$/; | |
next unless ( $exactmatch ? $_ =~ $exactmatch : 1 ); | |
next unless ( $letters ? $_ =~ $letters : 1 ); | |
next unless ( $miss ? $_ !~ $miss : 1); | |
next unless ( $nots ? $_ !~ $nots : 1); | |
push @wordlist, $_; | |
} | |
use List::Util qw[sample shuffle]; | |
print for sample 20, shuffle @wordlist; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example usage