Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,22 @@
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;
procedure Mean_Main is
type Vector is array (Positive range <>) of Float;
function Mean (Item : Vector) return float with pre => Item'length > 0;
function Mean (Item : Vector) return Float is
Sum : Float := 0.0;
begin
for I in Item'range loop
Sum := Sum + Item(I);
end loop;
return Sum / Float(Item'Length);
end Mean;
A : Vector := (3.0, 1.0, 4.0, 1.0, 5.0, 9.0);
begin
Put(Item => Mean (A), Fore => 1, Exp => 0);
New_Line;
-- test for zero length vector
Put(Item => Mean(A (1..0)), Fore => 1, Exp => 0);
New_Line;
end Mean_Main;

View file

@ -0,0 +1 @@
FUNCTION MEAN(some-table (ALL))

View file

@ -0,0 +1,28 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. find-mean.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 i PIC 9(4).
01 summ USAGE FLOAT-LONG.
LINKAGE SECTION.
01 nums-area.
03 nums-len PIC 9(4).
03 nums USAGE FLOAT-LONG
OCCURS 0 TO 1000 TIMES
DEPENDING ON nums-len.
01 result USAGE FLOAT-LONG.
PROCEDURE DIVISION USING nums-area, result.
IF nums-len = 0
MOVE 0 TO result
GOBACK
END-IF
DIVIDE FUNCTION SUM(nums (ALL)) BY nums-len GIVING result
GOBACK
.

View file

@ -0,0 +1 @@
u M

View file

@ -1,6 +1,5 @@
func mean &f[] .
for i = 1 to len f[] : s += f[i]
func mean f[] .
for v in f[] : s += v
return s / len f[]
.
f[] = [ 1 2 3 4 5 6 7 8 ]
print mean f[]
print mean [ 1 2 3 4 5 6 7 8 ]

View file

@ -0,0 +1,3 @@
(defun mean (lst)
(/ (float (apply '+ lst)) (length lst)))
(mean '(1 2 3 4))

View file

@ -0,0 +1,2 @@
(let ((x '(1 2 3 4)))
(calc-eval "vmean($1)" nil (append '(vec) x)))

View file

@ -0,0 +1,4 @@
(let ((x '(1 2 3 4)))
(string-to-number
(math-format-value
(calcFunc-vmean (cons 'vec x)))))

View file

@ -0,0 +1,16 @@
function 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
sequence test
test = {1.0, 2.0, 5.0, -5.0, 9.5, 3.14159}
? mean(test)

View file

@ -1,4 +1,4 @@
val umean = fn x:fold(x, by=fn{+}) / len(x)
val umean = fn(x list) { fold(x, by=fn{+}) / len(x) }
writeln " custom: ", umean([7, 3, 12])
writeln "built-in: ", mean([7, 3, 12])

View file

@ -0,0 +1,11 @@
function mean ($x) {
if ($x.Count -eq 0) {
return 0
} else {
$sum = 0
foreach ($i in $x) {
$sum += $i
}
return $sum / $x.Count
}
}

View file

@ -0,0 +1,7 @@
function mean ($x) {
if ($x.Count -eq 0) {
return 0
} else {
return ($x | Measure-Object -Average).Average
}
}

View file

@ -1,27 +1,29 @@
/*REXX program finds the averages/arithmetic mean of several lists (vectors) or CL input*/
parse arg @.1; if @.1='' then do; #=6 /*vector from the C.L.?*/
@.1 = 10 9 8 7 6 5 4 3 2 1
@.2 = 10 9 8 7 6 5 4 3 2 1 0 0 0 0 .11
@.3 = '10 20 30 40 50 -100 4.7 -11e2'
@.4 = '1 2 3 4 five 6 7 8 9 10.1. ±2'
@.5 = 'World War I & World War II'
@.6 = /* ◄─── a null value. */
end
else #=1 /*number of CL vectors.*/
do j=1 for #
say ' numbers = ' @.j
say ' average = ' avg(@.j)
say copies('', 79)
end /*t*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
avg: procedure; parse arg x; #=words(x) /*#: number of items.*/
if #==0 then return 'N/A: [null vector.]' /*No words? Return N/A*/
$=0
do k=1 for #; _=word(x,k) /*obtain a number. */
if datatype(_,'N') then do; $=$+_; iterate; end /*if numeric, then add*/
say left('',40) "***error*** non-numeric: " _; #=#-1 /*error; adjust number*/
end /*k*/
-- 21 Feb 2026
include Setting
if #==0 then return 'N/A: [no numeric values.]' /*No nums? Return N/A*/
return $ / # /*return the average. */
say 'ARITHMETIC MEAN'
say version
say
call Task '1;2;3;4;5;6;7;8;9;10'
call Task '1;10;100;1000;100000'
call Task '1'
exit
Task:
procedure
arg xx
say 'Arithmetic mean of' List2form(xx) '=' AmeanL(xx)
return
AmeanL:
procedure
arg xx
rr=0; nn=0
do while xx<>''
parse var xx xw';'xx
rr+=xw; nn+=1
end
return rr/nn
-- AmeanL full version; List2form
include Math

View file

@ -0,0 +1,7 @@
let arr = [3, 8, 4, 1, 5, 12]
let num = Js.Array.length(arr)
let tot = Js.Array.reduce(\"+", 0, arr)
let mean = float_of_int(tot) /. float_of_int(num)
Js.log(Js.Float.toString(mean))

View file

@ -0,0 +1,19 @@
rebol [
Title: "Arithmetic Mean (Average)"
URL: http://rosettacode.org/wiki/Average/Arithmetic_mean
]
average: func [v /local sum][
if empty? v [return 0]
sum: 0
forall v [sum: sum + v/1]
sum / length? v
]
; Note precision loss as spread increased.
print [mold x: [] "->" average x]
print [mold x: [3 1 4 1 5 9] "->" average x]
print [mold x: [1000 3 1 4 1 5 9 -1000] "->" average x]
print [mold x: [1e20 3 1 4 1 5 9 -1e20] "->" average x]

View file

@ -0,0 +1,4 @@
probe vect: #(i8! [3 1 4 1 5 9])
print ["mean:" vect/mean]
print ""
print query vect object! ;; to show all vector's info

View file

@ -0,0 +1,2 @@
Avg ← ÷⧻⟜/+
Avg [1 2 3 4]

View file

@ -0,0 +1,11 @@
Function mean(arr)
size = UBound(arr) + 1
mean = 0
For i = 0 To UBound(arr)
mean = mean + arr(i)
Next
mean = mean/size
End Function
'Example
WScript.Echo mean(Array(3,1,4,1,5,9))