Skip to content

Instantly share code, notes, and snippets.

@urokuta
Last active October 18, 2024 04:03
Show Gist options
  • Save urokuta/7df03d8a692ff83941af to your computer and use it in GitHub Desktop.
Save urokuta/7df03d8a692ff83941af to your computer and use it in GitHub Desktop.
Bitcoin AttackerSuccessProbability
#include <math.h>
double AttackerSuccessProbability(double q, int z){
double p = 1.0 - q;
double lambda = z * (q / p);
double sum = 1.0;
int i, k;
for (k = 0; k <= z; k++){
double poisson = exp(-lambda);
for (i = 1; i <= k; i++)poisson *= lambda / i;
sum -= poisson * (1 - pow(q / p, z - k));
}
return sum;
}
@renra14
Copy link

renra14 commented Sep 25, 2021

cd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment