-
-
Save kirilltobola/49c6b40583e734321600881703a324fb to your computer and use it in GitHub Desktop.
hw_bernulli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
ru_alphabet = { | |
'а': 8.01, | |
'б': 1.59, | |
'в': 4.54, | |
'г': 1.70, | |
'д': 2.98, | |
'е': 8.45, | |
'ё': 0.04, | |
'ж': 0.94, | |
'з': 1.65, | |
'и': 7.35, | |
'й': 1.21, | |
'к': 3.49, | |
'л': 4.40, | |
'м': 3.21, | |
'н': 6.70, | |
'о': 10.97, | |
'п': 2.81, | |
'р': 4.73, | |
'с': 5.47, | |
'т': 6.26, | |
'у': 2.62, | |
'ф': 0.26, | |
'х': 0.97, | |
'ц': 0.48, | |
'ч': 1.44, | |
'ш': 0.73, | |
'щ': 0.36, | |
'ъ': 0.04, | |
'ы': 1.90, | |
'ь': 1.74, | |
'э': 0.32, | |
'ю': 0.64, | |
'я': 2.01, | |
} | |
sum = 0 | |
for char in ru_alphabet.values(): | |
p = char/100 | |
sum += p * math.log2(p) | |
print('res =', sum * -1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
ru_alphabet = { | |
2: 1/36, | |
3: 2/36, | |
4: 3/36, | |
5: 4/36, | |
6: 5/36, | |
7: 6/36, | |
8: 5/36, | |
9: 4/36, | |
10: 3/36, | |
11: 2/36, | |
12: 1/36, | |
} | |
sum = 0 | |
for p in ru_alphabet.values(): | |
sum += p * math.log2(p) | |
print('res =', sum * -1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment