Jump to content

Wordle comparison: Difference between revisions

m (→‎{{header|Raku}}: insignificant changes)
Line 189:
<lang J> ('allow' wrdcmp 'lolly')&{&.;: 'gray yellow green'
yellow yellow green gray gray</lang>
 
=={{header|jq}}==
{{trans|Wren}}
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>def colors: ["grey", "yellow", "green"];
def wordle($answer; $guess):
($guess|length) as $n
| if ($answer|length) != $n then "The words must be of the same length." | error
else { answer: (answer | explode),
guess: (guess | explode),
result: [range(0;$n)|0] }
| reduce range(0; $n) as $i (.;
if .guess[$i] == .answer[$i]
then .answer[$i] = 0
| .result[$i] = 2
else .
end )
| reduce range(0; $n) as $i (.;
.guess[$i] as $g
| (.answer | index($g) ) as $ix
| if $ix
then .answer[$ix] = 0
| .result[$i] = 1
else .
end )
| .result
end ;
def pairs:
["ALLOW", "LOLLY"],
["BULLY", "LOLLY"],
["ROBIN", "ALERT"],
["ROBIN", "SONIC"],
["ROBIN", "ROBIN"]
;
 
pairs
| wordle(.[0]; .[1]) as $res
| ($res | map(colors[.])) as $res2
| "\(.[0]) v \(.[1]) => \($res) => \($res2)"</lang>
{{out}}
As for [[#Wren]].
 
=={{header|Julia}}==
2,484

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.