Wordle comparison: Difference between revisions

→‎{{header|Picat}}: Moving 2nd presentation to wordle predicate
(→‎{{header|Picat}}: Moving 2nd presentation to wordle predicate)
Line 732:
["ROSETTA", "OSSETAR"]],
foreach([Answer,Guess] in Pairs)
[Pres,Res] = wordle(Answer,Guess),
Len = Res.len,
printf("%w v %w => %w %w\n", Answer, Guess, ShowPres, Res)
Show = new_list(Len),
foreach(I in 1..Len)
if Res[I] == green then
Show[I] := [to_uppercase(Guess[I])] ++ " "
elseif Res[I] == yellow then
Show[I] := [to_lowercase(Guess[I])] ++ "*"
else
Show[I] := [to_lowercase(Guess[I])] ++ " "
end
end,
printf("%w v %w => %w %w\n", Answer, Guess, Show, Res)
end,
nl.
 
wordle(Answer,Guess) = [Presentation,Result =>
N = Guess.len,
Answer2 = copy_term(Answer), % don't touch Answer
if N != Answer.len then
print("The words must be of the same length.")
else
Answer2 = copy_term(Answer), % don't touch Answer
Result = new_list(N,grey), % grey by default
Presentation = copy_term(Guess).map(to_lowercase),
foreach(I in 1..N, Guess[I] == Answer2[I])
Answer2[I] := "",
Result[I] := green,
ShowPresentation[I] := [to_uppercase(Guess[I])] ++ " "
end,
foreach(I in 1..N, Ix = find_first_of(Answer2,Guess[I]), Ix > 0)
Answer2[Ix] := "",
Result[I] := yellow,
ShowPresentation[I] := [to_lowercase(Guess[I])] ++ "*"
end
end.</lang>
Line 773 ⟶ 766:
ROBBY v OBBYR => [o*,b*,B ,y*,r*] [yellow,yellow,green,yellow,yellow]
ROSETTA v OSSETAR => [o*,s ,S ,E ,t*,a*,r*] [yellow,grey,green,green,yellow,yellow,yellow]</pre>
 
 
=={{header|Python}}==
495

edits