RosettaCodeData/Task/Entropy/APL/entropy.apl

25 lines
418 B
APL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ENTROPY{-+/R×2R(+.=)÷}
⍝ How it works:
UNIQUEX'1223334444'
1234
TABLE_OF_OCCURENCESX.=UNIQUE
1 0 0 0
0 1 0 0
0 1 0 0
0 0 1 0
0 0 1 0
0 0 1 0
0 0 0 1
0 0 0 1
0 0 0 1
0 0 0 1
COUNT+TABLE_OF_OCCURENCES
1 2 3 4
NX
10
RATIOCOUNT÷N
0.1 0.2 0.3 0.4
-+/RATIO×2RATIO
1.846439345