Entropy/Narcissist: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Changed to Wren S/H)
Line 609: Line 609:
{{out}}
{{out}}
<pre>Entropy of file "src/EntropyNarcissist.java" = 4.691381977073.</pre>
<pre>Entropy of file "src/EntropyNarcissist.java" = 4.691381977073.</pre>

=={{header|jq}}==
'''Works with jq, the C implementation of jq'''

'''Works with gojq, the Go implementation of jq''' provided keys_unsorted is replaced by keys

The program assumes it will be presented to itself using
an invocation of jq with the -sR options, along the lines of:
<pre>
jq -sR -f entropy-narcissist.jq < entropy-narcissist.jq
</pre>
<syntaxhighlight lang="jq">
def chars: explode[] | [.] | implode;

# bag of words
def bow(stream):
reduce stream as $word ({}; .[($word|tostring)] += 1);

length as $l
| bow(chars) as $m
| reduce ($m|keys_unsorted[]) as $k (0;
$m[$k] as $c
| . + $c * ($c|log2) )
| ($l|log2) - ./$l
</syntaxhighlight>
{{output}}
<pre>
4.759188941960586
</pre>


=={{header|Julia}}==
=={{header|Julia}}==