Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Entropy/Scala/entropy.scala
Normal file
12
Task/Entropy/Scala/entropy.scala
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import scala.math._
|
||||
|
||||
def entropy( v:String ) = { v
|
||||
.groupBy (a => a)
|
||||
.values
|
||||
.map( i => i.length.toDouble / v.length )
|
||||
.map( p => -p * log10(p) / log10(2))
|
||||
.sum
|
||||
}
|
||||
|
||||
// Confirm that "1223334444" has an entropy of about 1.84644
|
||||
assert( math.round( entropy("1223334444") * 100000 ) * 0.00001 == 1.84644 )
|
||||
Loading…
Add table
Add a link
Reference in a new issue