Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,6 +0,0 @@
package Pythagorean_Means is
type Set is array (Positive range <>) of Float;
function Arithmetic_Mean (Data : Set) return Float;
function Geometric_Mean (Data : Set) return Float;
function Harmonic_Mean (Data : Set) return Float;
end Pythagorean_Means;

View file

@ -1,33 +0,0 @@
with Ada.Numerics.Generic_Elementary_Functions;
package body Pythagorean_Means is
package Math is new Ada.Numerics.Generic_Elementary_Functions (Float);
function "**" (Left, Right : Float) return Float renames Math."**";
function Arithmetic_Mean (Data : Set) return Float is
Sum : Float := 0.0;
begin
for I in Data'Range loop
Sum := Sum + Data (I);
end loop;
return Sum / Float (Data'Length);
end Arithmetic_Mean;
function Geometric_Mean (Data : Set) return Float is
Product : Float := 1.0;
begin
for I in Data'Range loop
Product := Product * Data (I);
end loop;
return Product**(1.0/Float(Data'Length));
end Geometric_Mean;
function Harmonic_Mean (Data : Set) return Float is
Reciprocal_Sum : Float := 0.0;
begin
for I in Data'Range loop
Reciprocal_Sum := Reciprocal_Sum + Data (I)**(-1);
end loop;
return Float (Data'Length) / Reciprocal_Sum;
end Harmonic_Mean;
end Pythagorean_Means;

View file

@ -1,13 +0,0 @@
with Ada.Text_IO;
with Pythagorean_Means;
procedure Main is
My_Set : Pythagorean_Means.Set := (1.0, 2.0, 3.0, 4.0, 5.0,
6.0, 7.0, 8.0, 9.0, 10.0);
Arithmetic_Mean : Float := Pythagorean_Means.Arithmetic_Mean (My_Set);
Geometric_Mean : Float := Pythagorean_Means.Geometric_Mean (My_Set);
Harmonic_Mean : Float := Pythagorean_Means.Harmonic_Mean (My_Set);
begin
Ada.Text_IO.Put_Line (Float'Image (Arithmetic_Mean) & " >= " &
Float'Image (Geometric_Mean) & " >= " &
Float'Image (Harmonic_Mean));
end Main;

View file

@ -1,52 +0,0 @@
function arithmetic_mean(sequence s)
atom sum
if length(s) = 0 then
return 0
else
sum = 0
for i = 1 to length(s) do
sum += s[i]
end for
return sum/length(s)
end if
end function
function geometric_mean(sequence s)
atom p
p = 1
for i = 1 to length(s) do
p *= s[i]
end for
return power(p,1/length(s))
end function
function harmonic_mean(sequence s)
atom sum
if length(s) = 0 then
return 0
else
sum = 0
for i = 1 to length(s) do
sum += 1/s[i]
end for
return length(s) / sum
end if
end function
function true_or_false(atom x)
if x then
return "true"
else
return "false"
end if
end function
constant s = {1,2,3,4,5,6,7,8,9,10}
constant arithmetic = arithmetic_mean(s),
geometric = geometric_mean(s),
harmonic = harmonic_mean(s)
printf(1,"Arithmetic: %g\n", arithmetic)
printf(1,"Geometric: %g\n", geometric)
printf(1,"Harmonic: %g\n", harmonic)
printf(1,"Arithmetic>=Geometric>=Harmonic: %s\n",
{true_or_false(arithmetic>=geometric and geometric>=harmonic)})

View file

@ -1,23 +0,0 @@
$A = 0
$LogG = 0
$InvH = 0
$ii = 1..10
foreach($i in $ii) {
# Arithmetic mean is computed directly
$A += $i / $ii.Count
# Geometric mean is computed using Logarithms
$LogG += [Math]::Log($i) / $ii.Count
# Harmonic mean is computed using its inverse
$InvH += 1 / ($i * $ii.Count)
}
$G = [Math]::Exp($LogG)
$H = 1/$InvH
write-host "Arithmetic mean: A = $A"
write-host "Geometric mean: G = $G"
write-host "Harmonic mean: H = $H"
write-host "Is A >= G ? $($A -ge $G)"
write-host "Is G >= H ? $($G -ge $H)"

View file

@ -1,27 +0,0 @@
Function arithmetic_mean(arr)
sum = 0
For i = 0 To UBound(arr)
sum = sum + arr(i)
Next
arithmetic_mean = sum / (UBound(arr)+1)
End Function
Function geometric_mean(arr)
product = 1
For i = 0 To UBound(arr)
product = product * arr(i)
Next
geometric_mean = product ^ (1/(UBound(arr)+1))
End Function
Function harmonic_mean(arr)
sum = 0
For i = 0 To UBound(arr)
sum = sum + (1/arr(i))
Next
harmonic_mean = (UBound(arr)+1) / sum
End Function
WScript.StdOut.WriteLine arithmetic_mean(Array(1,2,3,4,5,6,7,8,9,10))
WScript.StdOut.WriteLine geometric_mean(Array(1,2,3,4,5,6,7,8,9,10))
WScript.StdOut.WriteLine harmonic_mean(Array(1,2,3,4,5,6,7,8,9,10))