Wordle comparison: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: exp[anded a bit on the limit clobbering |
added Raku programming solution |
||
Line 268:
[ 0 2 1 2 0 ]
[ 2 2 2 2 2 ]
</pre>
=={{header|Raku}}==
<lang perl6># 20220216 Raku programming solution
sub wordle ($answer,$guess where [==] ($answer,$guess)>>.chars ) {
my %answer = $answer.comb.pairs;
my %guess = $guess.comb.pairs;
my @return;
for %guess -> \trial { # pair
if %answer{trial.key} eqv trial.value {
@return[trial.key] = 'green';
given trial.key { %answer{$_}:delete and %guess{$_}:delete }
}
}
for %guess.keys.sort -> \trial { # numeric pos
@return[trial] = 'grey';
for %answer -> \actual { # pair
if %guess{trial} eqv actual.value {
@return[trial] = 'yellow' and %answer{actual.key}:delete;
last
}
}
}
@return
}
say .[0]~' vs '~.[1]~"\t"~ wordle .[0],.[1] for (<ALLOW LOLLY>,<ROBIN ALERT>,
<ROBIN SONIC>,<ROBIN ROBIN>,<BULLY LOLLY>,<BBAABBB BBBBBAA>,<BBAABBB AABBBAA>);</lang>
{{out}}
<pre>
ALLOW vs LOLLY yellow yellow green grey grey
ROBIN vs ALERT grey grey grey yellow grey
ROBIN vs SONIC grey green yellow green grey
ROBIN vs ROBIN green green green green green
BULLY vs LOLLY grey grey green green green
BBAABBB vs BBBBBAA green green yellow yellow green yellow yellow
BBAABBB vs AABBBAA yellow yellow yellow yellow green grey grey
</pre>
|