
Task

Write a computer program that computes and shows its own   entropy.



Related Tasks

   Fibonacci_word
   Entropy


 
entropy(File) = E =>
    Bytes = read_file_bytes(File),
    F = [0: I in 1..256],
    foreach (B in Bytes)
        B1 := B + 1,
        F[B1] := F[B1] + 1
    end,
    HM = 0,
    foreach (C in F)
        if (C > 0) then
            HM := HM + C * log(2, C)
        end
    end,
    L = Bytes.length,
    E = log(2, L) - HM / L.
 
main(Args) =>
    printf("Entropy: %f\n", entropy(Args[1])).
 