Bitcoin tanıtim pdf icerisinde bulunan c code ,formül kodları çalişması.
#include <stdio.h>
#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;
}
int main()
{
int num = 10;
int z;
double p;
double q = 0.1;
printf("q=%.1f\n", q);
for (z=0; z <= num; z++)
{
p = AttackerSuccessProbability(q, z);
printf("z=%i P=%f\n", z, p);
}
int zTimes5;
q = 0.3;
printf("\nq=%.1f\n", q);
for (z=0; z <= num; z++)
{
zTimes5=z*5;
p = AttackerSuccessProbability(q, zTimes5);
printf("z=%i P=%f\n", zTimes5, p);
}
puts("\nSolving for P less than 0.1%...\n");
q = 0.1;
puts("P < 0.001");
for (q=0.10; q <= 0.45; q+=0.05)
{
p = 1;
for (z=0; p >= 0.001; z++)
{
p = AttackerSuccessProbability(q, z);
}
printf("q=%.2f z=%i\n", q, z-1);
}
}
Hiç yorum yok:
Yorum Gönder
Her yorum bilgidir. Araştırmaya devam...