Jaccard index: Difference between revisions

Added Quackery.
m (syntax highlighting fixup automation)
(Added Quackery.)
Line 474:
A = [8], B = [8], J = 1
true.
</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ $ "bigrat.qky" loadfile ] now!
 
[ over size - space swap of
join echo$ ] is recho$ ( $ n --> $ )
 
[ dip unbuild recho$ ] is recho ( x n --> $ )
 
[ 0 swap witheach [ bit | ] ] is set ( [ --> n )
 
[ & ] is intersection ( n --> n )
 
[ | ] is union ( n --> n )
 
[ [] 0 rot
[ dup 0 > while
dup 1 & if
[ dip [ tuck join swap ] ]
dip 1+
1 >> again ]
2drop ] is items ( n --> [ )
 
[ 2dup = iff [ 2drop 1 1 ] done
2dup union items size
dip [ intersection items size ]
dup 0 = if [ 2drop 0 1 ]
] is jaccard ( n n --> n/d )
 
[ ' [ ] set ] constant is A ( --> n )
[ ' [ 1 2 3 4 5 ] set ] constant is B ( --> n )
[ ' [ 1 3 5 7 9 ] set ] constant is C ( --> n )
[ ' [ 2 4 6 8 10 ] set ] constant is D ( --> n )
[ ' [ 2 3 5 7 ] set ] constant is E ( --> n )
[ ' [ 8 ] set ] constant is F ( --> n )
 
' [ A B C D E F ]
dup witheach
[ over witheach
[ over items 15 recho
dup items 15 recho
say "--> "
2dup jaccard
proper$ echo$
cr drop ]
drop
behead drop ]
drop</syntaxhighlight>
 
{{out}}
 
<pre>[ ] [ ] --> 1
[ ] [ 1 2 3 4 5 ] --> 0
[ ] [ 1 3 5 7 9 ] --> 0
[ ] [ 2 4 6 8 10 ] --> 0
[ ] [ 2 3 5 7 ] --> 0
[ ] [ 8 ] --> 0
[ 1 2 3 4 5 ] [ 1 2 3 4 5 ] --> 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 3 5 7 9 ] [ 1 3 5 7 9 ] --> 1
[ 1 3 5 7 9 ] [ 2 4 6 8 10 ] --> 0
[ 1 3 5 7 9 ] [ 2 3 5 7 ] --> 1/2
[ 1 3 5 7 9 ] [ 8 ] --> 0
[ 2 4 6 8 10 ] [ 2 4 6 8 10 ] --> 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
[ 2 3 5 7 ] [ 8 ] --> 0
[ 8 ] [ 8 ] --> 1
</pre>
 
1,462

edits