Multifactorial: Difference between revisions

m
(Add Draco)
m (→‎{{header|Wren}}: Minor tidy)
 
(26 intermediate revisions by 15 users not shown)
Line 22:
{{trans|Crystal}}
 
<langsyntaxhighlight lang="11l">F multifact(n, d)
R product((n .< 1).step(-d))
 
L(d) 1..5
print(‘Degree ’d‘: ’(1..10).map(n -> multifact(n, @d)))</langsyntaxhighlight>
 
{{out}}
Line 38:
 
{{trans|Wren}}
<langsyntaxhighlight lang="11l">F multifact(=n, d)
V prod = 1
L n > 1
prod *= n
n -= d
R prod</langsyntaxhighlight>
 
=={{header|360 Assembly}}==
For maximum compatibility, this program uses only the basic instruction set (S/360 1964 POP).
<langsyntaxhighlight lang="360asm">* Multifactorial 09/05/2016
MULFACR CSECT
USING MULFACR,13
Line 97:
R EQU 11
L EQU 12
END MULFACR</langsyntaxhighlight>
{{out}}
<pre>
Line 109:
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
PROC Multifactorial(INT n,d REAL POINTER res)
Line 138:
PutE()
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Multifactorial.png Screenshot from Atari 8-bit computer]
Line 150:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is
 
Line 168:
New_line;
end loop;
end Mfact;</langsyntaxhighlight>
{{out}}
<pre>
Line 179:
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">mf(integer a, n)
{
integer o;
Line 206:
 
0;
}</langsyntaxhighlight>
{{out}}
<pre>degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 216:
=={{header|ALGOL 68}}==
Translation of C.
<langsyntaxhighlight Algol68lang="algol68">BEGIN
INT highest degree = 5;
INT largest number = 10;
Line 240:
OD
END
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 253:
=={{header|ALGOL W}}==
Iterative multifactorial based on Ada, AutoHotkey, etc.
<langsyntaxhighlight lang="algolw">begin
% returns the multifactorial of n with the specified degree %
integer procedure multifactorial ( integer value n, degree ) ;
Line 274:
end for_v
end for_degree
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 284:
</pre>
 
=={{header|ANSI Standard BASICAppleScript}}==
<syntaxhighlight lang="applescript">on multifactorial(n, d)
set f to 1
repeat with n from n to 2 by -d
set f to f * n
end repeat
return f
end multifactorial
 
on task()
Translation of FreeBASIC.
set table to ""
repeat with degree from 1 to 5
set row to linefeed & "Degree " & degree & ":"
repeat with n from 1 to 10
set row to row & (space & multifactorial(n, degree))
end repeat
set table to table & row
end repeat
return table
end task
 
task()</syntaxhighlight>
<lang ANSI Standard BASIC>100 FUNCTION multiFactorial (n, degree)
 
110 IF n < 2 THEN
{{output}}
120 LET multiFactorial = 1
<syntaxhighlight lang="applescript">"
130 EXIT FUNCTION
Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
140 END IF
Degree 2: 1 2 3 8 15 48 105 384 945 3840
150 LET result = n
160Degree 3: 1 2 FOR3 i4 =10 n18 -28 degree TO 280 STEP162 -degree280
170Degree 4: 1 2 3 4 5 LET12 result21 =32 result45 * i120
Degree 5: 1 2 3 4 5 6 14 24 36 50"</syntaxhighlight>
180 NEXT i
190 LET multiFactorial = result
200 END FUNCTION
210
220 FOR degree = 1 TO 5
230 PRINT "Degree"; degree; " => ";
240 FOR n = 1 TO 10
250 PRINT multiFactorial(n, degree); " ";
260 NEXT n
270 PRINT
280 NEXT degree
290 END</lang>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">multifact: function [n deg][
if? n =< deg -> n
else -> n * multifact n-deg deg
Line 321 ⟶ 327:
]
print ""
]</langsyntaxhighlight>
 
{{out}}
Line 332 ⟶ 338:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Loop, 5 {
Output .= "Degree " (i := A_Index) ": "
Loop, 10
Line 344 ⟶ 350:
Result *= n
return, Result
}</langsyntaxhighlight>
'''Output:'''
<pre>Degree 1: 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800
Line 353 ⟶ 359:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MULTIFACTORIAL.AWK
# converted from Go
Line 373 ⟶ 379:
return(r)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 383 ⟶ 389:
</pre>
 
=={{header|BBC BASIC}}==
==={{header|ANSI BASIC}}===
<lang bbcbasic>REM >multifact
{{trans|FreeBASIC}}
{{works with|Decimal BASIC}}
<syntaxhighlight lang="basic">100 FUNCTION multiFactorial (n, degree)
110 IF n < 2 THEN
120 LET multiFactorial = 1
130 EXIT FUNCTION
140 END IF
150 LET result = n
160 FOR i = n - degree TO 2 STEP -degree
170 LET result = result * i
180 NEXT i
190 LET multiFactorial = result
200 END FUNCTION
210
220 FOR degree = 1 TO 5
230 PRINT "Degree"; degree; " => ";
240 FOR n = 1 TO 10
250 PRINT multiFactorial(n, degree); " ";
260 NEXT n
270 PRINT
280 NEXT degree
290 END</syntaxhighlight>
{{out}}
<pre>
Degree 1 => 1 2 6 24 120 720 5040 40320 362880 3628800
Degree 2 => 1 2 3 8 15 48 105 384 945 3840
Degree 3 => 1 2 3 4 10 18 28 80 162 280
Degree 4 => 1 2 3 4 5 12 21 32 45 120
Degree 5 => 1 2 3 4 5 6 14 24 36 50
</pre>
 
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic">REM >multifact
FOR i% = 1 TO 5
PRINT "Degree "; i%; ":";
Line 400 ⟶ 439:
mfact% = mfact% * i%
NEXT
= mfact%</langsyntaxhighlight>
{{out}}
<pre>Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 407 ⟶ 446:
Degree 4: 1 2 3 4 5 12 21 32 45 120
Degree 5: 1 2 3 4 5 6 14 24 36 50</pre>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "MultiFac.bas"
110 FOR I=1 TO 5
120 PRINT "Degree";I;": ";
130 FOR J=1 TO 10
140 PRINT MFACT(J,I);" ";
150 NEXT
160 PRINT
170 NEXT
180 DEF MFACT(N,DEGREE)
190 LET RESULT=1
200 FOR X=N TO 1 STEP-DEGREE
210 LET RESULT=RESULT*X
220 NEXT
230 LET MFACT=RESULT
240 END DEF</syntaxhighlight>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">MultiFact ← ×´⊣-↕∘⌈∘÷×⊢
 
