Jaccard index: Difference between revisions
m
syntax highlighting fixup automation
(Initial Haskell version.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 18:
=={{header|APL}}==
<
jaccard ← (≢∩)÷(≢∪)
Line 29:
'.ABCDEF' ⍪ 'ABCDEF' , ∘.jaccard⍨ A B C D E F
}</
{{out}}
<pre>. A B C D E F
Line 40:
=={{header|BQN}}==
<
a ← ⟨⟩
Line 49:
f ← ⟨8⟩
Jaccard⌜˜ ⟨a,b,c,d,e,f⟩</
{{out}}
<pre>┌─
Line 62:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
prettyprint sequences sequences.repeating sets ;
Line 71:
{ { } { 1 2 3 4 5 } { 1 3 5 7 9 } { 2 4 6 8 10 } { 2 3 5 7 } { 8 } }
[ 2 <combinations> ] [ 2 repeat 2 group append ] bi
[ 2dup jaccard "%u %u -> %u\n" printf ] assoc-each</
{{out}}
<pre>
Line 98:
=={{header|Haskell}}==
<
import Data.List (genericLength, intersect, nub, union)
import Data.List.Split (chunksOf)
Line 146:
, ("D", [2, 4, 6, 8, 10])
, ("E", [2, 3, 5, 7])
, ("F", [8])]</
{{out}}
<pre>
Line 175:
<br>
'''Preliminaries'''
<
def gcd(a; b):
Line 183:
else [.[1], .[0] % .[1]] | rgcd
end;
[a,b] | rgcd;</
<br>
'''The Task'''
<
def i(a;b): a - (a-b);
def u(a;b): a + (b - i(a;b)) | unique;
Line 221:
| " \($name): \(.)" ) ;
task</
{{out}}
<pre>
Line 234:
=={{header|Julia}}==
<
A = Int[]
Line 249:
replace(string(J(a, b)), "//" => "/"))
end
</
<pre>
Set A Set B J(A, B)
Line 292:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">sets</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 321:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 348:
=={{header|Perl}}==
<
use strict;
Line 372:
%union ? (grep $_ == 2, values %union) / (keys %union) : 1, "\n";
}
}</
{{out}}
<pre>
Line 422:
=={{header|Prolog}}==
<
show([]).
show([X|Xs]):- write(X), show(Xs).
Line 433:
findall(X, (member(X,B), not(member(X,A))), T), append(A,T,U), length(U,M),
j(N,M,J), show(["A = ",A,", B = ",B,", J = ",J]), nl)).
</syntaxhighlight>
{{out}}
<pre>
Line 477:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
my %p =
Line 490:
.say for %p.sort;
say '';
say "J({.join: ','}) = ", J |%p{$_} for [X] <A B C D E F> xx 2;</
{{out}}
<pre>A => ()
Line 541:
{{libheader|Wren-fmt}}
Note that the Set object in the above module is implemented as a Map and consequently the iteration order (and the order in which elements are printed) is undefined.
<
import "./trait" for Indexed
import "./fmt" for Fmt
Line 572:
Fmt.print("J($s, $s) = $h", i1, i2, jaccardIndex.call(v1, v2))
}
}</
{{out}}
|