How to resolve the algorithm Multifactorial step by step in the Common Lisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Multifactorial step by step in the Common Lisp 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 Common Lisp programming language

Source code in the common programming language

(defun mfac (n m)
  (reduce #'* (loop for i from n downto 1 by m collect i)))

(loop for i from 1 to 10
      do (format t "~2@a: ~{~a~^ ~}~%"
                 i (loop for j from 1 to 10
                         collect (mfac j i))))


  

You may also check:How to resolve the algorithm Hello world/Text step by step in the Self programming language
You may also check:How to resolve the algorithm Currying step by step in the Tcl programming language
You may also check:How to resolve the algorithm Return multiple values step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm 100 prisoners step by step in the J programming language
You may also check:How to resolve the algorithm Hello world/Web server step by step in the R programming language