Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,12 @@
|
|||
((main {
|
||||
(2 3 5 7 11 13 17 19 23)
|
||||
avg !
|
||||
%d nl <<})
|
||||
|
||||
(avg {
|
||||
dup
|
||||
<- sum ! ->
|
||||
len
|
||||
cudiv })
|
||||
|
||||
(sum { <- 0 -> {+} each }))
|
||||
|
|
@ -1,3 +1,2 @@
|
|||
0001>p&: #v_$::01g/.@
|
||||
^10+1g10+<
|
||||
Enter 0 (zero) to finish.
|
||||
&:0\:!v!:-1<
|
||||
@./\$_\&+\^
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import std.stdio;
|
||||
|
||||
real mean(Range)(Range r) {
|
||||
real mean(Range)(Range r) pure nothrow @nogc {
|
||||
real sum = 0.0;
|
||||
int count;
|
||||
|
||||
|
|
@ -16,8 +14,10 @@ real mean(Range)(Range r) {
|
|||
}
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
|
||||
int[] data;
|
||||
writeln("mean: ", data.mean());
|
||||
writeln("Mean: ", data.mean);
|
||||
data = [3, 1, 4, 1, 5, 9];
|
||||
writeln("mean: ", data.mean());
|
||||
writeln("Mean: ", data.mean);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
real mean(Range)(Range r) pure nothrow {
|
||||
real mean(Range)(Range r) pure nothrow @nogc {
|
||||
return r.sum / max(1.0L, r.count);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import std.stdio, std.conv, std.algorithm, std.math, std.traits;
|
||||
|
||||
CommonType!(T, real) mean(T)(T[] n ...) if (isNumeric!(T)) {
|
||||
alias CommonType!(T, real) E;
|
||||
CommonType!(T, real) mean(T)(T[] n ...) if (isNumeric!T) {
|
||||
alias E = CommonType!(T, real);
|
||||
auto num = n.dup;
|
||||
schwartzSort!(abs, "a > b")(num);
|
||||
return reduce!q{a+b}(0.0L, map!(to!E)(num)) / max(1, num.length);
|
||||
num.schwartzSort!(abs, "a > b");
|
||||
return num.map!(to!E).sum(0.0L) / max(1, num.length);
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@
|
|||
theValue += aValue.
|
||||
]
|
||||
|
||||
#method number = theValue / theCount.
|
||||
#method value = theValue / theCount.
|
||||
}
|
||||
|
||||
// --- Program ---
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
console writeLine:(MeanAction new foreach:(1, 2, 3, 4, 5, 6, 7, 8) number).
|
||||
console writeLine:(MeanAction new foreach:(1, 2, 3, 4, 5, 6, 7, 8) value).
|
||||
].
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
defmodule RC do
|
||||
def mean(list), do: Enum.sum(list) / Enum.count(list)
|
||||
end
|
||||
|
|
@ -9,3 +9,4 @@ function mean(array)
|
|||
}
|
||||
|
||||
alert( mean( [1,2,3,4,5] ) ); // 3
|
||||
alert( mean( [] ) ); // 0
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
function mean(a)
|
||||
{
|
||||
return a.length ? Functional.reduce('+', 0, a) / a.length : 0;
|
||||
}
|
||||
function mean(array) {
|
||||
var sum = 0;
|
||||
array.forEach(function(value){
|
||||
sum += value;
|
||||
});
|
||||
return array.length ? sum / array.length : 0;
|
||||
}
|
||||
|
||||
alert( mean( [1,2,3,4,5] ) ); // 3
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
function mean(array) {
|
||||
return !array.length ? 0
|
||||
: array.reduce(function(pre, cur, i) {
|
||||
return (pre * i + cur) / (i + 1);
|
||||
});
|
||||
}
|
||||
|
||||
alert( mean( [1,2,3,4,5] ) ); // 3
|
||||
alert( mean( [] ) ); // 0
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Array.prototype.mean = function() {
|
||||
return !this.length ? 0
|
||||
: this.reduce(function(pre, cur, i) {
|
||||
return (pre * i + cur) / (i + 1);
|
||||
});
|
||||
}
|
||||
|
||||
alert( [1,2,3,4,5].mean() ); // 3
|
||||
alert( [].mean() ); // 0
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function mean(a)
|
||||
{
|
||||
return a.length ? Functional.reduce('+', 0, a) / a.length : 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
:- module arithmetic_mean.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
|
||||
:- import_module float, list, require.
|
||||
|
||||
main(!IO) :-
|
||||
io.print_line(mean([1.0, 2.0, 3.0, 4.0, 5.0]), !IO).
|
||||
|
||||
:- func mean(list(float)) = float.
|
||||
|
||||
mean([]) = func_error("mean: emtpy list").
|
||||
mean(Ns @ [_ | _]) = foldl((+), Ns, 0.0) / float(length(Ns)).
|
||||
|
||||
:- end_module arithmetic_mean.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
:- func mean(list(float)::in(non_empty_list)) = (float::out).
|
||||
|
||||
mean(Ns) = foldl((+), Ns, 0.0) / float(length(Ns)).
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
mean(List, Mean) :-
|
||||
length(List, Length),
|
||||
sumlist(List, Sum),
|
||||
Mean is Sum / Length.
|
||||
|
|
@ -1,20 +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 = ''
|
||||
do j=1 for 6
|
||||
say 'numbers = ' @.j; say 'average = ' avg(@.j); say
|
||||
end /*t*/
|
||||
@.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 =
|
||||
do j=1 for 6
|
||||
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.]'
|
||||
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*/
|
||||
if w==0 then return 'N/A: ───[no numeric values.]'
|
||||
avg: procedure; parse arg x; w=words(x); s=0; $=left('',20)
|
||||
if w==0 then return 'N/A: ───[null vector.]'
|
||||
|
||||
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*/
|
||||
|
||||
if w==0 then return 'N/A: ───[no numeric values.]'
|
||||
return s/max(1,w)
|
||||
|
|
|
|||
|
|
@ -1,2 +1,9 @@
|
|||
def mean(nums)
|
||||
nums.inject(0.0, :+) / nums.size
|
||||
end
|
||||
|
||||
nums = [3, 1, 4, 1, 5, 9]
|
||||
nums.empty? ? 0 : nums.inject(:+) / Float(nums.size)
|
||||
nums.size.downto(0) do |i|
|
||||
ary = nums[0,i]
|
||||
puts "array size #{ary.size} : #{mean(ary)}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
fn sum(arr: &[f64]) -> f64 {
|
||||
return arr.iter().fold(0.0, |p,q| p + *q);
|
||||
}
|
||||
|
||||
fn mean(arr: &[f64]) -> f64 {
|
||||
return 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));
|
||||
|
||||
let w = &[];
|
||||
println!("mean of {}: {}", w, mean(w));
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
function Mean(lst)
|
||||
if empty(a:lst)
|
||||
throw "Empty"
|
||||
endif
|
||||
let sum = 0.0
|
||||
for i in a:lst
|
||||
let sum += i
|
||||
endfor
|
||||
return sum / len(a:lst)
|
||||
endfunction
|
||||
|
|
@ -0,0 +1 @@
|
|||
sum($values) div count($values)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:output method="text"/>
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:variable name="values" select="/*/*"/>
|
||||
<xsl:value-of select="sum($values) div count($values)"/>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<numbers>
|
||||
<!-- Average is 2.4 -->
|
||||
<number>1</number>
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
<number>3</number>
|
||||
<number>5</number>
|
||||
</numbers>
|
||||
Loading…
Add table
Add a link
Reference in a new issue