Wordle comparison: Difference between revisions

m
syntax highlighting fixup automation
(→‎{{header|Picat}}: Moving 2nd presentation to wordle predicate)
m (syntax highlighting fixup automation)
Line 20:
=={{header|C}}==
{{trans|Wren}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 74:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 86:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">Function wordle(Byval respuesta As String, Byval supuesto As String) As String
Dim As Integer n, i, k
Dim As String resultado
Line 142:
End If
Next i
Sleep</langsyntaxhighlight>
{{out}}
<pre>ALLOW v LOLLY => [1, 1, 2, 0, 0] => yellow yellow green grey grey
Line 158:
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 206:
fmt.Printf("%s v %s => %v => %v\n", pair[0], pair[1], res, res2)
}
}</langsyntaxhighlight>
 
{{out}}
Line 218:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Bifunctor (first)
import Data.List (intercalate, mapAccumL)
import qualified Data.Map.Strict as M
Line 291:
color 2 = "green"
color 1 = "amber"
color _ = "gray"</langsyntaxhighlight>
{{Out}}
<pre>Target -> Guess -> Scores
Line 310:
Implementation (brute force):
 
<langsyntaxhighlight Jlang="j">wrdcmp=: {{
yw=.gr=. I.x=y
key=. '#' gr} x
Line 320:
end.
2 gr} 1 yw} (#y)#0
}}</langsyntaxhighlight>
 
A bit more efficient (about 3 times faster on task example, which might matter if a few microseconds was important):
 
<langsyntaxhighlight Jlang="j">wrdcmp=: {{
yw=. ;(] , ({.~1<.#)@-.)&.>/(<@I.y=/~x#~y~:x),<I.x=y
2 (I.x=y)} 1 yw} (#y)#0
Line 335:
assert 2 2 2 2 2-: 'robin' wrdcmp 'robin'
assert 0 0 2 1 0-: 'mamma' wrdcmp 'nomad'
assert 0 1 2 0 0-: 'nomad' wrdcmp 'mamma'</langsyntaxhighlight>
 
Explanation:
Line 347:
Task example:
 
<langsyntaxhighlight Jlang="j"> ('allow' wrdcmp 'lolly')&{&.;: 'gray yellow green'
yellow yellow green gray gray</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">(() => {
"use strict";
 
Line 542:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>ALLOW -> LOLLY -> [1,1,2,0,0] -> amber amber green gray gray
Line 559:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<langsyntaxhighlight lang="jq">def colors: ["grey", "yellow", "green"];
def wordle($answer; $guess):
Line 595:
| wordle(.[0]; .[1]) as $res
| ($res | map(colors[.])) as $res2
| "\(.[0]) v \(.[1]) => \($res) => \($res2)"</langsyntaxhighlight>
{{out}}
As for [[#Wren]].
Line 601:
=={{header|Julia}}==
{{trans|Wren}}
<langsyntaxhighlight lang="julia">const colors = ["grey", "yellow", "green"]
function wordle(answer, guess)
Line 635:
res2 = [colors[i + 1] for i in res]
println("$pair0 v $pair1 => $res => $res2")
end</langsyntaxhighlight>{{out}}
<pre>
ALLOW v LOLLY => [1, 1, 2, 0, 0] => ["yellow", "yellow", "green", "grey", "grey"]
Line 645:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Wordle_comparison
Line 658:
print "@$test => @{[ qw( green yellow grey )
[map ord, split //, s/.*\n//r =~ tr/\0\1/\2/cr] ]}\n";
}</langsyntaxhighlight>
{{out}}
<pre>
Line 671:
<small>Aside: You may be mildly surprised to see the 2nd for loop limit being clobbered like this, but you ''cannot'' change the limit mid-loop in Phix (an explicit exit would be far clearer) and hence you ''can'' do this.<br>
In practice the for loop takes a private copy of the value of the limit, be that n or more significantly say length(s), and ignores any changes you might subsequently make to it.</small>
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">wordle</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">answer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">guess</span><span style="color: #0000FF;">)</span>
Line 705:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s v %s =&gt; %v =&gt; %v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">answer</span><span style="color: #0000FF;">,</span><span style="color: #000000;">guess</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rac</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 723:
 
{{trans|Go}}
<langsyntaxhighlight Picatlang="picat">main =>
Pairs = [["ALLOW", "LOLLY"],
["BULLY", "LOLLY"],
Line 756:
Presentation[I] := [to_lowercase(Guess[I])] ++ "*"
end
end.</langsyntaxhighlight>
 
{{out}}
Line 768:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">'''Wordle comparison'''
 
from functools import reduce
Line 941:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>Target -> Guess -> Scores
Line 958:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ tuck witheach
[ over i^ peek = while
2 rot i^ poke
Line 975:
$ "ROBIN" $ "SONIC" wordle-compare echo cr
$ "ROBIN" $ "ROBIN" wordle-compare echo cr
</syntaxhighlight>
</lang>
 
{{out}}
Line 990:
=={{header|Raku}}==
Updated to add a proof of concept matching for similarity where commonly found on spoofing domain names. Of course this is just the tip of the iceberg (only comparing results after decomposition) and there are way too many [https://util.unicode.org/UnicodeJsps/confusables.jsp Unicode homoglyphs] that can only be matched using a [http://www.unicode.org/Public/security/8.0.0/confusables.txt lookup table/database].
<syntaxhighlight lang="raku" perl6line># 20220216 Raku programming solution
 
sub wordle (\answer,\guess where [==] (answer,guess)».chars ) {
Line 1,020:
say .[0]~' vs '~.[1]~"\t"~ wordle .[0],.[1] for (
<ALLOW LOLLY>, <ROBIN ALERT>, <ROBIN SONIC>, <ROBIN ROBIN>, <BULLY LOLLY>,
<ADAPT SÅLÅD>, <Ukraine Ukraíne>, <BBAABBB BBBBBAA>, <BBAABBB AABBBAA> );</langsyntaxhighlight>
{{out}}
<pre>
Line 1,035:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">enum Colour : CustomStringConvertible {
case grey
case yellow
Line 1,080:
print("\(pair.0) v \(pair.1) => \(result)")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,092:
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
templates wordle
sink removeFirst
Line 1,119:
 
['ALLOW', 'LOLLY'] -> wordle -> !OUT::write
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,128:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang="vlang">fn wordle(answer string, guess string) []int {
n := guess.len
if n != answer.len {
Line 1,168:
println("${pair[0]} v ${pair[1]} => $res => $res2\n")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,181:
 
=={{header|Wren}}==
<langsyntaxhighlight lang="ecmascript">var colors = ["grey", "yellow", "green"]
 
var wordle = Fn.new { |answer, guess|
Line 1,215:
var res2 = res.map { |i| colors[i] }.toList
System.print("%(pair[0]) v %(pair[1]) => %(res) => %(res2)")
}</langsyntaxhighlight>
 
{{out}}
Line 1,227:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0;
 
proc ShowColors(Result);
Line 1,258:
ShowColors(Wordle("ROBIN", "SONIC"));
ShowColors(Wordle("ROBIN", "ROBIN"));
]</langsyntaxhighlight>
 
{{out}}
Line 1,271:
=={{header|Yabasic}}==
{{trans|Phix}}
<langsyntaxhighlight Yabasiclang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Wordle_comparison
// by Galileo, 02/2022
 
Line 1,312:
print
next
</syntaxhighlight>
</lang>
{{out}}
<pre>ALLOW v LOLLY => yellow yellow green grey grey
10,333

edits