Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,28 @@
PROGRAM MULTIFACTORIAL
PROCEDURE MULTI_FACT(NUM,DEG->MF)
RESULT=NUM
N=NUM
IF N=0 THEN
MF=1
EXIT PROCEDURE
END IF
LOOP
N-=DEG
EXIT IF N<=0
RESULT*=N
END LOOP
MF=RESULT
END PROCEDURE
BEGIN
PRINT(CHR$(12);)
FOR DEG=1 TO 10 DO
PRINT("Degree";DEG;":";)
FOR NUM=1 TO 10 DO
MULTI_FACT(NUM,DEG->MF)
PRINT(MF;)
END FOR
PRINT
END FOR
END PROGRAM

View file

@ -0,0 +1,22 @@
' FB 1.05.0 Win64
Function multiFactorial (n As UInteger, degree As Integer) As UInteger
If n < 2 Then Return 1
Var result = n
For i As Integer = n - degree To 2 Step -degree
result *= i
Next
Return result
End Function
For degree As Integer = 1 To 5
Print "Degree"; degree; " => ";
For n As Integer = 1 To 10
Print multiFactorial(n, degree); " ";
Next n
Print
Next degree
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,4 @@
def multifactorial( n, d ) = product( n..1 by -d )
for d <- 1..5
println( d, [multifactorial(i, d) | i <- 1..10] ))

View file

@ -0,0 +1,16 @@
# Recursive
proc multifact(n, deg): int =
result = (if n <= deg: n else: n * multifact(n - deg, deg))
# Iterative
proc multifactI(n, deg): int =
result = n
var n = n
while n >= deg + 1:
result *= n - deg
n -= deg
for i in 1..5:
stdout.write "\nDegree ", i, ": "
for j in 1..10:
stdout.write multifactI(j, i), " "

View file

@ -0,0 +1,5 @@
: 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 ] ;

View file

@ -0,0 +1,16 @@
see "Degree " + "|" + " Multifactorials 1 to 10" + nl
see copy("-", 52) + nl
for d = 1 to 5
see "" + d + " " + "| "
for n = 1 to 10
see "" + multiFact(n, d) + " "
next
see nl
next
func multiFact n, degree
fact = 1
for i = n to 2 step -degree
fact = fact * i
next
return fact

View file

@ -0,0 +1,7 @@
func mfact(s, n) {
n > 0 ? (n * mfact(s, n-s)) : 1
}
 
10.times { |s|
say "step=#{s}: #{1..10 -> map {|n| mfact(s, n)}.join(' ')}"
}

View file

@ -0,0 +1,10 @@
@let {
facd &[d n]?{<= n d n @prod@range[n 1 @-d]}
; tacit implementation
facdt ^(!?(/^> .1 ^(@prod @range ~1jdtShj &^!(@- @id))) @,)
; recursive
facdrec &[n d] ?{<= n d n *n !!facdrec -n d d}
; output
l @to 10
~@each @to 5 &n !console.log "Degree {n}: {@join @s !*\facd n l}"
}

View file

@ -0,0 +1,6 @@
# 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);

View file

@ -0,0 +1,6 @@
# 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)) )";

View file

@ -0,0 +1 @@
table(5; 10)

View file

@ -0,0 +1,6 @@
$ 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