Factorial
via User-defined Postfix Operator
[*]
is a reduction operator that multiplies all the following values together. Note that we don't need to start at 1, since the degenerate case of [*]()
correctly returns 1, and multiplying by 1 to start off with is silly in any case.
Output:
via Memoized Constant Sequence
This approach is much more efficient for repeated use, since it automatically caches. [\*]
is the so-called triangular version of [*]. It returns the intermediate results as a list. Note that Raku allows you to define constants lazily, which is rather helpful when your constant is of infinite size...
Output:
Last updated