Entropy/Narcissist: Difference between revisions
→{{header|jq}}: def sum():
(→{{header|jq}}: def sum():) |
|||
Line 613:
'''Works with jq, the C implementation of jq'''
'''Works with gojq, the Go implementation of jq'''
'''Works with jaq, the Rust implementation of jq'''
The program assumes it will be presented to itself using
Line 620 ⟶ 622:
jq -sR -f entropy-narcissist.jq < entropy-narcissist.jq
</pre>
If your jq supports `keys_unsorted`, feel free to use it instead of `keys`.
<syntaxhighlight lang="jq">
def chars: explode[] | [.] | implode;
def bow(stream):
reduce stream as $word ({}; .[($word|tostring)] += 1);
def sum(s): reduce s as $x (0; .+$x);
length as $l
| bow(chars)
|
| ($l|log2) - ./$l
</syntaxhighlight>
{{output}}
<pre>
{{output}}
<pre>
4.796499915496963
</pre>
|