Introduction
Factorials are one of the most frequently used examples to show how a programming language works. A factorial, denoted \$n!\$, is \$1⋅2⋅3⋅…⋅(n-2)⋅(n-1)⋅n\$.
There is also the superfactorial (there are other definitions of this, but I chose this one because it looks more like the factorial), denoted \$n$\$, which is equal to \$1!⋅2!⋅3!⋅…⋅(n-2)!⋅(n-1)!⋅n!\$.
From that you can create an infinity of (super)*factorials (means any number of times super
followed by one factorial
) (supersuperfactorial, supersupersuperfactorial, etc...) which all can be represented as a function \$‼(x,y)\$, which has two parameters, \$x\$ the number to (super)*factorialize, and y, the number of times plus one that you add the prefix super before factorial (So if \$y=1\$ it would be a factorial (\$x!=\space‼(x,1)\$), with \$y=2\$ a superfactorial, and with \$y=4\$ a supersupersuperfactorial).
\$!!\$ is defined as such:
\$‼(x,0)=x\$ (if \$y\$ is 0, return \$x\$)
\$‼(x,y)\space=\space‼(1,y-1)\space⋅\space‼(2,y-1)\space⋅\space‼(3,y-1)\space⋅…⋅\space‼(x-2,y-1)\space⋅\space‼(x-1,y-1)\$
The second definition would have looked cleaner with a pi product \$\prod\$, but it does not display properly. (image here)
In Python, \$!!\$ could be implemented this way:
from functools import reduce
def n_superfactorial(x, supers):
if x == 0:
return 1
elif supers == 0:
return x
return reduce(lambda x,y:x*y, [n_superfactorial(i, supers-1) for i in range(1, x+1)])
Challenge
Create a function/program that calculates \$!!(x,y)\$.
Your code is not required to support floats or negative numbers.
\$x\$ will always be \$≥1\$ and \$y\$ will always be \$≥0\$.
It is not required to compute \$!!\$ via recursion.
Your program may exit with a recursion error given large numbers, but should at least theoretically be able to calculate in finite time any (super)*factorial.
Test cases
Format : [x, y] -> result
[1, 1] -> 1
[2, 2] -> 2
[3, 3] -> 24
[3, 7] -> 384
[4, 4] -> 331776
[5, 3] -> 238878720
[2232, 0] -> 2232
[3, 200] -> 4820814132776970826625886277023487807566608981348378505904128
Note: if your language does not support integer types that are that large, you are not required to support the last test case.
Scoring
This is code-golf, so shortest answer in bytes wins.
factorial
). \$\endgroup\$