line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
use v5.14; |
2
|
1
|
|
|
1
|
|
13
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
4
|
|
|
|
|
|
|
use Data::Dumper; |
5
|
1
|
|
|
1
|
|
5
|
use List::Util qw(any uniq); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
6
|
1
|
|
|
1
|
|
6
|
use List::MoreUtils qw(pairwise); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
7
|
1
|
|
|
1
|
|
511
|
use Getopt::EX::Colormap qw(colorize); |
|
1
|
|
|
|
|
12393
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
1107
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
70
|
|
9
|
|
|
|
|
|
|
use Mo qw(is required default); { |
10
|
1
|
|
|
1
|
|
686
|
has answer => is => 'ro', required => 1 ; |
|
1
|
|
|
|
|
494
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
has attempts => [], lazy => 0 ; |
12
|
|
|
|
|
|
|
has map => {} ; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
no Mo; |
15
|
1
|
|
|
1
|
|
2212
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1317
|
|
16
|
|
|
|
|
|
|
my $obj = shift; |
17
|
|
|
|
|
|
|
push @{$obj->{attempts}}, @_; |
18
|
0
|
|
|
0
|
0
|
|
$obj->update(@_); |
19
|
0
|
|
|
|
|
|
$obj->solved; |
|
0
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $obj = shift; |
23
|
|
|
|
|
|
|
int @{$obj->{attempts}}; |
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
0
|
0
|
|
|
26
|
0
|
|
|
|
|
|
my $obj = shift; |
|
0
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
any { lc eq lc $obj->{answer} } @{$obj->{attempts}}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
31
|
0
|
|
|
0
|
|
|
my $answer = $obj->answer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %a = map { $_ => 1 } my @a = $answer =~ /./g; |
33
|
|
|
|
|
|
|
my $keys = $obj->map; |
34
|
|
|
|
|
|
|
for my $try (@_) { |
35
|
0
|
|
|
0
|
0
|
|
my @b = $try =~ /./g; |
36
|
0
|
|
|
|
|
|
pairwise { $keys->{$a} = 'G' if $a eq $b } @a, @b; |
37
|
0
|
|
|
|
|
|
$keys->{$_} ||= $a{$_} ? 'Y' : 'K' for @b; |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
$obj; |
40
|
0
|
|
|
|
|
|
} |
41
|
0
|
0
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
42
|
0
|
0
|
0
|
|
|
|
###################################################################### |
43
|
|
|
|
|
|
|
# keymap |
44
|
0
|
|
|
|
|
|
###################################################################### |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my %map_color = ( |
47
|
|
|
|
|
|
|
G => '555/#6aaa64', |
48
|
|
|
|
|
|
|
Y => '555/#c9b458', |
49
|
|
|
|
|
|
|
K => '#787c7e/#787c7e', |
50
|
|
|
|
|
|
|
K => 'L17/#787c7e', |
51
|
|
|
|
|
|
|
_ => '555/#787c7e', |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my($kmap, $cmap, $s) = @_; |
55
|
|
|
|
|
|
|
join '', map colorize($cmap->{$kmap->{$_}//'_'}, $_), $s =~ /./g; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $obj = shift; |
59
|
|
|
|
|
|
|
my $keys = keycolor $obj->map, \%map_color, join('', 'a'..'z'); |
60
|
0
|
|
|
0
|
0
|
|
$keys; |
61
|
0
|
|
0
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
###################################################################### |
64
|
|
|
|
|
|
|
# result |
65
|
0
|
|
|
0
|
0
|
|
###################################################################### |
66
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my %square = ( |
68
|
|
|
|
|
|
|
G => "\N{U+1F7E9}", # LARGE GREEN SQUARE |
69
|
|
|
|
|
|
|
Y => "\N{U+1F7E8}", # LARGE YELLOW SQUARE |
70
|
|
|
|
|
|
|
K => "\N{U+2B1C}", # WHITE LARGE SQUARE |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $obj = shift; |
74
|
|
|
|
|
|
|
my @result = _result(map lc, $obj->{answer}, @{$obj->{attempts}}); |
75
|
|
|
|
|
|
|
my $result = join "\n", map s/([GYK])/$square{$1}/ger, @result; |
76
|
|
|
|
|
|
|
$result; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $answer = shift; |
80
|
|
|
|
|
|
|
my %a = map { $_ => 1 } my @a = $answer =~ /./g; |
81
|
0
|
|
|
0
|
0
|
|
map { |
82
|
0
|
|
|
|
|
|
my @b = /./g; |
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
join '', pairwise { |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$a eq $b ? 'G' : $a{$b} ? 'Y' : 'K' |
85
|
|
|
|
|
|
|
} @a, @b; |
86
|
|
|
|
|
|
|
} @_; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
0
|
|
|
|
89
|
0
|
|
|
|
|
|
###################################################################### |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# hint |
91
|
0
|
|
|
|
|
|
###################################################################### |
|
0
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
0
|
|
|
my %hint_color = ( |
|
|
0
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
G => 'G', |
95
|
|
|
|
|
|
|
Y => 'Y', |
96
|
|
|
|
|
|
|
K => 'KU', |
97
|
|
|
|
|
|
|
_ => 'K', |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $obj = shift; |
101
|
|
|
|
|
|
|
map keycolor($obj->map, \%hint_color, $_), @_; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $obj = shift; |
105
|
|
|
|
|
|
|
my $pattern = _hint(map lc, $obj->{answer}, @{$obj->{attempts}}); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $answer = shift; |
109
|
|
|
|
|
|
|
my %a = map { $_ => 1 } my @a = $answer =~ /./g; |
110
|
0
|
|
|
0
|
0
|
|
my(@yes, @no); |
111
|
0
|
|
|
|
|
|
my $seen = ''; |
112
|
|
|
|
|
|
|
map { |
113
|
|
|
|
|
|
|
my @b = /./g; |
114
|
|
|
|
|
|
|
for my $i (0 .. $#b) { |
115
|
0
|
|
|
0
|
0
|
|
if ($a{$b[$i]}) { |
116
|
0
|
|
|
|
|
|
$seen .= $b[$i]; |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} else { |
118
|
|
|
|
|
|
|
$seen .= "-$b[$i]"; |
119
|
|
|
|
|
|
|
} |
120
|
0
|
|
|
0
|
|
|
if ($a[$i] eq $b[$i]) { |
121
|
0
|
|
|
|
|
|
$yes[$i] = $a[$i]; |
|
0
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
} else { |
123
|
0
|
|
|
|
|
|
$no[$i] .= $b[$i]; |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
|
} |
|
0
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
} @_; |
127
|
0
|
0
|
|
|
|
|
my $match = join '', pairwise { |
128
|
0
|
|
|
|
|
|
$b = join '', uniq $b =~ /./g if $b; |
129
|
|
|
|
|
|
|
$a ? $a : "[^$b]"; |
130
|
0
|
|
|
|
|
|
} @yes, @no; |
131
|
|
|
|
|
|
|
my $in = join '', map { "(?=.*$_)" } uniq $seen =~ /(?<!-)\w/g; |
132
|
0
|
0
|
|
|
|
|
my $ex = sprintf '(?!.*[%s])', join('', uniq $seen =~ /(?<=-)\w/g); |
133
|
0
|
|
|
|
|
|
$in . $ex . $match; |
134
|
|
|
|
|
|
|
} |
135
|
0
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |