Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Entropy/Tcl/entropy-1.tcl
Normal file
10
Task/Entropy/Tcl/entropy-1.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
|
||||
}
|
||||
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"]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue