App-wordlist-wordle

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

FUNCTIONS
  wordlist_wordle
    Usage:

     wordlist_wordle(%args) -> [$status_code, $reason, $payload, \%result_meta]

    Help solve Wordle.

    Examples:

    *   One guess:

         wordlist_wordle(arg => ["cR^eEk"]);

    *   Five guesses:

         wordlist_wordle(arg => ["A^R^isE^", "Pound", "might", "blA^ck", "PR^ivY^"]);

    This is a wrapper to wordlist designed to be a convenient helper to
    solve Wordle puzzle. By default it greps from the "EN::Wordle" wordlist.
    It accepts a series of guesses in a format like the following:

     A^R^isE^
     Pound
     might
     blA^ck
     PR^ivY^

    where lowercase means wrong guess, uppercase means correct letter and
    position, while (uppercase) letter followed by a caret ("^") means the
    letter exists in another position. It will convert these guesses to
    regex patterns and the "--chars-unordered" option and pass it to
    "wordlist".

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   arg => *array[str]*

        (No description)

lib/App/wordlist/wordle.pm  view on Meta::CPAN

        'chars_unordered',
        'chars_ordered',
    ],
    modify_meta => sub {
        $_[0]{summary} = 'Help solve Wordle';
        delete $_[0]{'x.doc.faq'};
        $_[0]{description} = <<'MARKDOWN';

This is a wrapper to <prog:wordlist> designed to be a convenient helper to solve
Wordle puzzle. By default it greps from the `EN::Wordle` wordlist. It accepts
a series of guesses in a format like the following:

    A^R^isE^
    Pound
    might
    blA^ck
    PR^ivY^

where lowercase means wrong guess, uppercase means correct letter and position,
while (uppercase) letter followed by a caret (`^`) means the letter exists in
another position. It will convert these guesses to regex patterns and the
`--chars-unordered` option and pass it to `wordlist`.

MARKDOWN
        $_[0]{examples} = [
            {
                argv => ['cR^eEk'],
                summary => 'One guess',
                test => 0,
                'x.doc.show_result' => 0,
            },
            {
                argv => ['A^R^isE^', 'Pound', 'might', 'blA^ck', 'PR^ivY^'],
                summary => 'Five guesses',
                test => 0,
                'x.doc.show_result' => 0,
            },
        ];
    },
    output_code => sub {
        my %args = @_;

        $args{arg} //= [];

        my $chars_unordered = '';
        my $possible_letters = join '', "a".."z";
        my @new_arg;
        for my $arg (@{ $args{arg} }) {
            my @chars = split //, $arg;
            my $re = '';
            my %letter_exists;
            while (@chars) {
                my $char = shift @chars;
                return [400, "Invalid letter '$char' in guess '$arg'"] unless $char =~ /[A-Za-z]/;
                my $caret = @chars && $chars[0] eq '^' ? shift(@chars) : '';
                my $uc = $char eq uc $char;
                $char = lc $char;

                if ($caret) { # letter is in another position
                    my $letters = $possible_letters;
                    $letters =~ s/$char//;
                    $re .= "[$letters]";
                    $letter_exists{$char}++;
                    $chars_unordered .= $char unless index($chars_unordered, $char) >= 0;
                } elsif ($uc) { # correct guess
                    $re .= $char;
                    $letter_exists{$char}++;
                    $chars_unordered .= $char unless index($chars_unordered, $char) >= 0;
                } else { # wrong guess
                    my $letters = $possible_letters;
                    $letters =~ s/$char//;
                    $possible_letters =~ s/$char// unless $letter_exists{$char};
                    $re .= "[$letters]";
                }
            }
            $re = "/\\A$re\\z/";
            push @new_arg, $re;
        }

lib/App/wordlist/wordle.pm  view on Meta::CPAN

Usage:

 wordlist_wordle(%args) -> [$status_code, $reason, $payload, \%result_meta]

Help solve Wordle.

Examples:

=over

=item * One guess:

 wordlist_wordle(arg => ["cR^eEk"]);

=item * Five guesses:

 wordlist_wordle(arg => ["A^R^isE^", "Pound", "might", "blA^ck", "PR^ivY^"]);

=back

This is a wrapper to L<wordlist> designed to be a convenient helper to solve
Wordle puzzle. By default it greps from the C<EN::Wordle> wordlist. It accepts
a series of guesses in a format like the following:

 A^R^isE^
 Pound
 might
 blA^ck
 PR^ivY^

where lowercase means wrong guess, uppercase means correct letter and position,
while (uppercase) letter followed by a caret (C<^>) means the letter exists in
another position. It will convert these guesses to regex patterns and the
C<--chars-unordered> option and pass it to C<wordlist>.

This function is not exported.

Arguments ('*' denotes required arguments):

=over 4

=item * B<arg> => I<array[str]>

script/_wordlist-wordle  view on Meta::CPAN

use warnings;

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2025-03-07'; # DATE
our $DIST = 'App-wordlist-wordle'; # DIST
our $VERSION = '0.295'; # VERSION
die "Please run this script under shell completion\n" unless $ENV{COMP_LINE} || $ENV{COMMAND_LINE};

my $args = {program_name=>"wordlist-wordle",read_config=>0,read_env=>0,skip_format=>undef,subcommands=>undef,url=>"/App/wordlist/wordle/wordlist_wordle"};

my $meta = {_orig_args_as=>undef,_orig_result_naked=>undef,args=>{arg=>{greedy=>1,pos=>0,schema=>["array",{of=>"str*",req=>1}],tags=>["category:word-filtering"]},color=>{default=>"auto",schema=>["str",{in=>["never","always","auto"],req=>1,"x.in.summa...

my $sc_metas = {};

my $copts = {format=>{default=>undef,description=>"\nOutput can be displayed in multiple formats, and a suitable default format is\nchosen depending on the application and/or whether output destination is\ninteractive terminal (i.e. whether output is...

my $r = {common_opts=>$copts};

# get words
my $shell;
my ($words, $cword);

script/wordlist-wordle  view on Meta::CPAN

# load modules


### declare global variables

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2025-03-07'; # DATE
our $DIST = 'App-wordlist-wordle'; # DIST
our $VERSION = '0.295'; # VERSION

my $_pci_metas = {""=>{args=>{arg=>{greedy=>1,pos=>0,schema=>["array",{of=>["str",{req=>1}],req=>1}],tags=>["category:word-filtering"]},color=>{default=>"auto",schema=>["str",{in=>["never","always","auto"],req=>1,"x.in.summaries"=>["Never show color"...

our $_pci_log_outputs = {};
our $_pci_meta_result_stream = 0;
our $_pci_meta_result_type;
our $_pci_meta_result_type_is_simple;
our $_pci_meta_skip_format = 0;
our $_pci_r = {naked_res=>0,read_config=>1,read_env=>1,subcommand_name=>""};
our %_pci_args;

### begin code_before_enable_logging

script/wordlist-wordle  view on Meta::CPAN


{
my %mentioned_args;
require Getopt::Long::EvenLess;
log_trace("Parsing command-line arguments ...");
my $go_spec1 = {
    'config-path=s@' => sub { $_pci_r->{config_paths} //= []; push @{ $_pci_r->{config_paths} }, $_[1]; },
    'config-profile=s' => sub { $_pci_r->{config_profile} = $_[1]; },
    'debug' => sub { require Log::ger::Util; Log::ger::Util::set_level("debug"); $_pci_r->{log_level} = "debug"; },
    'format=s' => sub { $_pci_r->{format} = $_[1]; },
    'help|h|?' => sub { print "wordlist-wordle - Help solve Wordle\n\nUsage:\n  wordlist-wordle --help (or -h, -?)\n  wordlist-wordle --version (or -v)\n  wordlist-wordle [--color=str] [(--config-path=path)+|--no-config]\n    [--config-profile=profil...
    'json' => sub { $_pci_r->{format} = (-t STDOUT) ? "json-pretty" : "json"; ## no critic InputOutput::ProhibitInteractiveTest
 },
    'log-level=s' => sub { if ($_[1] eq "trace") { require Log::ger::Util; Log::ger::Util::set_level("trace"); Log::ger::Output::Composite::set_level("trace") } if ($_[1] eq "debug") { require Log::ger::Util; Log::ger::Util::set_level("debug"); Log::...
    'naked-res' => sub { $_pci_r->{naked_res} = 1; },
    'no-config' => sub { $_pci_r->{read_config} = 0; },
    'no-env' => sub { $_pci_r->{read_env} = 0; },
    'no-naked-res|nonaked-res' => sub { $_pci_r->{naked_res} = 0; },
    'page-result:s' => sub { $_pci_r->{page_result} = 1; },
    'quiet' => sub { require Log::ger::Util; Log::ger::Util::set_level("error"); $_pci_r->{log_level} = "error"; },
    'trace' => sub { require Log::ger::Util; Log::ger::Util::set_level("trace"); $_pci_r->{log_level} = "trace"; },

script/wordlist-wordle  view on Meta::CPAN

B<wordlist-wordle> [B<L<--color|/"--color=s">>=I<str>] [(B<L<--config-path|/"--config-path=s">>=I<path>)+|B<L<--no-config|/"--no-config">>] [B<L<--config-profile|/"--config-profile=s">>=I<profile>] [B<L<--debug|/"--debug">>|B<L<--log-level|/"--log-le...



See examples in the L</EXAMPLES> section.

=head1 DESCRIPTION

This is a wrapper to L<wordlist> designed to be a convenient helper to solve
Wordle puzzle. By default it greps from the C<EN::Wordle> wordlist. It accepts
a series of guesses in a format like the following:

 A^R^isE^
 Pound
 might
 blA^ck
 PR^ivY^

where lowercase means wrong guess, uppercase means correct letter and position,
while (uppercase) letter followed by a caret (C<^>) means the letter exists in
another position. It will convert these guesses to regex patterns and the
C<--chars-unordered> option and pass it to C<wordlist>.

=head1 OPTIONS

C<*> marks required options.

=head2 Main options

=over

script/wordlist-wordle  view on Meta::CPAN

=head1 FILES

=head2 ~/.config/wordlist-wordle.conf

=head2 ~/wordlist-wordle.conf

=head2 /etc/wordlist-wordle.conf

=head1 EXAMPLES

=head2 One guess

 % wordlist-wordle cR^eEk

=head2 Five guesses

 % wordlist-wordle A^R^isE^ Pound might blA^ck PR^ivY^

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-wordlist-wordle>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-wordlist-wordle>.



( run in 1.264 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )