Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,4 @@
|
|||
{x{+=<:2:x/%<:d:~$<:01:~><:02:~><:03:~><:04:~><:05:~><:06:~><:07:~><:08:
|
||||
~><:09:~><:0a:~><:0b:~><:0c:~><:0d:~><:0e:~><:0f:~><:10:~><:11:~><:12:~>
|
||||
<:13:~><:14:~><:15:~><:16:~><:17:~><:18:~><:19:~><:ffffffffffffffff:~>{x
|
||||
{+>}:8f:{&={+>{~>&=x<:ffffffffffffffff:/#:8f:{{=<:19:x/%
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
AVGP CSECT
|
||||
USING AVGP,12
|
||||
LR 12,15
|
||||
SR 3,3 i=0
|
||||
SR 6,6 sum=0
|
||||
LOOP CH 3,=AL2(NN-T-1) for i=1 to nn
|
||||
BH ENDLOOP
|
||||
L 2,T(3) t(i)
|
||||
MH 2,=H'100' scaling factor=2
|
||||
AR 6,2 sum=sum+t(i)
|
||||
LA 3,4(3) next i
|
||||
B LOOP
|
||||
ENDLOOP LR 5,6 sum
|
||||
LA 4,0
|
||||
D 4,NN sum/nn
|
||||
XDECO 5,Z edit binary
|
||||
MVC U,Z+10 descale
|
||||
MVI Z+10,C'.'
|
||||
MVC Z+11(2),U
|
||||
XPRNT Z,80 output
|
||||
XR 15,15
|
||||
BR 14
|
||||
T DC F'10',F'9',F'8',F'7',F'6',F'5',F'4',F'3',F'2',F'1'
|
||||
NN DC A((NN-T)/4)
|
||||
Z DC CL80' '
|
||||
U DS CL2
|
||||
END AVGP
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
begin
|
||||
% procedure to find the mean of the elements of a vector. %
|
||||
% As the procedure can't find the bounds of the array for itself, %
|
||||
% we pass them in lb and ub %
|
||||
real procedure mean ( real array vector ( * )
|
||||
; integer value lb
|
||||
; integer value ub
|
||||
) ;
|
||||
begin
|
||||
real sum;
|
||||
assert( ub > lb ); % terminate the program if there are no elements %
|
||||
sum := 0;
|
||||
for i := lb until ub do sum := sum + vector( i );
|
||||
sum / ( ( ub + 1 ) - lb )
|
||||
end mean ;
|
||||
|
||||
% test the mean procedure by finding the mean of 1.1, 2.2, 3.3, 4.4, 5.5 %
|
||||
real array numbers ( 1 :: 5 );
|
||||
for i := 1 until 5 do numbers( i ) := i + ( i / 10 );
|
||||
r_format := "A"; r_w := 10; r_d := 2; % set fixed point output %
|
||||
write( mean( numbers, 1, 5 ) );
|
||||
end.
|
||||
|
|
@ -1,32 +1,27 @@
|
|||
#define system.
|
||||
#define system'routines.
|
||||
#define extensions.
|
||||
|
||||
// --- Sum ---
|
||||
|
||||
#class MeanAction : BasePattern
|
||||
#class(extension)op
|
||||
{
|
||||
#field theValue.
|
||||
#field theCount.
|
||||
|
||||
#constructor new
|
||||
#method average
|
||||
[
|
||||
theValue := Real new.
|
||||
theCount := Integer new.
|
||||
#var aSum := Real new.
|
||||
#var aCount := Integer new:0.
|
||||
|
||||
#var anEnumerator := self enumerator.
|
||||
|
||||
#loop (anEnumerator next)?
|
||||
[
|
||||
aSum += anEnumerator get.
|
||||
aCount += 1.
|
||||
].
|
||||
|
||||
^ aSum / aCount.
|
||||
]
|
||||
|
||||
#method evaluate : aValue
|
||||
[
|
||||
theCount += 1.
|
||||
|
||||
theValue += aValue.
|
||||
]
|
||||
|
||||
#method value = theValue / theCount.
|
||||
}
|
||||
|
||||
// --- Program ---
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
console writeLine:(MeanAction new foreach:(1, 2, 3, 4, 5, 6, 7, 8) value).
|
||||
#var anArray := (1, 2, 3, 4, 5, 6, 7, 8).
|
||||
console writeLine:"Arithmetic mean of {":anArray:"} is ":(anArray average).
|
||||
].
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
(setq x '[1 2 3 4])
|
||||
(string-to-number (calc-eval (format "vmean(%s)" x)))
|
||||
|
|
@ -1 +1,2 @@
|
|||
sub mean (@a) { ([+] @a) / (@a || 1) }
|
||||
multi mean([]){ Failure.new('mean on empty list is not defined') }; # Failure-objects are lazy exceptions
|
||||
multi mean (@a) { ([+] @a) / @a }
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
/*REXX pgm finds the averages/arithmetic mean of several lists (vectors)*/
|
||||
@.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 =
|
||||
/*REXX program finds the averages/arithmetic mean of several lists (vectors).*/
|
||||
@.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. */
|
||||
do j=1 for 6
|
||||
say 'numbers = ' @.j; say 'average = ' avg(@.j); say copies('═',60)
|
||||
say 'numbers = ' @.j; say "average = " avg(@.j); say copies('═',60)
|
||||
end /*t*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────AVG subroutine──────────────────────*/
|
||||
avg: procedure; parse arg x; w=words(x); s=0; $=left('',20)
|
||||
if w==0 then return 'N/A: ───[null vector.]'
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
avg: procedure; parse arg x; #=words(x); $=0 /*#: number of items. */
|
||||
if #==0 then return 'N/A: ───[null vector.]' /*No words? Return N/A*/
|
||||
|
||||
do k=1 for w; _=word(x,k)
|
||||
if datatype(_,'N') then do; s=s+_; iterate; end
|
||||
say $ '***error!*** non-numeric: ' _; w=w-1 /*adjust W*/
|
||||
end /*k*/
|
||||
do k=1 for #; _=word(x,k) /*obtain a number.*/
|
||||
if datatype(_,'N') then do; $=$+_; iterate; end /*if numeric, add.*/
|
||||
say left('',20) "***error!*** non-numeric: " _; #=#-1 /*error; adjust #.*/
|
||||
end /*k*/
|
||||
|
||||
if w==0 then return 'N/A: ───[no numeric values.]'
|
||||
return s/max(1,w)
|
||||
if #==0 then return 'N/A: ───[no numeric values.]' /*No nums? Return N/A.*/
|
||||
return $/max(1,#) /*return the average. */
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
fn sum(arr: &[f64]) -> f64 {
|
||||
return arr.iter().fold(0.0, |p,q| p + *q);
|
||||
arr.iter().fold(0.0, |p,&q| p + q)
|
||||
}
|
||||
|
||||
fn mean(arr: &[f64]) -> f64 {
|
||||
return sum(arr) / arr.len() as f64;
|
||||
sum(arr) / arr.len() as f64
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v = &[2.0, 3.0, 5.0, 7.0, 13.0, 21.0, 33.0, 54.0];
|
||||
println!("mean of {}: {}", v, mean(v));
|
||||
println!("mean of {:?}: {:?}", v, mean(v));
|
||||
|
||||
let w = &[];
|
||||
println!("mean of {}: {}", w, mean(w));
|
||||
println!("mean of {:?}: {:?}", w, mean(w));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
create table "numbers" ("datapoint" integer);
|
||||
|
||||
insert into "numbers" select rownum from tab;
|
||||
|
||||
select sum("datapoint")/count(*) from "numbers";
|
||||
|
|
@ -0,0 +1 @@
|
|||
Mean(Ans
|
||||
|
|
@ -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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue