Entropy/Narcissist: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
(Added XPL0 example.) |
||
Line 1,056: | Line 1,056: | ||
4.6302314663 |
4.6302314663 |
||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
|||
To run: entropy < entropy.xpl |
|||
<syntaxhighlight lang "XPL0">int Count(128), I, Len, Ch; |
|||
real Sum, Prob; |
|||
[for I:= 0 to 127 do Count(I):= 0; |
|||
Len:= 0; |
|||
loop [Ch:= ChIn(1); |
|||
if Ch = $1A\EOF\ then quit; |
|||
Count(Ch):= Count(Ch)+1; |
|||
Len:= Len+1; |
|||
]; |
|||
Sum:= 0.; |
|||
for I:= 0 to 127 do |
|||
if Count(I) then |
|||
[Prob:= float(Count(I)) / float(Len); |
|||
Sum:= Sum + Prob*Ln(Prob); |
|||
]; |
|||
RlOut(0, -Sum/Ln(2.)); |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
4.63457</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |