Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,54 @@
import system'routines;
import system'collections;
import extensions;
class SMA
{
object thePeriod;
object theList;
constructor new(period)
{
thePeriod := period;
theList :=new List();
}
append(n)
{
theList.append(n);
var count := theList.Length;
count =>
0 { ^0.0r }
: {
if (count > thePeriod)
{
theList.removeAt:0;
count := thePeriod
};
var sum := theList.summarize(Real.new());
^ sum / count
}
}
}
public program()
{
var SMA3 := SMA.new:3;
var SMA5 := SMA.new:5;
for (int i := 1, i <= 5, i += 1) {
console.printPaddingRight(30, "sma3 + ", i, " = ", SMA3.append:i);
console.printLine("sma5 + ", i, " = ", SMA5.append:i)
};
for (int i := 5, i >= 1, i -= 1) {
console.printPaddingRight(30, "sma3 + ", i, " = ", SMA3.append:i);
console.printLine("sma5 + ", i, " = ", SMA5.append:i)
};
console.readChar()
}