MultiFact⌜⟜(5⊸↑) 1+↕10</syntaxhighlight>
{{out}}
<pre>┌─
╵ 1 1 1 1 1
2 2 2 2 2
6 3 3 3 3
24 8 4 4 4
120 15 10 5 5
720 48 18 12 6
5040 105 28 21 14
40320 384 80 32 24
362880 945 162 45 36
3628800 3840 280 120 50
┘</pre>
 
=={{header|C}}==
{{uses from|Library|C Runtime|component1=printf}}
<syntaxhighlight lang="c">
<lang c>
/* Include statements and constant definitions */
#include <stdio.h>
Line 441 ⟶ 515:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 452 ⟶ 526:
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">namespace RosettaCode.Multifactorial
{
using System;
Line 489 ⟶ 563:
}
}
}</langsyntaxhighlight>
Output:
<pre>1 2 6 24 120 720 5040 40320 362880 3628800
Line 498 ⟶ 572:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <algorithm>
#include <iostream>
Line 515 ⟶ 589:
return 0;
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 531 ⟶ 605:
=={{header|Clojure}}==
 
<langsyntaxhighlight Clojurelang="clojure">(defn !! [m n]
(->> (iterate #(- % m) n) (take-while pos?) (apply *)))
 
(doseq [m (range 1 6)]
(prn m (map #(!! m %) (range 1 11))))</langsyntaxhighlight>
 
{{out}}
Line 546 ⟶ 620:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">multifactorial = proc (n, degree: int) returns (int)
result: int := 1
for i: int in int$from_to_by(n, 1, -degree) do
Line 562 ⟶ 636:
stream$putc(po, '\n')
end
end start_up</langsyntaxhighlight>
{{out}}
<pre> 1 1 1 1 1
Line 576 ⟶ 650:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">
(defun mfac (n m)
(reduce #'* (loop for i from n downto 1 by m collect i)))
Line 584 ⟶ 658:
i (loop for j from 1 to 10
collect (mfac j i))))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 597 ⟶ 671:
9: 1 2 3 4 5 6 7 8 9 10
10: 1 2 3 4 5 6 7 8 9 10</pre>
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub multifac(n: uint32, d: uint32): (r: uint32) is
r := 1;
loop
r := r * n;
if n <= d then break; end if;
n := n - d;
end loop;
end sub;
 
var d: uint32 := 1;
while d <= 5 loop
print_i32(d);
print(": ");
var n: uint32 := 1;
while n <= 10 loop
print_i32(multifac(n, d));
print(" ");
n := n + 1;
end loop;
print_nl();
d := d + 1;
end loop;</syntaxhighlight>
{{out}}
<pre>1: 1 2 6 24 120 720 5040 40320 362880 3628800
2: 1 2 3 8 15 48 105 384 945 3840
3: 1 2 3 4 10 18 28 80 162 280
4: 1 2 3 4 5 12 21 32 45 120
5: 1 2 3 4 5 6 14 24 36 50</pre>
 
=={{header|Crystal}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">def multifact(n, d)
n.step(to: 1, by: -d).product
end
 
(1..5).each {|d| puts "Degree #{d}: #{(1..10).map{|n| multifact(n, d)}.join "\t"}"}</langsyntaxhighlight>
'''output'''
<pre style="overflow:scroll">
Line 614 ⟶ 720:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio, std.algorithm, std.range;
 
T multifactorial(T=long)(in int n, in int m) pure /*nothrow*/ {
Line 625 ⟶ 731:
writefln("%2d: %s", m, iota(1, 11)
.map!(n => multifactorial(n, m)));
}</langsyntaxhighlight>
{{out}}
<pre> 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 639 ⟶ 745:
 
=={{header|Dart}}==
<langsyntaxhighlight lang="dart">
main()
{
Line 665 ⟶ 771:
return a*fact((a-b),b);
}
</syntaxhighlight>
</lang>
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">proc nonrec multifac(int n, deg) ulong:
ulong result;
result := 1;
Line 686 ⟶ 792:
writeln()
od
corp</langsyntaxhighlight>
{{out}}
<pre> 1 1 1 1 1
Line 698 ⟶ 804:
362880 945 162 45 36
3628800 3840 280 120 50</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
function MultiFact(Num,Deg: integer): integer;
{Multifactorial from Degree and Number}
var N: integer;
begin
N:=Num;
Result:=Num;
if N = 0 then Result:=1
else while true do
begin
N := N - deg;
if N<1 then break;
Result:=Result * N;
end;
end;
 
 
procedure ShowMultifactorial(Memo: TMemo);
{Show combinations of deg/num of multifactorial}
var Deg,Num: integer;
var S: string;
begin
S:='';
for Deg:=1 to 5 do
begin
S:=S+Format('Degree: %d:',[Deg]);
for Num:=1 to 10 do S:=S+' '+Format('%7d',[MultiFact(Num,Deg)]);
S:=S+#$0D#$0A;
end;
Memo.Lines.Add(S);
end;
 
</syntaxhighlight>
{{out}}
<pre>
Degree: 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Degree: 2: 1 2 3 8 15 48 105 384 945 3840
Degree: 3: 1 2 3 4 10 18 28 80 162 280
Degree: 4: 1 2 3 4 5 12 21 32 45 120
Degree: 5: 1 2 3 4 5 6 14 24 36 50
</pre>
 
 
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight lang=easylang>
func mfact n k .
r = 1
while n > 1
r *= n
n -= k
.
return r
.
for k = 1 to 5
write "degree " & k & ":"
for n = 1 to 10
write " " & mfact n k
.
print ""
.
</syntaxhighlight>
 
=={{header|Elixir}}==
{{trans|Erlang}}
<langsyntaxhighlight lang="elixir">defmodule RC do
def multifactorial(n,d) do
Enum.take_every(n..1, d) |> Enum.reduce(1, fn x,p -> x*p end)
Line 710 ⟶ 884:
multifac = for n <- 1..10, do: RC.multifactorial(n,d)
IO.puts "Degree #{d}: #{inspect multifac}"
end)</langsyntaxhighlight>
 
{{out}}
Line 722 ⟶ 896:
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">-module(multifac).
-compile(export_all).
 
Line 733 ⟶ 907:
lists:foreach(fun (D) ->
io:format("Degree ~b: ~p~n",[D, [ multifac(N,D) || N <- Ns]])
end, Ds).</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="erlang">5> multifac:main().
Degree 1: [1,2,6,24,120,720,5040,40320,362880,3628800]
Degree 2: [1,2,3,8,15,48,105,384,945,3840]
Line 741 ⟶ 915:
Degree 4: [1,2,3,4,5,12,21,32,45,120]
Degree 5: [1,2,3,4,5,6,14,24,36,50]
ok</langsyntaxhighlight>
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM MULTIFACTORIAL
 
Line 773 ⟶ 947:
END FOR
END PROGRAM
</syntaxhighlight>
</lang>
<pre>
Degree 1 : 1 2 6 24 120 720 5040 40320 362880 3628800
Line 789 ⟶ 963:
=={{header|F_Sharp|F#}}==
 
<langsyntaxhighlight lang="fsharp">let rec mfact d = function
| n when n <= d -> n
| n -> n * mfact d (n-d)
Line 804 ⟶ 978:
ignore (List.init maxDegree (fun i -> showFor (i+1)))
0
</syntaxhighlight>
</lang>
<pre>1: [1; 2; 6; 24; 120; 720; 5040; 40320; 362880; 3628800]
2: [1; 2; 3; 8; 15; 48; 105; 384; 945; 3840]
Line 812 ⟶ 986:
 
=={{header|Factor}}==
<syntaxhighlight lang="text">USING: formatting io kernel math math.ranges prettyprint
sequences ;
IN: rosetta-code.multifactorial
Line 826 ⟶ 1,000:
5 [1,b] [ mf-row nl ] each ;
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 837 ⟶ 1,011:
 
=={{header|Forth}}==
<syntaxhighlight lang="text">: !n negate swap 1 dup rot do i * over +loop nip ;
: test cr 6 1 ?do 11 1 ?do i j !n . loop cr loop ;</langsyntaxhighlight>
{{out}}
<pre>test
Line 850 ⟶ 1,024:
=={{header|Fortran}}==
{{works with|Fortran|95 and later}}
<langsyntaxhighlight lang="fortran">program test
implicit none
integer :: i, j, n
Line 872 ⟶ 1,046:
 
end function multifactorial
end program test</langsyntaxhighlight>
{{out}}
<pre>
Line 883 ⟶ 1,057:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Function multiFactorial (n As UInteger, degree As Integer) As UInteger
Line 904 ⟶ 1,078:
Print
Print "Press any key to quit"
Sleep</langsyntaxhighlight>
 
{{out}}
Line 916 ⟶ 1,090:
 
=={{header|FunL}}==
<langsyntaxhighlight lang="funl">def multifactorial( n, d ) = product( n..1 by -d )
 
for d <- 1..5
println( d, [multifactorial(i, d) | i <- 1..10] ))</langsyntaxhighlight>
 
{{out}}
Line 932 ⟶ 1,106:
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap">MultiFactorial := function(n, k)
local r;
r := 1;
Line 952 ⟶ 1,126:
[ 40320, 384, 80, 32, 24 ],
[ 362880, 945, 162, 45, 36 ],
[ 3628800, 3840, 280, 120, 50 ] ]</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 975 ⟶ 1,149:
fmt.Println()
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 986 ⟶ 1,160:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">mulfac :: (Num a, Enum a) => a -> [a]
mulfac k = 1 : s
where
Line 1,001 ⟶ 1,175:
(print . take 10 . tail . mulfac)
[1 .. 5]
</syntaxhighlight>
</lang>
{{out}}
<pre>[1,2,6,24,120,720,5040,40320,362880,3628800]
Line 1,012 ⟶ 1,186:
 
The following is Unicon specific but can be readily translated into Icon:
<langsyntaxhighlight lang="unicon">procedure main(A)
l := integer(A[1]) | 10
every writeRow(n := !l, [: mf(!10,n) :])
Line 1,025 ⟶ 1,199:
if n <= 0 then return 1
return n*mf(n-m, m)
end</langsyntaxhighlight>
 
Sample run:
Line 1,039 ⟶ 1,213:
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "Multifac.bas"
110 FOR I=1 TO 5
120 PRINT "Degree";I;":";
Line 1,055 ⟶ 1,229:
240 NEXT
250 LET MFACT=RES
260 END DEF</langsyntaxhighlight>
 
=={{header|J}}==
<syntaxhighlight lang="j"> NB. n multifact degree
<lang J>
multifact=: */@([ - ] * i.@>.@%)&>
NB. tacit implementation of the recursive c function
('';' degree'),multifact table >:i.10
NB. int multifact(int n,int deg){return n<=deg?n:n*multifact(n-deg,deg);}
 
multifact=: [`([ * - $: ])@.(<~)
(a:,<' degree'),multifact table >:i.10
┌─────────┬──────────────────────────────────────┐
│ │ degree │
Line 1,079 ⟶ 1,250:
│ 9 │ 362880 945 162 45 36 27 18 9 9 9│
│10 │3628800 3840 280 120 50 40 30 20 10 10│
└─────────┴──────────────────────────────────────┘</syntaxhighlight>
</lang>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class MultiFact {
private static long multiFact(long n, int deg){
long ans = 1;
Line 1,101 ⟶ 1,271:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,113 ⟶ 1,283:
===Iterative===
{{trans|C}}
<syntaxhighlight lang="javascript">
<lang JavaScript>
function multifact(n, deg){
var result = n;
Line 1,122 ⟶ 1,292:
return result;
}
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="javascript">
<lang JavaScript>
function test (n, deg) {
for (var i = 1; i <= deg; i ++) {
Line 1,134 ⟶ 1,304:
}
}
</syntaxhighlight>
</lang>
 
{{out}}
<syntaxhighlight lang="javascript">
<lang JavaScript>
test(10, 5)
Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,144 ⟶ 1,314:
Degree 4: 1 2 3 4 5 12 21 32 45 120
Degree 5: 1 2 3 4 5 6 14 24 36 50
</syntaxhighlight>
</lang>
 
===Recursive===
 
{{trans|C}}
<langsyntaxhighlight JavaScriptlang="javascript">function multifact(n, deg){
return n <= deg ? n : n * multifact(n - deg, deg);
}</langsyntaxhighlight>
 
Test
<langsyntaxhighlight JavaScriptlang="javascript">function test (n, deg) {
for (var i = 1; i <= deg; i ++) {
var results = '';
Line 1,162 ⟶ 1,332:
console.log('Degree ' + i + ': ' + results);
}
}</langsyntaxhighlight>
{{Out}}
<syntaxhighlight lang="javascript">
<lang JavaScript>
test(10, 5)
Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,170 ⟶ 1,340:
Degree 3: 1 2 3 4 10 18 28 80 162 280
Degree 4: 1 2 3 4 5 12 21 32 45 120
Degree 5: 1 2 3 4 5 6 14 24 36 50 </langsyntaxhighlight>
 
=={{header|jq}}==
{{works with|jq|1.4}}
<langsyntaxhighlight lang="jq"># Input: n
# Output: n * (n - d) * (n - 2d) ...
def multifactorial(d):
. as $n
| ($n / d | floor) as $k
| reduce ($n - (d * range(0; $k))) as $i (1; . * $i);</langsyntaxhighlight>
 
<langsyntaxhighlight lang="jq"># Print out a d-by-n table of multifactorials neatly:
def table(d; n):
def lpad(i): tostring | (i - length) * " " + .;
def pp(stream): reduce stream as $i (""; . + ($i | lpad(8)));
range(1; d+1) as $d | "Degree \($d): \( pp(range(1; n+1) | multifactorial($d)) )";</langsyntaxhighlight>
The specific task:
<syntaxhighlight lang ="jq">table(5; 10)</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">$ jq -n -r -f Multifactorial.jq
Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Degree 2: 1 2 3 8 15 48 105 384 945 3840
Degree 3: 1 1 3 4 5 18 28 40 162 280
Degree 4: 1 1 1 4 5 6 7 32 45 60
Degree 5: 1 1 1 1 5 6 7 8 9 50</langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Printf
 
function multifact(n::Integer, k::Integer)
Line 1,213 ⟶ 1,383:
lab = "n" * "!" ^ k
@printf(" %-6s → %s\n", lab, a)
end</langsyntaxhighlight>
 
{{out}}
Line 1,224 ⟶ 1,394:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">fun multifactorial(n: Long, d: Int) : Long {
val r = n % d
return (1..n).filter { it % d == r } .reduce { i, p -> i * p }
Line 1,237 ⟶ 1,407:
println()
}
}</langsyntaxhighlight>
{{Out}}
<pre> !: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,246 ⟶ 1,416:
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang="scheme">
{def multifact
{lambda {:n :deg}
Line 1,264 ⟶ 1,434:
Degree 4: 1 2 3 4 5 12 21 32 45 120
Degree 5: 1 2 3 4 5 6 14 24 36 50
</syntaxhighlight>
</lang>
 
=={{header|Latitude}}==
 
<langsyntaxhighlight lang="latitude">use 'format importAllSigils.
 
multiFactorial := {
Line 1,278 ⟶ 1,448:
answers := 1 upto 11 to (Array) map { multiFactorial ($1, degree). }.
$stdout printf: ~fmt "Degree ~S: ~S", degree, answers.
}.</langsyntaxhighlight>
 
{{Out}}
Line 1,288 ⟶ 1,458:
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">function multiFact (n, degree)
local fact = 1
for i = n, 2, -degree do
Line 1,304 ⟶ 1,474:
end
print()
end</langsyntaxhighlight>
{{out}}
<pre>Degree | Multifactorials 1 to 10
Line 1,316 ⟶ 1,486:
=={{header|MAD}}==
 
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(N,DEG)
Line 1,331 ⟶ 1,501:
VECTOR VALUES OUTP = $5(I10,S1)*$
END OF PROGRAM</langsyntaxhighlight>
 
{{out}}
Line 1,348 ⟶ 1,518:
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">f := proc (n, m)
{{output?|Maple}}
<lang Maple>
f := proc (n, m)
local fac, i;
fac := 1;
Line 1,365 ⟶ 1,533:
end do;
end do;
a;</syntaxhighlight>
a;
{{out}}
</lang>
[1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 , 3628800]
[ ]
[1 , 2 , 3 , 8 , 15 , 48 , 105 , 384 , 945 , 3840]
[ ]
[1 , 2 , 3 , 4 , 10 , 18 , 28 , 80 , 162 , 280]
[ ]
[1 , 2 , 3 , 4 , 5 , 12 , 21 , 32 , 45 , 120]
[ ]
[1 , 2 , 3 , 4 , 5 , 6 , 14 , 24 , 36 , 50]
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang="mathematica">Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}]
Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm</langsyntaxhighlight>
{{out}}
<pre>1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,377 ⟶ 1,554:
4: 1 2 3 4 5 12 21 32 45 120
5: 1 2 3 4 5 6 14 24 36 50</pre>
 
=={{header|Maxima}}==
Using built-in function genfact
<syntaxhighlight lang="maxima">
multifactorial(x,n):=genfact(x,x/n,n)$
 
/* Test case */
makelist(multifactorial(i,1),i,1,10);
makelist(multifactorial(i,2),i,1,10);
block(makelist(mod(i,3),i,1,10),at(%%,0=1),%%*makelist(multifactorial(i,3),i,1,10));
block(makelist(mod(i,4),i,1,10),at(%%,0=1),%%*makelist(multifactorial(i,4),i,1,10));
block(makelist(mod(i,5),i,1,10),at(%%,0=1),%%*makelist(multifactorial(i,5),i,1,10));
</syntaxhighlight>
{{out}}
<pre>
[1,2,6,24,120,720,5040,40320,362880,3628800]
[1,2,3,8,15,48,105,384,945,3840]
[1,2,3,4,10,18,28,80,162,280]
[1,2,3,4,5,12,21,32,45,120]
[1,2,3,4,5,6,14,24,36,50]
</pre>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<langsyntaxhighlight lang="min">(:d (dup 0 <=) (pop 1) (dup d -) (*) linrec) :multifactorial
(:d 1 (dup d multifactorial print! " " print! succ) 10 times newline pop) :row
 
1 (dup "Degree " print! print ": " print! row succ) 5 times</langsyntaxhighlight>
{{out}}
<pre>
Line 1,392 ⟶ 1,590:
Degree 5: 1 2 3 4 5 6 14 24 36 50
</pre>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">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</syntaxhighlight>
{{out}}
<pre>1: [1,2,6,24,120,720,5040,40320,362880,3628800]
2: [1,2,3,8,15,48,105,384,945,3840]
3: [1,2,3,4,10,18,28,80,162,280]
4: [1,2,3,4,5,12,21,32,45,120]
5: [1,2,3,4,5,6,14,24,36,50]</pre>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">П1 <-> П0 П2 ИП0 ИП1 1 + - x>=0
23 ИП2 ИП0 ИП1 - * П2 ИП0 ИП1 -
П1 БП 04 ИП2 С/П</langsyntaxhighlight>
 
Instruction: ''number'' ^ ''degree'' В/О С/П
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim"># Recursive
proc multifact(n, deg: int): int =
result = (if n <= deg: n else: n * multifact(n - deg, deg))
Line 1,417 ⟶ 1,630:
for j in 1..10:
stdout.write multifactI(j, i), " "
stdout.write('\n')</langsyntaxhighlight>
 
{{out}}
Line 1,428 ⟶ 1,641:
=={{header|Objeck}}==
{{trans|C}}
<langsyntaxhighlight lang="objeck">
class Multifact {
function : MultiFact(n : Int, deg : Int) ~ Int {
Line 1,450 ⟶ 1,663:
}
}
</syntaxhighlight>
</lang>
 
Output:
Line 1,459 ⟶ 1,672:
Degree 4: 1 2 3 4 5 12 21 32 45 120
Degree 5: 1 2 3 4 5 6 14 24 36 50
</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let multi_fac d n =
let rec loop a x = if x < 2 then a else loop (a * x) (x - d) in
loop n (n - d)
 
let () =
for i = 1 to 5 do
Seq.(ints 1 |> take 10 |> map (multi_fac i) |> map string_of_int)
|> List.of_seq |> String.concat " " |> print_endline
done</syntaxhighlight>
{{out}}
<pre>
1 2 6 24 120 720 5040 40320 362880 3628800
1 2 3 8 15 48 105 384 945 3840
1 2 3 4 10 18 28 80 162 280
1 2 3 4 5 12 21 32 45 120
1 2 3 4 5 6 14 24 36 50
</pre>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">: multifact(n, deg) 1 while( n 0 > ) [ n * n deg - ->n ] ;
: printMulti
| i |
5 loop: i [ System.Out i << " : " << 10 seq map(#[ i multifact]) << cr ] ;</langsyntaxhighlight>
 
{{out}}
Line 1,476 ⟶ 1,708:
4 : [1, 2, 3, 4, 5, 12, 21, 32, 45, 120]
5 : [1, 2, 3, 4, 5, 6, 14, 24, 36, 50]
</pre>
 
=={{header|Ol}}==
<syntaxhighlight lang="scheme">
(define (multifactorial n d)
(fold * 1 (iota (div n d) n (negate d))))
 
(for-each (lambda (i)
(display "Degree ")
(display i)
(display ":")
(for-each (lambda (n)
(display " ")
(display (multifactorial n i)))
(iota 10 1))
(print))
(iota 5 1))
</syntaxhighlight>
{{out}}
<pre>
Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Degree 2: 1 2 3 8 15 48 105 384 945 3840
Degree 3: 1 1 3 4 5 18 28 40 162 280
Degree 4: 1 1 1 4 5 6 7 32 45 60
Degree 5: 1 1 1 1 5 6 7 8 9 50
</pre>
 
By the way, we can create few multifactorial functions and use them directly or as part of infix math notation (inside "//" macro).
<syntaxhighlight lang="scheme">
(define (!!!!! n) (multifactorial n 5))
(print (!!!!! 74))
 
(import (math infix-notation))
; register !!!!! as a postfix function
(define \\postfix-functions (put \\postfix-functions '!!!!! #t))
 
; now use "\\" as usual
(print (\\
2 + 74!!!!!
))
</syntaxhighlight>
{{out}}
<pre>
4959435223298761261056
4959435223298761261058
</pre>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">fac(n,d)=prod(k=0,(n-1)\d,n-k*d)
for(k=1,5,for(n=1,10,print1(fac(n,k)" "));print)</langsyntaxhighlight>
<pre>1 2 6 24 120 720 5040 40320 362880 3628800
1 2 3 8 15 48 105 384 945 3840
Line 1,488 ⟶ 1,765:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">{ # <-- scoping the cache and bigint clause
my @cache;
use bigint;
Line 1,501 ⟶ 1,778:
print "step=$s: ";
print join(" ", map(mfact($s, $_), 1 .. 10)), "\n";
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,518 ⟶ 1,795:
We can also do this iteratively. ntheory's vecprod makes bigint products if needed, so we don't have to worry about it.
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use ntheory qw/vecprod/;
 
sub mfac {
Line 1,527 ⟶ 1,804:
for my $degree (1..5) {
say "$degree: ",join(" ",map{mfac($_,$degree)} 1..10);
}</langsyntaxhighlight>
{{out}}
<pre>1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,536 ⟶ 1,813:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>function multifactorial(integer n, integer order)
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
atom res = 1
<span style="color: #008080;">function</span> <span style="color: #000000;">multifactorial</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">order</span><span style="color: #0000FF;">)</span>
if n>0 then
<span style="color: #004080;">atom</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
res = n*multifactorial(n-order,order)
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
end if
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">*</span><span style="color: #000000;">multifactorial</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">order</span><span style="color: #0000FF;">,</span><span style="color: #000000;">order</span><span style="color: #0000FF;">)</span>
return res
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end function
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
sequence s = repeat(0,10)
for i=1 to 5 do
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
for j=1 to 10 do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">5</span> <span style="color: #008080;">do</span>
s[j] = multifactorial(j,i)
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
end for
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">multifactorial</span><span style="color: #0000FF;">(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
?s
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end for</lang>
<span style="color: #7060A8;">pp</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,559 ⟶ 1,839:
{1,2,3,4,5,6,14,24,36,50}
</pre>
 
=={{header|Picat}}==
===Using prod/1===
<syntaxhighlight lang="picat">multifactorial(N,Degree) = prod([ I : I in N..-Degree..1]).</syntaxhighlight>
 
===Using reduce/2===
<syntaxhighlight lang="picat">multifactorial2(N,Degree) = reduce(*, [I : I in N..-Degree..1]).</syntaxhighlight>
 
===While loop===
<syntaxhighlight lang="picat">multifactorial3(N,Degree) = M =>
M = 1, I = N,
while(I > 0)
M := M*I,
I := I - Degree
end.</syntaxhighlight>
 
===Recursive variants===
<syntaxhighlight lang="picat">multifactorial4(N,_D) = 1, N <= 0 => true.</syntaxhighlight>
<syntaxhighlight lang="picat">multifactorial4(N,D) = N*multifactorial4(N-D,D).</syntaxhighlight>
<syntaxhighlight lang="picat">multifactorial5(N,D) = M =>
N <= 0 -> M = 1 ; M = N*multifactorial4(N-D,D).</syntaxhighlight>
<syntaxhighlight lang="picat">multifactorial6(N,D) = cond(N <= 0, 1, N*multifactorial6(N-D,D)).</syntaxhighlight>
 
===Test===
<syntaxhighlight lang="picat">import util.
 
go =>
foreach(D in 1..15)
println(D=[multifactorial(I,D) : I in 1..15])
end,
nl.</syntaxhighlight>
 
{{out}}
<pre>1 = [1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368000]
2 = [1,2,3,8,15,48,105,384,945,3840,10395,46080,135135,645120,2027025]
3 = [1,2,3,4,10,18,28,80,162,280,880,1944,3640,12320,29160]
4 = [1,2,3,4,5,12,21,32,45,120,231,384,585,1680,3465]
5 = [1,2,3,4,5,6,14,24,36,50,66,168,312,504,750]
6 = [1,2,3,4,5,6,7,16,27,40,55,72,91,224,405]
7 = [1,2,3,4,5,6,7,8,18,30,44,60,78,98,120]
8 = [1,2,3,4,5,6,7,8,9,20,33,48,65,84,105]
9 = [1,2,3,4,5,6,7,8,9,10,22,36,52,70,90]
10 = [1,2,3,4,5,6,7,8,9,10,11,24,39,56,75]
11 = [1,2,3,4,5,6,7,8,9,10,11,12,26,42,60]
12 = [1,2,3,4,5,6,7,8,9,10,11,12,13,28,45]
13 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,30]
14 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
15 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]</pre>
 
===Constraint modelling===
Using constraint modelling for a reversible variant (i.e. all parameters can be inputs or outputs); here shown by identifying all the valid N and the degree given the multifactorial (M).
<syntaxhighlight lang="picat">import cp.
 
%
% Reversible: find Degree and N given M
%
go2 =>
Ms = [4,20,105], % The multifactorials to identify
 
foreach(M in Ms)
println(m=M),
Degree :: 1..10, % limit of the degree
N :: 1..100, % limit of N
All = findall([N,Degree,M], (multifactorial_reversible(N,Degree,M),
solve([M,N,Degree]))),
foreach([NN,DD,MM] in All.sort)
printf("n=%d degree=%d m=%d\n",NN,DD,MM)
end,
nl
end,
nl.
 
% reversible variant (using CP)
multifactorial_reversible(N,_D,M) :-
N #<= 0, M #= 1.
multifactorial_reversible(N,D,M) :-
D #> 0,
N #> 0,
ND #= N-D,
multifactorial_reversible(ND,D,M1),
M #= N*M1.</syntaxhighlight>
 
{{out}}
<pre>Reversible: find Degree and N given M:
m = 4
n=4 degree=3 m=4
n=4 degree=4 m=4
n=4 degree=5 m=4
n=4 degree=6 m=4
n=4 degree=7 m=4
n=4 degree=8 m=4
n=4 degree=9 m=4
n=4 degree=10 m=4
 
m = 20
n=10 degree=8 m=20
 
m = 105
n=7 degree=2 m=105
n=15 degree=8 m=105</pre>
 
=={{header|PicoLisp}}==
{{trans|C}}
<langsyntaxhighlight PicoLisplang="picolisp">(de multifact (N Deg)
(let Res N
(while (> N Deg)
Line 1,572 ⟶ 1,952:
(for J 10
(prin " " (multifact J I)) )
(prinl) )</langsyntaxhighlight>
Output:
<pre>Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,581 ⟶ 1,961:
 
=={{header|PL/I}}==
<syntaxhighlight lang="text">
multi: procedure options (main); /* 29 October 2013 */
declare (i, j, n) fixed binary;
Line 1,603 ⟶ 1,983:
 
end multi;
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,616 ⟶ 1,996:
Works with an etex engine.
 
<langsyntaxhighlight TeXlang="tex">\long\def\antefi#1#2\fi{#2\fi#1}
\def\fornum#1=#2to#3(#4){%
\edef#1{\number\numexpr#2}\edef\fornumtemp{\noexpand\fornumi\expandafter\noexpand\csname fornum\string#1\endcsname
Line 1,629 ⟶ 2,009:
}
\fornum\degree=1 to 5(+1){Degree \degree: \fornum\ii=1 to 10(+1){\multifact\ii\degree\space\space}\par}
\bye</langsyntaxhighlight>
 
Output pdf looks like:
Line 1,640 ⟶ 2,020:
=={{header|Python}}==
===Python: Iterative===
<langsyntaxhighlight lang="python">>>> from functools import reduce
>>> from operator import mul
>>> def mfac(n, m): return reduce(mul, range(n, 0, -m))
Line 1,656 ⟶ 2,036:
9: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
10: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> </langsyntaxhighlight>
 
===Python: Recursive===
<langsyntaxhighlight lang="python">>>> def mfac2(n, m): return n if n <= (m + 1) else n * mfac2(n - m, m)
 
>>> for m in range(1, 6): print("%2i: %r" % (m, [mfac2(n, m) for n in range(1, 11)]))
Line 1,668 ⟶ 2,048:
4: [1, 2, 3, 4, 5, 12, 21, 32, 45, 120]
5: [1, 2, 3, 4, 5, 6, 14, 24, 36, 50]
>>> </langsyntaxhighlight>
 
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ 1 rot times
[ i 1+ *
dip [ over step ] ]
Line 1,681 ⟶ 2,061:
[ i^ 1+ over m!
echo sp ]
drop cr ]</langsyntaxhighlight>
 
{{Out}}
Line 1,693 ⟶ 2,073:
=={{header|R}}==
===Recursive solution===
<langsyntaxhighlight lang="rsplus">#x is Input
#n is Factorial Number
multifactorial=function(x,n){
Line 1,701 ⟶ 2,081:
return(x*multifactorial(x-n,n))
}
}</langsyntaxhighlight>
===Sequence solution===
This task doesn't use big enough numbers to need efficient code, so R can solve this very succinctly.
<langsyntaxhighlight lang="rsplus">mFact <- function(n, deg) prod(seq(from = n, to = 1, by = -deg))
cat("Simple version:\n")
print(outer(1:10, 1:5, Vectorize(mFact)))</langsyntaxhighlight>
If we really insist on a pretty table, then we can add some names and transpose the output.
<langsyntaxhighlight lang="rsplus">mFact <- function(n, deg) prod(seq(from = n, to = 1, by = -deg))
cat("Pretty version:\n")
print(t(outer(setNames(1:10, 1:10), setNames(1:5, paste0("Degree ", 1:5, ":")), Vectorize(mFact))))</langsyntaxhighlight>
{{out}}
<pre>Simple version:
Line 1,733 ⟶ 2,113:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
 
(define (multi-factorial-fn m)
Line 1,750 ⟶ 2,130:
(for/list ([m (in-range 1 (add1 5))])
(for/list ([n (in-range 1 (add1 10))])
(multi-factorial m n)))</langsyntaxhighlight>
Output:
<pre>'((1 2 6 24 120 720 5040 40320 362880 3628800)
Line 1,765 ⟶ 2,145:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>for 1 .. 5 -> $degree {
sub mfact($n) { [*] $n, *-$degree ...^ * <= 0 };
say "$degree: ", map &mfact, 1..10
}</langsyntaxhighlight>
{{out}}
<pre>1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,778 ⟶ 2,158:
=={{header|REXX}}==
This version also handles zero as well as positive integers.
<langsyntaxhighlight lang="rexx">/*REXX program calculates and displays K-fact (multifactorial) of non-negative integers.*/
numeric digits 1000 /*get ka-razy with the decimal digits. */
parse arg num deg . /*get optional arguments from the C.L. */
Line 1,795 ⟶ 2,175:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Kfact: procedure; !=1; do j=arg(1) to 2 by -word(arg(2) 1,1); !=!*j; end; return !</langsyntaxhighlight>
'''output''' &nbsp; when using the default input:
<pre>
Line 1,813 ⟶ 2,193:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "Degree " + "|" + " Multifactorials 1 to 10" + nl
see copy("-", 52) + nl
Line 1,830 ⟶ 2,210:
next
return fact
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,840 ⟶ 2,220:
4 | 1 2 3 4 5 12 21 32 45 120
5 | 1 2 3 4 5 6 14 24 36 50
</pre>
 
=={{header|RPL}}==
Recursivity is the simplest way to implement the task in RPL.
{{works with|Halcyon Calc|4.2.7}}
===Recursive===
≪ IF DUP2 > THEN DUP2 - SWAP NFACT * ELSE DROP END ≫
'NFACT' STO
===Iterative===
≪ OVER
WHILE DUP2 < REPEAT OVER - DUP 4 ROLL * ROT ROT END
DROP2
'NFACT' STO
 
≪ 1 5 FOR p
{ } 1 10 FOR n
n p NFACT +
NEXT NEXT
≫ EVAL
{{out}}
<pre>
5: { 1 2 6 24 120 720 5040 40320 362880 3628800 }
4: { 1 2 3 8 15 48 105 384 945 3840 }
3: { 1 2 3 4 10 18 28 80 162 280 }
2: { 1 2 3 4 5 12 21 32 45 120 }
1: { 1 2 3 4 5 6 14 24 36 50 }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">def multifact(n, d)
n.step(1, -d).inject( :* )
end
 
(1..5).each {|d| puts "Degree #{d}: #{(1..10).map{|n| multifact(n, d)}.join "\t"}"}</langsyntaxhighlight>
'''output'''
<pre style="overflow:scroll">
Line 1,857 ⟶ 2,264:
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">
print "Degree " + "|" + " Multifactorials 1 to 10" + nl
print copy("-", 52) + nl
Line 1,874 ⟶ 2,281:
next
multiFact = fact
end function</langsyntaxhighlight>
<pre>Degree | Multifactorials 1 to 10
--------|---------------------------------------------
Line 1,885 ⟶ 2,292:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">fn multifactorial(n: i32, deg: i32) -> i32 {
if n < 1 {
1
Line 1,900 ⟶ 2,307:
println!("");
}
}</langsyntaxhighlight>
<pre>
1 2 6 24 120 720 5040 40320 362880 3628800
Line 1,910 ⟶ 2,317:
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">
def multiFact(n : BigInt, degree : BigInt) = (n to 1 by -degree).product
 
Line 1,917 ⟶ 2,324:
str = (1 to 10).map(n => multiFact(n, degree)).mkString(" ")
} println(s"Degree $degree: $str")
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,928 ⟶ 2,335:
=={{header|Scheme}}==
 
<langsyntaxhighlight lang="scheme">
(import (scheme base)
(scheme write)
Line 1,948 ⟶ 2,355:
(newline))
(iota 5 1))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,960 ⟶ 2,367:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func integer: multiFact (in var integer: num, in integer: degree) is func
Line 1,984 ⟶ 2,391:
writeln;
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 1,994 ⟶ 2,401:
Degree 5: 1 2 3 4 5 6 14 24 36 50
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program multifactorial;
loop for d in [1..5] do
print(d, ":", [multifac(n, d) : n in [1..10]]);
end loop;
 
proc multifac(n, d);
return */{n, (n-d)..1};
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>1 : [1 2 6 24 120 720 5040 40320 362880 3628800]
2 : [1 2 3 8 15 48 105 384 945 3840]
3 : [1 2 3 4 10 18 28 80 162 280]
4 : [1 2 3 4 5 12 21 32 45 120]
5 : [1 2 3 4 5 6 14 24 36 50]</pre>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func mfact(s, n) {
n > 0 ? (n * mfact(s, n-s)) : 1
}
Line 2,002 ⟶ 2,426:
{ |s|
say "step=#{s}: #{{|n| mfact(s, n)}.map(1..10).join(' ')}"
} << 1..10</langsyntaxhighlight>
{{out}}
<pre>
Line 2,019 ⟶ 2,443:
=={{header|Swift}}==
 
<langsyntaxhighlight lang="swift">func multiFactorial(_ n: Int, k: Int) -> Int {
return stride(from: n, to: 0, by: -k).reduce(1, *)
}
Line 2,031 ⟶ 2,455:
for (i, degree) in multis.enumerated() {
print("Degree \(i + 1): \(degree)")
}</langsyntaxhighlight>
 
{{out}}
Line 2,042 ⟶ 2,466:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.6
 
proc mfact {n m} {
Line 2,052 ⟶ 2,476:
foreach n {1 2 3 4 5 6 7 8 9 10} {
puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,]
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,069 ⟶ 2,493:
=={{header|uBasic/4tH}}==
{{Trans|Run BASIC}}
<syntaxhighlight lang="text">print "Degree | Multifactorials 1 to 10"
for x = 1 to 53 : print "-"; : next : print
for d = 1 to 5
Line 2,087 ⟶ 2,511:
c@ = c@ * d@
next
return (c@)</langsyntaxhighlight>
{{Out}}
<pre>Degree | Multifactorials 1 to 10
Line 2,100 ⟶ 2,524:
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Function multifactorial(n,d)
If n = 0 Then
Line 2,126 ⟶ 2,550:
WScript.StdOut.WriteLine
Next
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,138 ⟶ 2,562:
 
=={{header|Wortel}}==
<langsyntaxhighlight lang="wortel">@let {
facd &[d n]?{<= n d n @prod@range[n 1 @-d]}
; tacit implementation
Line 2,147 ⟶ 2,571:
l @to 10
~@each @to 5 &n !console.log "Degree {n}: {@join @s !*\facd n l}"
}</langsyntaxhighlight>
Output
<pre>Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Line 2,157 ⟶ 2,581:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
 
var mf = Fn.new { |n, d|
Line 2,172 ⟶ 2,596:
for (n in 1..10) System.write(Fmt.d(8, mf.call(n, d)))
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 2,184 ⟶ 2,608:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code ChOut=8, CrLf=9, IntOut=11;
 
func MultiFac(N, D); \Return multifactorial of N in degree D
Line 2,201 ⟶ 2,625:
[IntOut(0, MultiFac(I, J)); ChOut(0, 9\tab\)];
CrLf(0);
]</langsyntaxhighlight>
 
{{out}}
Line 2,213 ⟶ 2,637:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn mfact(n,m){ [n..1,-m].reduce('*,1) }
foreach m in ([1..5]){ println("%d: %s".fmt(m,[1..10].apply(mfact.fp1(m)))) }</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits