Jaccard index: Difference between revisions

added Arturo
(added Arturo)
Line 38:
E 0 0.5 0.5 0.125 1 0
F 0 0 0 0.2 0 1 </pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">jaccard: function [a b][
if and? empty? a empty? b -> return to :rational 1
x: size intersection a b
y: size union a b
fdiv to :rational x to :rational y
]
 
sets: [
[]
[1 2 3 4 5]
[1 3 5 7 9]
[2 4 6 8 10]
[2 3 5 7]
[8]
]
 
loop combine.repeated.by: 2 sets 'p ->
print [pad ~"|p\0|" 12 pad ~"|p\1|" 12 "->" jaccard p\0 p\1]</syntaxhighlight>
 
{{out}}
 
<pre> [] [] -> 1/1
[] [1 2 3 4 5] -> 0/1
[] [1 3 5 7 9] -> 0/1
[] [2 4 6 8 10] -> 0/1
[] [2 3 5 7] -> 0/1
[] [8] -> 0/1
[1 2 3 4 5] [1 2 3 4 5] -> 1/1
[1 2 3 4 5] [1 3 5 7 9] -> 3/7
[1 2 3 4 5] [2 4 6 8 10] -> 1/4
[1 2 3 4 5] [2 3 5 7] -> 1/2
[1 2 3 4 5] [8] -> 0/1
[1 3 5 7 9] [1 3 5 7 9] -> 1/1
[1 3 5 7 9] [2 4 6 8 10] -> 0/1
[1 3 5 7 9] [2 3 5 7] -> 1/2
[1 3 5 7 9] [8] -> 0/1
[2 4 6 8 10] [2 4 6 8 10] -> 1/1
[2 4 6 8 10] [2 3 5 7] -> 1/8
[2 4 6 8 10] [8] -> 1/5
[2 3 5 7] [2 3 5 7] -> 1/1
[2 3 5 7] [8] -> 0/1
[8] [8] -> 1/1</pre>
 
=={{header|BQN}}==
1,532

edits