Premium problem129. Shannon Entropy

Easy Locked

Return the Shannon entropy of a discrete distribution, in bits.

H=−∑ipilog⁡2piH = -\sum_i p_i \log_2 p_i

Treat pi=0p_i = 0 as contributing nothing, since 0log⁡00\log 0 is taken as 0 by the limit rather than being undefined. Entropy is maximal for a uniform distribution and zero when one outcome is certain.

Input

[0.5, 0.5]

Output

1.0

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)