Python version of Satoshi Nakamoto's blockchain formula originally written in C. Original function: https://bitcoin.org/bitcoin.pdf.
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
import math | |
import ast | |
def attacker_success_probability(q, z): | |
p = (1 - q) | |
lamb = (z * (q / p)) | |
some = 1 | |
k = 0 | |
while (k <= z): | |
poisson = math.exp(-lamb) | |
i = 1 | |
while (i <= k): | |
poisson *= (lamb / i) | |
i += 1 | |
some -= (poisson * (1 - math.pow(q / p, z - k))) | |
k += 1 | |
attacker_success_probability.some = some | |
q = input("What is q? ") | |
q = ast.literal_eval(q) | |
z = input("What is z? ") | |
z = ast.literal_eval(z) | |
attacker_success_probability(q, z) | |
print('\nq={}\nz={}\tp={}'.format(q, z, attacker_success_probability.some)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment