Benford's law: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 4,208:
9 0.045 0.046
</pre>
 
=={{header|XPL0}}==
The program is run like this: benford < fibdig.txt
 
Luckly, there's no need to show how the first digits of the Fibonacci sequence were obtained.
<syntaxhighlight lang "XPL0">int D, N, Counts(10);
real A, E;
[for D:= 0 to 9 do Counts(D):= 0;
for N:= 1 to 1000 do
[D:= ChIn(1) & $0F; \ASCII to binary
Counts(D):= Counts(D)+1;
];
Text(0, "Digit Actual Expected Difference^m^j");
for D:= 1 to 9 do
[IntOut(0, D); ChOut(0, ^ );
A:= float(Counts(D))/1000.;
RlOut(0, A);
E:= Log(1. + 1./float(D));
RlOut(0, E);
RlOut(0, E-A);
CrLf(0);
];
]</syntaxhighlight>
{{out}}
<pre>
Digit Actual Expected Difference
1 0.30100 0.30103 0.00003
2 0.17700 0.17609 -0.00091
3 0.12500 0.12494 -0.00006
4 0.09600 0.09691 0.00091
5 0.08000 0.07918 -0.00082
6 0.06700 0.06695 -0.00005
7 0.05600 0.05799 0.00199
8 0.05300 0.05115 -0.00185
9 0.04500 0.04576 0.00076
</pre>
 
=={{header|zkl}}==
{{trans|Go}}
291

edits