App-Greple-wordle

 view release on metacpan or  search on metacpan

lib/App/Greple/wordle/game.pm  view on Meta::CPAN

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
sub attempt {
    my $obj = shift;
    int @{$obj->{attempts}};
}
 
sub solved {
    my $obj = shift;
    any { lc eq lc $obj->{answer} } @{$obj->{attempts}};
}
 
sub update {
    my $obj = shift;
    my $answer = $obj->answer;
    my %a = map { $_ => 1 } my @a = $answer =~ /./g;
    my $keys = $obj->map;
    for my $try (@_) {
        my @b = $try =~ /./g;
        pairwise { $keys->{$a} = 'G' if $a eq $b } @a, @b;
        $keys->{$_} ||= $a{$_} ? 'Y' : 'K' for @b;
    }
    $obj;



( run in 0.672 second using v1.01-cache-2.11-cpan-5f2e87ce722 )