Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,49 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Numerics.Generic_Elementary_Functions;
|
||||
|
||||
procedure Benford is
|
||||
|
||||
subtype Nonzero_Digit is Natural range 1 .. 9;
|
||||
function First_Digit(S: String) return Nonzero_Digit is
|
||||
(if S(S'First) in '1' .. '9'
|
||||
then Nonzero_Digit'Value(S(S'First .. S'First))
|
||||
else First_Digit(S(S'First+1 .. S'Last)));
|
||||
|
||||
package N_IO is new Ada.Text_IO.Integer_IO(Natural);
|
||||
|
||||
procedure Print(D: Nonzero_Digit; Counted, Sum: Natural) is
|
||||
package Math is new Ada.Numerics.Generic_Elementary_Functions(Float);
|
||||
package F_IO is new Ada.Text_IO.Float_IO(Float);
|
||||
Actual: constant Float := Float(Counted) / Float(Sum);
|
||||
Expected: constant Float := Math.Log(1.0 + 1.0 / Float(D), Base => 10.0);
|
||||
Deviation: constant Float := abs(Expected-Actual);
|
||||
begin
|
||||
N_IO.Put(D, 5);
|
||||
N_IO.Put(Counted, 14);
|
||||
F_IO.Put(Float(Sum)*Expected, Fore => 16, Aft => 1, Exp => 0);
|
||||
F_IO.Put(100.0*Actual, Fore => 9, Aft => 2, Exp => 0);
|
||||
F_IO.Put(100.0*Expected, Fore => 11, Aft => 2, Exp => 0);
|
||||
F_IO.Put(100.0*Deviation, Fore => 13, Aft => 2, Exp => 0);
|
||||
end Print;
|
||||
|
||||
Cnt: array(Nonzero_Digit) of Natural := (1 .. 9 => 0);
|
||||
D: Nonzero_Digit;
|
||||
Sum: Natural := 0;
|
||||
Counter: Positive;
|
||||
|
||||
begin
|
||||
while not Ada.Text_IO.End_Of_File loop
|
||||
-- each line in the input file holds Counter, followed by Fib(Counter)
|
||||
N_IO.Get(Counter);
|
||||
-- Counter and skip it, we just don't need it
|
||||
D := First_Digit(Ada.Text_IO.Get_Line);
|
||||
-- read the rest of the line and extract the first digit
|
||||
Cnt(D) := Cnt(D)+1;
|
||||
Sum := Sum + 1;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(" Digit Found[total] Expected[total] Found[%]"
|
||||
& " Expected[%] Difference[%]");
|
||||
for I in Nonzero_Digit loop
|
||||
Print(I, Cnt(I), Sum);
|
||||
Ada.Text_IO.New_Line;
|
||||
end loop;
|
||||
end Benford;
|
||||
|
|
@ -1 +0,0 @@
|
|||
-- N_IO.Get(Counter);
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
func$ add a$ b$ .
|
||||
for i to higher len a$ len b$
|
||||
if len a$ < len b$ : swap a$ b$
|
||||
for i to len a$
|
||||
a = number substr a$ i 1
|
||||
b = number substr b$ i 1
|
||||
b = 0
|
||||
if i <= len b$ : b = number substr b$ i 1
|
||||
r = a + b + c
|
||||
c = r div 10
|
||||
r$ &= r mod 10
|
||||
|
|
@ -9,7 +11,6 @@ func$ add a$ b$ .
|
|||
if c > 0 : r$ &= c
|
||||
return r$
|
||||
.
|
||||
#
|
||||
len fibdist[] 9
|
||||
proc mkfibdist .
|
||||
# generate 1000 fibonacci numbers as
|
||||
|
|
@ -36,7 +37,7 @@ mkfibdist
|
|||
len benfdist[] 9
|
||||
proc mkbenfdist .
|
||||
for i to 9
|
||||
benfdist[i] = log10 (1 + 1.0 / i)
|
||||
benfdist[i] = log (1 + 1 / i) 10
|
||||
.
|
||||
.
|
||||
mkbenfdist
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
$url = "https://oeis.org/A000045/b000045.txt"
|
||||
$file = "$env:TEMP\FibonacciNumbers.txt"
|
||||
(New-Object System.Net.WebClient).DownloadFile($url, $file)
|
||||
|
||||
$benford = Get-Content -Path $file |
|
||||
Select-Object -Skip 1 -First 1000 |
|
||||
ForEach-Object {(($_ -split " ")[1].ToString().ToCharArray())[0]} |
|
||||
Group-Object |
|
||||
Select-Object -Property @{Name="Digit" ; Expression={[int]($_.Name)}},
|
||||
Count,
|
||||
@{Name="Actual" ; Expression={$_.Count/1000}},
|
||||
@{Name="Expected"; Expression={[double]("{0:f5}" -f [Math]::Log10(1 + 1 / $_.Name))}}
|
||||
|
||||
$benford | Sort-Object -Property Digit | Format-Table -AutoSize
|
||||
|
||||
Remove-Item -Path $file -Force -ErrorAction SilentlyContinue
|
||||
Loading…
Add table
Add a link
Reference in a new issue