Course of Raku / Advanced / Operators / Meta-operators / Exercises / Every factorial at once
Solution: Every factorial at once
Here is a possible solution to the task.
Code
say [\*] 1..6;🦋 You can find the source code in the file factorial.raku.
Output
(1 2 6 24 120 720)Comments
The backslash inside the brackets turns
[*]into a triangular reduction. Instead of collapsing the list to a single value, it keeps every partial product:1, then1*2, then1*2*3, and so on.Each partial product
1*2*...*kis exactly k!, so the result is the list of factorials of1through6. A plain[*] 1..6would have given only the last of these,720.