Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -0,0 +1,33 @@
import ballerina/io;
function sma(int period) returns (function(float) returns float) {
int i = 0;
float sum = 0.0;
float[] storage = [];
return function(float input) returns float {
if storage.length() < period {
sum += input;
storage.push(input);
}
sum += input - storage[i];
storage[i] = input;
i = (i + 1) % period;
return sum / <float>storage.length();
};
}
function F(float f, int size, int prec) returns string {
string s = f.toFixedString(prec);
return size >= 0 ? s.padStart(size) : s.padEnd(size);
}
public function main() {
var sma3 = sma(3);
var sma5 = sma(5);
io:println(" x sma3 sma5");
float[] rng = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1];
foreach float x in rng {
io:println(`${F(x, 5, 3)} ${F(sma3(x), 5, 3)} ${F(sma5(x), 5, 3)}`);
}
}

View file

@ -23,7 +23,7 @@ prefix
#
sma5 = sma_new 5
sma3 = sma_new 3
numfmt 2 4
numfmt 4 2
for v in [ 1 2 3 4 5 5 4 3 2 1 ]
print sma_get sma3 v & " " & sma_get sma5 v
.