WeixiangYan/CodeTransOcean huggingface dataset:
Task: Hailstone sequence








VB: Private Function hailstone(ByVal n As Long) As Collection
    Dim s As New Collection
    s.Add CStr(n), CStr(n)
    i = 0
    Do While n <> 1
        If n Mod 2 = 0 Then
            n = n / 2
        Else
            n = 3 * n + 1
        End If
        s.Add CStr(n), CStr(n)
    Loop
    Set hailstone = s
End Function
 
Private Function hailstone_count(ByVal n As Long)
    Dim count As Long: count = 1
    Do While n <> 1
        If n Mod 2 = 0 Then
            n = n / 2
        Else
            n = 3 * n + 1
        End If
        count = count + 1
    Loop
    hailstone_count = count
End Function
 
Public Sub rosetta()
    Dim s As Collection, i As Long
    Set s = hailstone(27)
    Dim ls As Integer: ls = s.count
    Debug.Print "hailstone(27) = ";
    For i = 1 To 4
        Debug.Print s(i); ", ";
    Next i
    Debug.Print "... ";
    For i = s.count - 4 To s.count - 1
        Debug.Print s(i); ", ";
    Next i
    Debug.Print s(s.count)
    Debug.Print "length ="; ls
    Dim hmax As Long: hmax = 1
    Dim imax As Long: imax = 1
    Dim count As Integer
    For i = 2 To 100000# - 1
        count = hailstone_count(i)
        If count > hmax Then
            hmax = count
            imax = i
        End If
    Next i
    Debug.Print "The longest hailstone sequence under 100,000 is"; imax; "with"; hmax; "elements."
End Sub



Fortran: program Hailstone
  implicit none

  integer :: i, maxn
  integer :: maxseqlen = 0, seqlen
  integer, allocatable :: seq(:)

  call hs(27, seqlen)
  allocate(seq(seqlen))
  call hs(27, seqlen, seq)
  write(*,"(a,i0,a)") "Hailstone sequence for 27 has ", seqlen, " elements"
  write(*,"(a,4(i0,a),3(i0,a),i0)") "Sequence = ", seq(1), ", ", seq(2), ", ", seq(3), ", ", seq(4), " ...., ",  &
                                     seq(seqlen-3), ", ", seq(seqlen-2), ", ", seq(seqlen-1), ", ", seq(seqlen) 
  
  do i = 1, 99999
    call hs(i, seqlen)
    if (seqlen > maxseqlen) then
      maxseqlen = seqlen
      maxn = i
    end if
  end do
  write(*,*)
  write(*,"(a,i0,a,i0,a)") "Longest sequence under 100000 is for ", maxn, " with ", maxseqlen, " elements"

  deallocate(seq)
  
contains

subroutine hs(number, length, seqArray)
  integer, intent(in)  :: number
  integer, intent(out) :: length  
  integer, optional, intent(inout) :: seqArray(:)
  integer :: n

  n = number
  length = 1
  if(present(seqArray)) seqArray(1) = n
  do while(n /= 1)
    if(mod(n,2) == 0) then
      n = n / 2
    else
      n = n * 3 + 1
    end if
    length = length + 1
    if(present(seqArray)) seqArray(length) = n
  end do
end subroutine

end program
Task: Hailstone sequence






PHP: function hailstone($n,$seq=array()){
	$sequence = $seq;
	$sequence[] = $n;
	if($n == 1){
		return $sequence;
	}else{
		$n = ($n%2==0) ? $n/2 : (3*$n)+1;
		return hailstone($n, $sequence);
	}
}

$result = hailstone(27);
echo count($result) . ' Elements.<br>';
echo 'Starting with : ' . implode(",",array_slice($result,0,4)) .' and ending with : ' . implode(",",array_slice($result,count($result)-4)) . '<br>';

$maxResult = array(0);

for($i=1;$i<=100000;$i++){
		$result = count(hailstone($i));
		if($result > max($maxResult)){
			$maxResult = array($i=>$result);
		}
}
foreach($maxResult as $key => $val){
echo 'Number < 100000 with longest Hailstone seq.: ' . $key . ' with length of ' . $val;
}





Fortran: program Hailstone
  implicit none

  integer :: i, maxn
  integer :: maxseqlen = 0, seqlen
  integer, allocatable :: seq(:)

  call hs(27, seqlen)
  allocate(seq(seqlen))
  call hs(27, seqlen, seq)
  write(*,"(a,i0,a)") "Hailstone sequence for 27 has ", seqlen, " elements"
  write(*,"(a,4(i0,a),3(i0,a),i0)") "Sequence = ", seq(1), ", ", seq(2), ", ", seq(3), ", ", seq(4), " ...., ",  &
                                     seq(seqlen-3), ", ", seq(seqlen-2), ", ", seq(seqlen-1), ", ", seq(seqlen) 
  
  do i = 1, 99999
    call hs(i, seqlen)
    if (seqlen > maxseqlen) then
      maxseqlen = seqlen
      maxn = i
    end if
  end do
  write(*,*)
  write(*,"(a,i0,a,i0,a)") "Longest sequence under 100000 is for ", maxn, " with ", maxseqlen, " elements"

  deallocate(seq)
  
contains

subroutine hs(number, length, seqArray)
  integer, intent(in)  :: number
  integer, intent(out) :: length  
  integer, optional, intent(inout) :: seqArray(:)
  integer :: n

  n = number
  length = 1
  if(present(seqArray)) seqArray(1) = n
  do while(n /= 1)
    if(mod(n,2) == 0) then
      n = n / 2
    else
      n = n * 3 + 1
    end if
    length = length + 1
    if(present(seqArray)) seqArray(length) = n
  end do
end subroutine

end program
Task: Hailstone sequence






PHP: function hailstone($n,$seq=array()){
	$sequence = $seq;
	$sequence[] = $n;
	if($n == 1){
		return $sequence;
	}else{
		$n = ($n%2==0) ? $n/2 : (3*$n)+1;
		return hailstone($n, $sequence);
	}
}

$result = hailstone(27);
echo count($result) . ' Elements.<br>';
echo 'Starting with : ' . implode(",",array_slice($result,0,4)) .' and ending with : ' . implode(",",array_slice($result,count($result)-4)) . '<br>';

$maxResult = array(0);

for($i=1;$i<=100000;$i++){
		$result = count(hailstone($i));
		if($result > max($maxResult)){
			$maxResult = array($i=>$result);
		}
}
foreach($maxResult as $key => $val){
echo 'Number < 100000 with longest Hailstone seq.: ' . $key . ' with length of ' . $val;
}
Task: Hailstone sequence






PHP: function hailstone($n,$seq=array()){
	$sequence = $seq;
	$sequence[] = $n;
	if($n == 1){
		return $sequence;
	}else{
		$n = ($n%2==0) ? $n/2 : (3*$n)+1;
		return hailstone($n, $sequence);
	}
}

$result = hailstone(27);
echo count($result) . ' Elements.<br>';
echo 'Starting with : ' . implode(",",array_slice($result,0,4)) .' and ending with : ' . implode(",",array_slice($result,count($result)-4)) . '<br>';

$maxResult = array(0);

for($i=1;$i<=100000;$i++){
		$result = count(hailstone($i));
		if($result > max($maxResult)){
			$maxResult = array($i=>$result);
		}
}
foreach($maxResult as $key => $val){
echo 'Number < 100000 with longest Hailstone seq.: ' . $key . ' with length of ' . $val;
}






Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
	type int_arr is array(Positive range <>) of Integer;
	type int_arr_pt is access all int_arr;

	function hailstones(num:Integer; pt:int_arr_pt) return Integer is
		stones : Integer := 1;
		n : Integer := num;
		begin
		if pt /= null then pt(1) := num; end if;
		while (n/=1) loop
			stones := stones + 1;
			if n mod 2 = 0 then n := n/2;
			else n := (3*n)+1;
			end if;
			if pt /= null then pt(stones) := n; end if;
		end loop;
		return stones;
	end hailstones;
	
	nmax,stonemax,stones : Integer := 0;
	list : int_arr_pt;
begin
	stones := hailstones(27,null);
	list := new int_arr(1..stones);
	stones := hailstones(27,list);
	put(" 27: "&Integer'Image(stones)); new_line;
	for n in 1..4 loop put(Integer'Image(list(n)));	end loop;
	put(" .... ");
	for n in stones-3..stones loop put(Integer'Image(list(n))); end loop;
	new_line;
	for n in 1..100000 loop
		stones := hailstones(n,null);
		if stones>stonemax then
			nmax := n; stonemax := stones;
		end if;
	end loop;
	put_line(Integer'Image(nmax)&" max @ n= "&Integer'Image(stonemax));
end hailstone;
Task: Multifactorial



C#: namespace RosettaCode.Multifactorial
{
    using System;
    using System.Linq;

    internal static class Program
    {
        private static void Main()
        {
            Console.WriteLine(string.Join(Environment.NewLine,
                                          Enumerable.Range(1, 5)
                                                    .Select(
                                                        degree =>
                                                        string.Join(" ",
                                                                    Enumerable.Range(1, 10)
                                                                              .Select(
                                                                                  number =>
                                                                                  Multifactorial(number, degree))))));
        }

        private static int Multifactorial(int number, int degree)
        {
            if (degree < 1)
            {
                throw new ArgumentOutOfRangeException("degree");
            }

            var count = 1 + (number - 1) / degree;
            if (count < 1)
            {
                throw new ArgumentOutOfRangeException("number");
            }

            return Enumerable.Range(0, count)
                             .Aggregate(1, (accumulator, index) => accumulator * (number - degree * index));
        }
    }
}









Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is

   function MultiFact (num : Natural; deg : Positive) return Natural is
      Result, N : Integer := num;
   begin
      if N = 0 then return 1; end if;
      loop
         N := N - deg; exit when N <= 0; Result := Result * N;
      end loop; return Result;
   end MultiFact;

begin
   for deg in 1..5 loop
      Put("Degree"& Integer'Image(deg) &":");
      for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
      New_line;
   end loop;
end Mfact;
Task: Multifactorial

C: 
#include <stdio.h>
#define HIGHEST_DEGREE 5
#define LARGEST_NUMBER 10


int multifact(int n, int deg){
   return n <= deg ? n : n * multifact(n - deg, deg);
}


int multifact_i(int n, int deg){
   int result = n;
   while (n >= deg + 1){
      result *= (n - deg);
      n -= deg;
   }
   return result;
}


int main(void){
   int i, j;
   for (i = 1; i <= HIGHEST_DEGREE; i++){
      printf("\nDegree %d: ", i);
      for (j = 1; j <= LARGEST_NUMBER; j++){
         printf("%d ", multifact(j, i));
      }
   }
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is

   function MultiFact (num : Natural; deg : Positive) return Natural is
      Result, N : Integer := num;
   begin
      if N = 0 then return 1; end if;
      loop
         N := N - deg; exit when N <= 0; Result := Result * N;
      end loop; return Result;
   end MultiFact;

begin
   for deg in 1..5 loop
      Put("Degree"& Integer'Image(deg) &":");
      for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
      New_line;
   end loop;
end Mfact;
Task: Multifactorial


C++: #include <algorithm>
#include <iostream>
#include <iterator>

int main(void) {
   for (int g = 1; g < 10; g++) {
     int v[11], n=0;
     generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;});
     std::cout << std::endl;
   }
   return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is

   function MultiFact (num : Natural; deg : Positive) return Natural is
      Result, N : Integer := num;
   begin
      if N = 0 then return 1; end if;
      loop
         N := N - deg; exit when N <= 0; Result := Result * N;
      end loop; return Result;
   end MultiFact;

begin
   for deg in 1..5 loop
      Put("Degree"& Integer'Image(deg) &":");
      for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
      New_line;
   end loop;
end Mfact;
Task: Multifactorial




Go: package main

import "fmt"

func multiFactorial(n, k int) int {
    r := 1
    for ; n > 1; n -= k {
        r *= n
    }
    return r
}

func main() {
    for k := 1; k <= 5; k++ {
        fmt.Print("degree ", k, ":")
        for n := 1; n <= 10; n++ {
            fmt.Print(" ", multiFactorial(n, k))
        }
        fmt.Println()
    }
}








Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is

   function MultiFact (num : Natural; deg : Positive) return Natural is
      Result, N : Integer := num;
   begin
      if N = 0 then return 1; end if;
      loop
         N := N - deg; exit when N <= 0; Result := Result * N;
      end loop; return Result;
   end MultiFact;

begin
   for deg in 1..5 loop
      Put("Degree"& Integer'Image(deg) &":");
      for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
      New_line;
   end loop;
end Mfact;
Task: Multifactorial





Java: public class MultiFact {
	private static long multiFact(long n, int deg){
		long ans = 1;
		for(long i = n; i > 0; i -= deg){
			ans *= i;
		}
		return ans;
	}
	
	public static void main(String[] args){
		for(int deg = 1; deg <= 5; deg++){
			System.out.print("degree " + deg + ":");
			for(long n = 1; n <= 10; n++){
				System.out.print(" " + multiFact(n, deg));
			}
			System.out.println();
		}
	}
}







Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is

   function MultiFact (num : Natural; deg : Positive) return Natural is
      Result, N : Integer := num;
   begin
      if N = 0 then return 1; end if;
      loop
         N := N - deg; exit when N <= 0; Result := Result * N;
      end loop; return Result;
   end MultiFact;

begin
   for deg in 1..5 loop
      Put("Degree"& Integer'Image(deg) &":");
      for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
      New_line;
   end loop;
end Mfact;
Task: Multifactorial







Python: >>> from functools import reduce
>>> from operator import mul
>>> def mfac(n, m): return reduce(mul, range(n, 0, -m))

>>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)]))

 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]
 6: [1, 2, 3, 4, 5, 6, 7, 16, 27, 40]
 7: [1, 2, 3, 4, 5, 6, 7, 8, 18, 30]
 8: [1, 2, 3, 4, 5, 6, 7, 8, 9, 20]
 9: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
10: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>>





Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is

   function MultiFact (num : Natural; deg : Positive) return Natural is
      Result, N : Integer := num;
   begin
      if N = 0 then return 1; end if;
      loop
         N := N - deg; exit when N <= 0; Result := Result * N;
      end loop; return Result;
   end MultiFact;

begin
   for deg in 1..5 loop
      Put("Degree"& Integer'Image(deg) &":");
      for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
      New_line;
   end loop;
end Mfact;
Task: Multifactorial








VB: Function multifactorial(n,d)
	If n = 0 Then
		multifactorial = 1
	Else
		For i = n To 1 Step -d
			If i = n Then
				multifactorial = n
			Else
				multifactorial = multifactorial * i
			End If
		Next
	End If
End Function

For j = 1 To 5
	WScript.StdOut.Write "Degree " & j & ": "
	For k = 1 To 10
		If k = 10 Then
			WScript.StdOut.Write multifactorial(k,j)
		Else
			WScript.StdOut.Write multifactorial(k,j) & " "
		End If
	Next
	WScript.StdOut.WriteLine
Next




Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is

   function MultiFact (num : Natural; deg : Positive) return Natural is
      Result, N : Integer := num;
   begin
      if N = 0 then return 1; end if;
      loop
         N := N - deg; exit when N <= 0; Result := Result * N;
      end loop; return Result;
   end MultiFact;

begin
   for deg in 1..5 loop
      Put("Degree"& Integer'Image(deg) &":");
      for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
      New_line;
   end loop;
end Mfact;
Task: Multifactorial

C: 
#include <stdio.h>
#define HIGHEST_DEGREE 5
#define LARGEST_NUMBER 10


int multifact(int n, int deg){
   return n <= deg ? n : n * multifact(n - deg, deg);
}


int multifact_i(int n, int deg){
   int result = n;
   while (n >= deg + 1){
      result *= (n - deg);
      n -= deg;
   }
   return result;
}


int main(void){
   int i, j;
   for (i = 1; i <= HIGHEST_DEGREE; i++){
      printf("\nDegree %d: ", i);
      for (j = 1; j <= LARGEST_NUMBER; j++){
         printf("%d ", multifact(j, i));
      }
   }
}
Task: Multifactorial



C#: namespace RosettaCode.Multifactorial
{
    using System;
    using System.Linq;

    internal static class Program
    {
        private static void Main()
        {
            Console.WriteLine(string.Join(Environment.NewLine,
                                          Enumerable.Range(1, 5)
                                                    .Select(
                                                        degree =>
                                                        string.Join(" ",
                                                                    Enumerable.Range(1, 10)
                                                                              .Select(
                                                                                  number =>
                                                                                  Multifactorial(number, degree))))));
        }

        private static int Multifactorial(int number, int degree)
        {
            if (degree < 1)
            {
                throw new ArgumentOutOfRangeException("degree");
            }

            var count = 1 + (number - 1) / degree;
            if (count < 1)
            {
                throw new ArgumentOutOfRangeException("number");
            }

            return Enumerable.Range(0, count)
                             .Aggregate(1, (accumulator, index) => accumulator * (number - degree * index));
        }
    }
}
Task: Multifactorial


C++: #include <algorithm>
#include <iostream>
#include <iterator>

int main(void) {
   for (int g = 1; g < 10; g++) {
     int v[11], n=0;
     generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;});
     std::cout << std::endl;
   }
   return 0;
}
Task: Multifactorial





Java: public class MultiFact {
	private static long multiFact(long n, int deg){
		long ans = 1;
		for(long i = n; i > 0; i -= deg){
			ans *= i;
		}
		return ans;
	}
	
	public static void main(String[] args){
		for(int deg = 1; deg <= 5; deg++){
			System.out.print("degree " + deg + ":");
			for(long n = 1; n <= 10; n++){
				System.out.print(" " + multiFact(n, deg));
			}
			System.out.println();
		}
	}
}
Task: Multifactorial







Python: >>> from functools import reduce
>>> from operator import mul
>>> def mfac(n, m): return reduce(mul, range(n, 0, -m))

>>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)]))

 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]
 6: [1, 2, 3, 4, 5, 6, 7, 16, 27, 40]
 7: [1, 2, 3, 4, 5, 6, 7, 8, 18, 30]
 8: [1, 2, 3, 4, 5, 6, 7, 8, 9, 20]
 9: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
10: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>>
Task: Multifactorial








VB: Function multifactorial(n,d)
	If n = 0 Then
		multifactorial = 1
	Else
		For i = n To 1 Step -d
			If i = n Then
				multifactorial = n
			Else
				multifactorial = multifactorial * i
			End If
		Next
	End If
End Function

For j = 1 To 5
	WScript.StdOut.Write "Degree " & j & ": "
	For k = 1 To 10
		If k = 10 Then
			WScript.StdOut.Write multifactorial(k,j)
		Else
			WScript.StdOut.Write multifactorial(k,j) & " "
		End If
	Next
	WScript.StdOut.WriteLine
Next
Task: Multifactorial




Go: package main

import "fmt"

func multiFactorial(n, k int) int {
    r := 1
    for ; n > 1; n -= k {
        r *= n
    }
    return r
}

func main() {
    for k := 1; k <= 5; k++ {
        fmt.Print("degree ", k, ":")
        for n := 1; n <= 10; n++ {
            fmt.Print(" ", multiFactorial(n, k))
        }
        fmt.Println()
    }
}
Task: Multifactorial



C#: namespace RosettaCode.Multifactorial
{
    using System;
    using System.Linq;

    internal static class Program
    {
        private static void Main()
        {
            Console.WriteLine(string.Join(Environment.NewLine,
                                          Enumerable.Range(1, 5)
                                                    .Select(
                                                        degree =>
                                                        string.Join(" ",
                                                                    Enumerable.Range(1, 10)
                                                                              .Select(
                                                                                  number =>
                                                                                  Multifactorial(number, degree))))));
        }

        private static int Multifactorial(int number, int degree)
        {
            if (degree < 1)
            {
                throw new ArgumentOutOfRangeException("degree");
            }

            var count = 1 + (number - 1) / degree;
            if (count < 1)
            {
                throw new ArgumentOutOfRangeException("number");
            }

            return Enumerable.Range(0, count)
                             .Aggregate(1, (accumulator, index) => accumulator * (number - degree * index));
        }
    }
}








Fortran: program test
  implicit none
  integer :: i, j, n

  do i = 1, 5
    write(*, "(a, i0, a)", advance = "no") "Degree ", i, ": "
    do j = 1, 10
      n = multifactorial(j, i)
      write(*, "(i0, 1x)", advance = "no") n
    end do
    write(*,*)
  end do
   
contains

function multifactorial (range, degree)
  integer :: multifactorial, range, degree
  integer :: k
   
  multifactorial = product((/(k, k=range, 1, -degree)/))

end function multifactorial
end program test
Task: Multifactorial


C++: #include <algorithm>
#include <iostream>
#include <iterator>

int main(void) {
   for (int g = 1; g < 10; g++) {
     int v[11], n=0;
     generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;});
     std::cout << std::endl;
   }
   return 0;
}









Fortran: program test
  implicit none
  integer :: i, j, n

  do i = 1, 5
    write(*, "(a, i0, a)", advance = "no") "Degree ", i, ": "
    do j = 1, 10
      n = multifactorial(j, i)
      write(*, "(i0, 1x)", advance = "no") n
    end do
    write(*,*)
  end do
   
contains

function multifactorial (range, degree)
  integer :: multifactorial, range, degree
  integer :: k
   
  multifactorial = product((/(k, k=range, 1, -degree)/))

end function multifactorial
end program test
Task: Multifactorial

C: 
#include <stdio.h>
#define HIGHEST_DEGREE 5
#define LARGEST_NUMBER 10


int multifact(int n, int deg){
   return n <= deg ? n : n * multifact(n - deg, deg);
}


int multifact_i(int n, int deg){
   int result = n;
   while (n >= deg + 1){
      result *= (n - deg);
      n -= deg;
   }
   return result;
}


int main(void){
   int i, j;
   for (i = 1; i <= HIGHEST_DEGREE; i++){
      printf("\nDegree %d: ", i);
      for (j = 1; j <= LARGEST_NUMBER; j++){
         printf("%d ", multifact(j, i));
      }
   }
}










Fortran: program test
  implicit none
  integer :: i, j, n

  do i = 1, 5
    write(*, "(a, i0, a)", advance = "no") "Degree ", i, ": "
    do j = 1, 10
      n = multifactorial(j, i)
      write(*, "(i0, 1x)", advance = "no") n
    end do
    write(*,*)
  end do
   
contains

function multifactorial (range, degree)
  integer :: multifactorial, range, degree
  integer :: k
   
  multifactorial = product((/(k, k=range, 1, -degree)/))

end function multifactorial
end program test
Task: Multifactorial





Java: public class MultiFact {
	private static long multiFact(long n, int deg){
		long ans = 1;
		for(long i = n; i > 0; i -= deg){
			ans *= i;
		}
		return ans;
	}
	
	public static void main(String[] args){
		for(int deg = 1; deg <= 5; deg++){
			System.out.print("degree " + deg + ":");
			for(long n = 1; n <= 10; n++){
				System.out.print(" " + multiFact(n, deg));
			}
			System.out.println();
		}
	}
}






Fortran: program test
  implicit none
  integer :: i, j, n

  do i = 1, 5
    write(*, "(a, i0, a)", advance = "no") "Degree ", i, ": "
    do j = 1, 10
      n = multifactorial(j, i)
      write(*, "(i0, 1x)", advance = "no") n
    end do
    write(*,*)
  end do
   
contains

function multifactorial (range, degree)
  integer :: multifactorial, range, degree
  integer :: k
   
  multifactorial = product((/(k, k=range, 1, -degree)/))

end function multifactorial
end program test