Wordle comparison: Difference between revisions
m
syntax highlighting fixup automation
(→{{header|Picat}}: Moving 2nd presentation to wordle predicate) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 20:
=={{header|C}}==
{{trans|Wren}}
<
#include <stdlib.h>
#include <string.h>
Line 74:
}
return 0;
}</
{{out}}
Line 86:
=={{header|FreeBASIC}}==
<
Dim As Integer n, i, k
Dim As String resultado
Line 142:
End If
Next i
Sleep</
{{out}}
<pre>ALLOW v LOLLY => [1, 1, 2, 0, 0] => yellow yellow green grey grey
Line 158:
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 206:
fmt.Printf("%s v %s => %v => %v\n", pair[0], pair[1], res, res2)
}
}</
{{out}}
Line 218:
=={{header|Haskell}}==
<
import Data.List (intercalate, mapAccumL)
import qualified Data.Map.Strict as M
Line 291:
color 2 = "green"
color 1 = "amber"
color _ = "gray"</
{{Out}}
<pre>Target -> Guess -> Scores
Line 310:
Implementation (brute force):
<
yw=.gr=. I.x=y
key=. '#' gr} x
Line 320:
end.
2 gr} 1 yw} (#y)#0
}}</
A bit more efficient (about 3 times faster on task example, which might matter if a few microseconds was important):
<
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'</
Explanation:
Line 347:
Task example:
<
yellow yellow green gray gray</
=={{header|JavaScript}}==
<
"use strict";
Line 542:
// MAIN ---
return main();
})();</
{{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'''
<
def wordle($answer; $guess):
Line 595:
| wordle(.[0]; .[1]) as $res
| ($res | map(colors[.])) as $res2
| "\(.[0]) v \(.[1]) => \($res) => \($res2)"</
{{out}}
As for [[#Wren]].
Line 601:
=={{header|Julia}}==
{{trans|Wren}}
<
function wordle(answer, guess)
Line 635:
res2 = [colors[i + 1] for i in res]
println("$pair0 v $pair1 => $res => $res2")
end</
<pre>
ALLOW v LOLLY => [1, 1, 2, 0, 0] => ["yellow", "yellow", "green", "grey", "grey"]
Line 645:
=={{header|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";
}</
{{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>
<!--<
<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 => %v => %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>
<!--</
{{out}}
<pre>
Line 723:
{{trans|Go}}
<
Pairs = [["ALLOW", "LOLLY"],
["BULLY", "LOLLY"],
Line 756:
Presentation[I] := [to_lowercase(Guess[I])] ++ "*"
end
end.</
{{out}}
Line 768:
=={{header|Python}}==
<
from functools import reduce
Line 941:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>Target -> Guess -> Scores
Line 958:
=={{header|Quackery}}==
<
[ over i^ peek = while
2 rot i^ poke
Line 975:
$ "ROBIN" $ "SONIC" wordle-compare echo cr
$ "ROBIN" $ "ROBIN" wordle-compare echo cr
</syntaxhighlight>
{{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"
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> );</
{{out}}
<pre>
Line 1,035:
=={{header|Swift}}==
<
case grey
case yellow
Line 1,080:
print("\(pair.0) v \(pair.1) => \(result)")
}
}</
{{out}}
Line 1,092:
=={{header|Tailspin}}==
<
templates wordle
sink removeFirst
Line 1,119:
['ALLOW', 'LOLLY'] -> wordle -> !OUT::write
</syntaxhighlight>
{{out}}
Line 1,128:
=={{header|Vlang}}==
{{trans|Go}}
<
n := guess.len
if n != answer.len {
Line 1,168:
println("${pair[0]} v ${pair[1]} => $res => $res2\n")
}
}</
{{out}}
Line 1,181:
=={{header|Wren}}==
<
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)")
}</
{{out}}
Line 1,227:
=={{header|XPL0}}==
<
proc ShowColors(Result);
Line 1,258:
ShowColors(Wordle("ROBIN", "SONIC"));
ShowColors(Wordle("ROBIN", "ROBIN"));
]</
{{out}}
Line 1,271:
=={{header|Yabasic}}==
{{trans|Phix}}
<
// by Galileo, 02/2022
Line 1,312:
print
next
</syntaxhighlight>
{{out}}
<pre>ALLOW v LOLLY => yellow yellow green grey grey
|