How to resolve the algorithm Multifactorial step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multifactorial step by step in the J 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 J programming language
Source code in the j programming language
NB. n multifact degree
multifact=: */@([ - ] * i.@>.@%)&>
('';' degree'),multifact table >:i.10
┌─────────┬──────────────────────────────────────┐
│ │ degree │
├─────────┼──────────────────────────────────────┤
│multifact│ 1 2 3 4 5 6 7 8 9 10│
├─────────┼──────────────────────────────────────┤
│ 1 │ 1 1 1 1 1 1 1 1 1 1│
│ 2 │ 2 2 2 2 2 2 2 2 2 2│
│ 3 │ 6 3 3 3 3 3 3 3 3 3│
│ 4 │ 24 8 4 4 4 4 4 4 4 4│
│ 5 │ 120 15 10 5 5 5 5 5 5 5│
│ 6 │ 720 48 18 12 6 6 6 6 6 6│
│ 7 │ 5040 105 28 21 14 7 7 7 7 7│
│ 8 │ 40320 384 80 32 24 16 8 8 8 8│
│ 9 │ 362880 945 162 45 36 27 18 9 9 9│
│10 │3628800 3840 280 120 50 40 30 20 10 10│
└─────────┴──────────────────────────────────────┘
You may also check:How to resolve the algorithm Shortest common supersequence step by step in the zkl programming language
You may also check:How to resolve the algorithm Bitmap/Write a PPM file step by step in the Python programming language
You may also check:How to resolve the algorithm Brace expansion step by step in the Phix programming language
You may also check:How to resolve the algorithm Palindrome dates step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Hello world/Web server step by step in the Dylan.NET programming language