Just a question of curiosity, not serious.
In the JS language I know that a factorial operation can be defined in the following form.
function factorial(n) {
if (n === 1) return 1;
return factorial(n - 1) * n;
}
Then I defined a factorial of a factorial operation in the following form, and called it super_factorial_1
. There is a similar description on Wikipedia.
function super_factorial_1(n) {
if (n === 1) return factorial(1);
return super_factorial_1(n - 1) * factorial(n);
}
Similarly, using the super_factorial_1
as an operator, the super_factorial_2
is defined here:
function super_factorial_2(n) {
if (n === 1) return super_factorial_1(1);
return super_factorial_2(n - 1) * super_factorial_1(n);
}
Now the question is how to define the super_factorial_n
operation, and the super_factorial_n_n
, and furthermore, the super_factorial_n..._n{n of n}
.
I have used a crude method to define the above super_factorial_n
operation, but I don't think this method is good enough.
function super_factorial_n(n, m) {
const fns = Array(n + 1).fill(0);
fns[0] = factorial;
for (let i = 1; i <= n; i++) {
fns[i] = function (m) {
if (m === 1) return fns[i - 1](1);
return fns[i](m - 1) * fns[i - 1](m);
}
}
return fns[n](m);
}
Perhaps this is an optimisation direction for the process programming paradigm. :)