Created
March 1, 2018 10:40
-
-
Save beltiras/d23194c4c48880979ed0993bd3ec4b7c to your computer and use it in GitHub Desktop.
This file contains 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
from random import shuffle, choice, randint | |
key = {} | |
key['a'] = 11.68 | |
key['b'] = 4.43 | |
key['c'] = 5.24 | |
key['d'] = 3.17 | |
key['e'] = 2.80 | |
key['f'] = 4.03 | |
key['g'] = 1.64 | |
key['h'] = 4.20 | |
key['i'] = 7.29 | |
key['j'] = 0.51 | |
key['k'] = 0.46 | |
key['l'] = 2.42 | |
key['m'] = 3.83 | |
key['n'] = 2.28 | |
key['o'] = 7.63 | |
key['p'] = 4.32 | |
key['q'] = 0.22 | |
key['r'] = 2.83 | |
key['s'] = 6.69 | |
key['t'] = 15.98 | |
key['u'] = 1.18 | |
key['v'] = 0.82 | |
key['w'] = 5.50 | |
key['x'] = 0.05 | |
key['y'] = 0.76 | |
key['z'] = 0.05 | |
matrix = [[(key[x]/100)*(key[y]/100) for x in key.keys()] for y in key.keys()] | |
result = [[0 for x in key.keys()] for y in key.keys()] | |
all_combined = [x+y for x in key.keys() for y in key.keys()] | |
shuffle(all_combined) | |
odds_of_appearing = [0 for x in range(20)] | |
for place in all_combined: | |
x,y = ord(place[0]) - ord('a'), ord(place[1]) - ord('a') | |
max_iter = 0 | |
while place: | |
max_iter += 1 | |
suggestion = randint(1,20) | |
if odds_of_appearing[suggestion - 1] + matrix[x][y] < 0.050001: | |
odds_of_appearing[suggestion - 1] += matrix[x][y] | |
result[x][y] = suggestion | |
place = None | |
if place and max_iter == 100000: | |
print("defaulting") | |
odds_of_appearing[suggestion - 1] += matrix[x][y] | |
result[x][y] = suggestion | |
place = None | |
print(("{:>2} "*27).format(*([" "] + list(key.keys())))) | |
for letter, row in zip(key.keys(), result): | |
print(("{:>2} "*27).format(*[str(a) for a in [letter] + row])) | |
print("Difference between maximum and minimum odds: {:>10}".format(max(odds_of_appearing) - min(odds_of_appearing))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment