Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
T multifactorial(T=long)(in int n, in int m) /*pure*/ {
|
||||
T multifactorial(T=long)(in int n, in int m) pure /*nothrow*/ {
|
||||
T one = 1;
|
||||
return reduce!q{a * b}(one, iota(n, 0, -m));
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (m; 1 .. 11)
|
||||
foreach (immutable m; 1 .. 11)
|
||||
writefln("%2d: %s", m, iota(1, 11)
|
||||
.map!(n => multifactorial(n, m))());
|
||||
.map!(n => multifactorial(n, m)));
|
||||
}
|
||||
|
|
|
|||
21
Task/Multifactorial/GAP/multifactorial.gap
Normal file
21
Task/Multifactorial/GAP/multifactorial.gap
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MultiFactorial := function(n, k)
|
||||
local r;
|
||||
r := 1;
|
||||
while n > 1 do
|
||||
r := r*n;
|
||||
n := n - k;
|
||||
od;
|
||||
return r;
|
||||
end;
|
||||
|
||||
PrintArray(List([1 .. 10], n -> List([1 .. 5], k -> MultiFactorial(n, k))));
|
||||
[ [ 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 ] ]
|
||||
14
Task/Multifactorial/Haskell/multifactorial-2.hs
Normal file
14
Task/Multifactorial/Haskell/multifactorial-2.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
procedure main(A)
|
||||
l := integer(A[1]) | 10
|
||||
every writeRow(n := !l, [: mf(!10,n) :])
|
||||
end
|
||||
|
||||
procedure writeRow(n, r)
|
||||
writes(right(n,3),": ")
|
||||
every writes(right(!r,8)|"\n")
|
||||
end
|
||||
|
||||
procedure mf(n, m)
|
||||
if n <= 0 then return 1
|
||||
return n*mf(n-m, m)
|
||||
end
|
||||
21
Task/Multifactorial/PL-I/multifactorial.pli
Normal file
21
Task/Multifactorial/PL-I/multifactorial.pli
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
multi: procedure options (main); /* 29 October 2013 */
|
||||
declare (i, j, n) fixed binary;
|
||||
declare text character (6) static initial ('n!!!!!');
|
||||
|
||||
do i = 1 to 5;
|
||||
put skip edit (substr(text, 1, i+1), '=' ) (A, COLUMN(8));
|
||||
do n = 1 to 10;
|
||||
put edit ( trim( multifactorial(n,i) ) ) (X(1), A);
|
||||
end;
|
||||
end;
|
||||
|
||||
multifactorial: procedure (n, j) returns (fixed(15));
|
||||
declare (n, j) fixed binary;
|
||||
declare f fixed (15), m fixed(15);
|
||||
|
||||
f, m = n;
|
||||
do while (m > j); f = f * (m-fixed(j)); m = m - j; end;
|
||||
return (f);
|
||||
end multifactorial;
|
||||
|
||||
end multi;
|
||||
|
|
@ -1,20 +1,21 @@
|
|||
/*REXX pgm calculates K-fact (multifactorial) of non-negative integers.*/
|
||||
numeric digits 1000 /*lets get ka-razy with precision*/
|
||||
parse arg num deg . /*allow user to specify num & deg*/
|
||||
if num=='' | num==',' then num=12 /*Not specified? Then use default*/
|
||||
if deg=='' | deg==',' then deg=10 /* " " " " " */
|
||||
if num=='' | num==',' then num=15 /*Not specified? Then use default*/
|
||||
if deg=='' | deg==',' then deg=10 /* " " " " " */
|
||||
say '═══showing multiple factorials (1 ──►' deg") for numbers 1 ──►" num
|
||||
say
|
||||
do d=1 for deg /*the factorializing (º) of !'s. */
|
||||
_= /*the list of factorials so far. */
|
||||
do f=1 for num /* ◄── do a ! from 1 to num.*/
|
||||
_=_ Kfact(f,d) /*construct a list of factorials.*/
|
||||
end /*f*/ /*(above) D can default to 1.*/
|
||||
|
||||
do d=1 to deg /*the degree of factorialization.*/
|
||||
_= /*the list of factorials so far. */
|
||||
do f=1 to num
|
||||
_=_ Kfact(f,d) /*construct a list of factorials.*/
|
||||
end /*f*/ /*(above) D can be omitted. */
|
||||
|
||||
say 'degree' right(d,length(num))':' _ /*show factorials.*/
|
||||
end /*d*/
|
||||
say right('n'copies("!", d),1+deg) right('['d"]",2+length(num))':' _
|
||||
end /*d*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────KFACT subroutine────────────────────*/
|
||||
Kfact: procedure; !=1; do j=arg(1) to 2 by -word(arg(2) 1, 1)
|
||||
Kfact: procedure; !=1; do j=arg(1) to 2 by -word(arg(2) 1, 1)
|
||||
!=!*j
|
||||
end /*j*/
|
||||
return !
|
||||
|
|
|
|||
25
Task/Multifactorial/Seed7/multifactorial.seed7
Normal file
25
Task/Multifactorial/Seed7/multifactorial.seed7
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const func integer: multiFact (in var integer: num, in integer: degree) is func
|
||||
result
|
||||
var integer: multiFact is 1;
|
||||
begin
|
||||
while num > 1 do
|
||||
multiFact *:= num;
|
||||
num -:= degree;
|
||||
end while;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var integer: degree is 0;
|
||||
var integer: num is 0;
|
||||
begin
|
||||
for degree range 1 to 5 do
|
||||
write("Degree " <& degree <& ": ");
|
||||
for num range 1 to 10 do
|
||||
write(multiFact(num, degree) <& " ");
|
||||
end for;
|
||||
writeln;
|
||||
end for;
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue