Benford's law: Difference between revisions

GP
(GP)
Line 938:
9: 4.500000% 4.575749% 0.075749%
</pre>
 
=={{header|PARI/GP}}==
<lang parigp>distribution(v)={
my(t=vector(9,n,sum(i=1,#v,v[i]==n)));
print("Digit\tActual\tExpected");
for(i=1,9,print(i, "\t", t[i], "\t", round(#v*(log(i+1)-log(i))/log(10))))
};
dist(f)=distribution(vector(1000,n,digits(f(n))[1]));
lucas(n)=fibonacci(n-1)+fibonacci(n+1);
dist(fibonacci)
dist(lucas)</lang>
{{out}}
<pre>Digit Actual Expected
1 301 301
2 177 176
3 125 125
4 96 97
5 80 79
6 67 67
7 56 58
8 53 51
9 45 46
 
Digit Actual Expected
1 301 301
2 174 176
3 127 125
4 97 97
5 79 79
6 66 67
7 59 58
8 51 51
9 46 46</pre>
 
=={{header|Perl}}==