How to resolve the algorithm Entropy/Narcissist step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Entropy/Narcissist step by step in the zkl programming language

Table of Contents

Problem Statement

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

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Entropy/Narcissist step by step in the zkl programming language

Source code in the zkl programming language

fcn entropy(text){
   text.pump(Void,fcn(c,freq){ c=c.toAsc(); freq[c]=freq[c]+1; freq }
       .fp1((0).pump(256,List,(0.0).create.fp(0)).copy()))
   .filter()		      // remove all zero entries
   .apply('/(text.len()))     // (num of char)/len
   .apply(fcn(p){-p*p.log()}) // |p*ln(p)|
   .sum(0.0)/(2.0).log();     // sum * ln(e)/ln(2) to convert to log2
}

entropy(File("entropy.zkl").read().text).println();

  

You may also check:How to resolve the algorithm Show ASCII table step by step in the Clojure programming language
You may also check:How to resolve the algorithm Sokoban step by step in the Phix programming language
You may also check:How to resolve the algorithm Sierpinski carpet step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Stair-climbing puzzle step by step in the Oz programming language
You may also check:How to resolve the algorithm Sum to 100 step by step in the Tcl programming language