Jaccard index: Difference between revisions
→{{header|Factor}}: whoops, remove redundant pairings
(→{{header|Wren}}: Added self pairings - every time I look at this the task description has changed!) |
(→{{header|Factor}}: whoops, remove redundant pairings) |
||
Line 19:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: assocs formatting grouping kernel math
prettyprint sequences sequences.repeating sets ;
: jaccard ( seq1 seq2 -- x )
Line 26 ⟶ 27:
{ { } { 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
{{out}}
<pre>
{ } { 1, 2, 3, 4, 5 } -> 0
{ } { 1, 3, 5, 7, 9 } -> 0
Line 35 ⟶ 36:
{ } { 2, 3, 5, 7 } -> 0
{ } { 8 } -> 0
{ 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 } { 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, 3, 5, 7 } -> 1/8
{ 2, 4, 6, 8, 10 } { 8 } -> 1/5
{ 2, 3, 5, 7 } { 8 } -> 0
{
{
{
{ 2, 4, 6, 8, 10 } { 2, 4, 6, 8, 10 } -> 1
{
{ 8 } { 8 } -> 1
</pre>
|