How to resolve the algorithm Multifactorial step by step in the Miranda programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multifactorial step by step in the Miranda programming language
Table of Contents
Problem Statement
The factorial of a number, written as
n !
{\displaystyle n!}
, is defined as
n !
n ( n − 1 ) ( n − 2 ) . . . ( 2 ) ( 1 )
{\displaystyle n!=n(n-1)(n-2)...(2)(1)}
. Multifactorials generalize factorials as follows: In all cases, the terms in the products are positive integers. If we define the degree of the multifactorial as the difference in successive terms that are multiplied together for a multifactorial (the number of exclamation marks), then the task is twofold:
Note: The wikipedia entry on multifactorials gives a different formula. This task uses the Wolfram mathworld definition.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Multifactorial step by step in the Miranda programming language
Source code in the miranda programming language
main :: [sys_message]
main = [ Stdout (show deg ++ ": " ++ show (map (multifac deg) [1..10]) ++ "\n")
| deg <- [1..5]]
multifac :: num->num->num
multifac deg = product . takewhile (>1) . iterate sub
where sub n = n - deg
You may also check:How to resolve the algorithm Program name step by step in the Make programming language
You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm 100 doors step by step in the CLU programming language
You may also check:How to resolve the algorithm Multisplit step by step in the Java programming language
You may also check:How to resolve the algorithm Longest increasing subsequence step by step in the Swift programming language