Create a gist now

Instantly share code, notes, and snippets.

@snitzr /bitcoin.py
Last active May 22, 2016

What would you like to do?
Python version of Satoshi Nakamoto's blockchain formula originally written in C. Original function: https://bitcoin.org/bitcoin.pdf.
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