74 lines
1.4 KiB
Python
74 lines
1.4 KiB
Python
import os, math, matplotlib.pyplot as plt
|
|
|
|
path = '/home/benjamin/Desktop/bens_folder/school/m2/internship/work/romaric/me/'
|
|
|
|
os.chdir(path)
|
|
|
|
def getDifficultyOfHash(hexHash):
|
|
return int(hexHash, 16)
|
|
|
|
X, Y = [], []
|
|
|
|
difficultyRatios = []
|
|
|
|
with open('hashes.txt') as f:
|
|
lines = f.read().splitlines()
|
|
for line in lines:
|
|
lineParts = line.split()
|
|
hash = lineParts[0]
|
|
target = lineParts[1]
|
|
hashDifficulty = getDifficultyOfHash(hash)
|
|
targetDifficulty = getDifficultyOfHash(target)
|
|
difficultyRatio = math.log2(targetDifficulty / hashDifficulty)
|
|
difficultyRatios += [difficultyRatio]
|
|
|
|
i = 0
|
|
for difficultyRatio in difficultyRatios:
|
|
if 1 < difficultyRatio and difficultyRatio < 2:
|
|
i += 1
|
|
print(i)
|
|
|
|
N = 100
|
|
|
|
for i in range(N):
|
|
y = 0
|
|
for difficultyRatio in difficultyRatios:
|
|
|
|
if i in difficultyRatios:
|
|
X += [i]
|
|
Y += [difficultyRatios[i] / len(lines)]
|
|
|
|
## To improve the readability:
|
|
|
|
plt.scatter(X, Y)
|
|
|
|
plt.xticks(X, X)
|
|
|
|
YP = [2 ** -i for i in range(len(X))][:7]
|
|
|
|
plt.yticks(YP, YP)
|
|
|
|
for x, y in zip(X, Y):
|
|
if x <= 5:
|
|
plt.text(x, y, f'({x}, {round(y, 4)})', ha='center', va='top')
|
|
|
|
##
|
|
|
|
plt.plot(X, Y)
|
|
|
|
plt.show()
|
|
|
|
## To understand the difference between `int` and `round:`
|
|
|
|
import numpy as np
|
|
|
|
x = np.linspace(0, 10, 1000)
|
|
|
|
plt.plot(x, np.vectorize(int)(x), label = 'int')
|
|
plt.plot(x, np.vectorize(round)(x), label = 'round')
|
|
|
|
plt.legend(loc = 'upper left')
|
|
|
|
plt.show()
|
|
|