34 lines
563 B
Plaintext
34 lines
563 B
Plaintext
type IFact {
|
|
int fact(int n);
|
|
}
|
|
|
|
class FactRec() : IFact impl IFact {
|
|
int fact(int n) {
|
|
return factA(n, 1);
|
|
}
|
|
|
|
int factA(int n, int a) {
|
|
if n == 0 { a; }
|
|
else { factA(n - 1, a * n); };
|
|
}
|
|
|
|
export IFact : fact;
|
|
}
|
|
|
|
class FactAcc() : IFact impl IFact {
|
|
int fact(int n) {
|
|
int ret = 1;
|
|
while (n > 1) {
|
|
ret = ret * n;
|
|
n = n - 1;
|
|
};
|
|
return ret;
|
|
}
|
|
|
|
export IFact : fact;
|
|
}
|
|
|
|
int main(){
|
|
(new FactRec:IFact()).fact(500) + (new FactAcc:IFact()).fact(500);
|
|
}
|