Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
34
Task/Entropy/FreeBASIC/entropy.freebasic
Normal file
34
Task/Entropy/FreeBASIC/entropy.freebasic
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
' version 25-06-2015
|
||||
' compile with: fbc -s console
|
||||
|
||||
Sub calc_entropy(source As String, base_ As Integer)
|
||||
|
||||
Dim As Integer i, sourcelen = Len(source), totalchar(255)
|
||||
Dim As Double prop, entropy
|
||||
|
||||
For i = 0 To sourcelen -1
|
||||
totalchar(source[i]) += 1
|
||||
Next
|
||||
|
||||
Print "Char count"
|
||||
For i = 0 To 255
|
||||
If totalchar(i) = 0 Then Continue For
|
||||
Print " "; Chr(i); Using " ######"; totalchar(i)
|
||||
prop = totalchar(i) / sourcelen
|
||||
entropy = entropy - (prop * Log (prop) / Log(base_))
|
||||
Next
|
||||
|
||||
Print : Print "The Entropy of "; Chr(34); source; Chr(34); " is"; entropy
|
||||
|
||||
End Sub
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
calc_entropy("1223334444", 2)
|
||||
Print
|
||||
|
||||
' empty keyboard buffer
|
||||
While InKey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue