First commit of partial RosettaCode contents.
Pushing this for testing purposes. Lots of work still needed.
This commit is contained in:
commit
1e05ecd7ee
781 changed files with 9080 additions and 0 deletions
2
Task/Entropy/Tcl/entropy-2.tcl
Normal file
2
Task/Entropy/Tcl/entropy-2.tcl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
puts [format "entropy = %.5f" [entropy "1223334444"]]
|
||||
puts [format "entropy = %.5f" [entropy "Rosetta Code"]]
|
||||
10
Task/Entropy/Tcl/entropy.tcl
Normal file
10
Task/Entropy/Tcl/entropy.tcl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
proc entropy {str} {
|
||||
set log2 [expr log(2)]
|
||||
foreach char [split $str ""] {dict incr counts $char}
|
||||
set entropy 0.0
|
||||
foreach count [dict values $counts] {
|
||||
set freq [expr {$count / double([string length $str])}]
|
||||
set entropy [expr {$entropy - $freq * log($freq)/$log2}]
|
||||
}
|
||||
return $entropy
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue