RosettaCodeData/Task/Forward-difference/Objeck/forward-difference.objeck

37 lines
769 B
Plaintext

bundle Default {
class Test {
function : Main(args : String[]) ~ Nil {
a := [90.0, 47.0, 58.0, 29.0, 22.0, 32.0, 55.0, 5.0, 55.0, 73.0];
Print(Diff(a, 1));
Print(Diff(a, 2));
Print(Diff(a, 9));
}
function : Print(a : Float[]) ~ Nil {
if(a <> Nil) {
'['->Print();
each(i : a) {
a[i]->Print(); ','->Print();
};
']'->PrintLine();
};
}
function : Diff(a : Float[], n : Int) ~ Float[] {
if (n < 0) {
return Nil;
};
for(i := 0; i < n & a->Size() > 0; i += 1;) {
b := Float->New[a->Size() - 1];
for(j := 0; j < b->Size(); j += 1;){
b[j] := a[j+1] - a[j];
};
a := b;
};
return a;
}
}
}