Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Can you help me rewrite this code in C instead of F#, keeping it the same logically?
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
#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(vo...
Port the following code from F# to C# with equivalent syntax and logic.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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) ...
Maintain the same structure and functionality when rewriting this code in C#.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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) ...
Port the following code from F# to C++ with equivalent syntax and logic.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
#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; }
Ensure the translated C++ code behaves exactly like the original F# snippet.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
#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; }
Translate this program into Java but keep the logic exactly as in F#.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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++){ ...
Please provide an equivalent version of this F# code in Java.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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++){ ...
Write the same algorithm in Python as shown in this F# implementation.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
>>> 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,...
Maintain the same structure and functionality when rewriting this code in Python.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
>>> 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,...
Please provide an equivalent version of this F# code in VB.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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 WS...
Convert the following code from F# to VB, ensuring the logic remains intact.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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 WS...
Keep all operations the same but rewrite the snippet in Go.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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)) } ...
Keep all operations the same but rewrite the snippet in Go.
let rec mfact d = function | n when n <= d -> n | n -> n * mfact d (n-d) [<EntryPoint>] let main argv = let (|UInt|_|) = System.UInt32.TryParse >> function | true, v -> Some v | false, _ -> None let (maxDegree, maxN) = match argv with | [| UInt d; UInt n |] -> (int d, int n) ...
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)) } ...
Port the provided Fortran code into C# while preserving the original functionality.
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 :...
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) ...
Convert this Fortran block to C#, preserving its control flow and logic.
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 :...
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) ...
Produce a language-to-language conversion: from Fortran to C++, same semantics.
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 :...
#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; }
Generate an equivalent C++ version of this Fortran code.
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 :...
#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; }
Rewrite this program in C while keeping its functionality equivalent to the Fortran version.
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 :...
#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(vo...
Translate the given Fortran code snippet into C without altering its behavior.
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 :...
#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(vo...
Ensure the translated Java code behaves exactly like the original Fortran snippet.
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 :...
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++){ ...
Write the same algorithm in Java as shown in this Fortran implementation.
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 :...
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++){ ...
Rewrite this program in Python while keeping its functionality equivalent to the Fortran version.
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 :...
>>> 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,...
Convert this Fortran block to Python, preserving its control flow and logic.
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 :...
>>> 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,...
Rewrite this program in VB while keeping its functionality equivalent to the Fortran version.
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 :...
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 WS...
Convert this Fortran snippet to VB and keep its semantics consistent.
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 :...
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 WS...
Keep all operations the same but rewrite the snippet in C.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
#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(vo...
Produce a functionally identical C code for the snippet given in Haskell.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
#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(vo...
Write the same algorithm in C# as shown in this Haskell implementation.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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) ...
Can you help me rewrite this code in C# instead of Haskell, keeping it the same logically?
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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) ...
Produce a functionally identical C++ code for the snippet given in Haskell.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
#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; }
Generate an equivalent C++ version of this Haskell code.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
#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; }
Keep all operations the same but rewrite the snippet in Java.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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++){ ...
Rewrite the snippet below in Java so it works the same as the original Haskell code.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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++){ ...
Transform the following Haskell implementation into Python, maintaining the same output and logic.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
>>> 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,...
Port the provided Haskell code into Python while preserving the original functionality.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
>>> 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,...
Preserve the algorithm and functionality while converting the code from Haskell to VB.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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 WS...
Ensure the translated VB code behaves exactly like the original Haskell snippet.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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 WS...
Produce a functionally identical Go code for the snippet given in Haskell.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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)) } ...
Convert this Haskell snippet to Go and keep its semantics consistent.
mulfac :: (Num a, Enum a) => a -> [a] mulfac k = 1 : s where s = [1 .. k] <> zipWith (*) s [k + 1 ..] mulfac1 :: (Num a, Enum a) => a -> a -> a mulfac1 k n = product [n, n - k .. 1] main :: IO () main = mapM_ (print . take 10 . tail . mulfac) [1 .. 5]
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)) } ...
Rewrite this program in C while keeping its functionality equivalent to the J version.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
#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(vo...
Write the same algorithm in C as shown in this J implementation.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
#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(vo...
Generate an equivalent C# version of this J code.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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) ...
Please provide an equivalent version of this J code in C#.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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) ...
Change the programming language of this snippet from J to C++ without modifying what it does.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
#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; }
Generate a C++ translation of this J snippet without changing its computational steps.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
#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; }
Write the same algorithm in Java as shown in this J implementation.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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++){ ...
Produce a language-to-language conversion: from J to Java, same semantics.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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++){ ...
Produce a language-to-language conversion: from J to Python, same semantics.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
>>> 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,...
Keep all operations the same but rewrite the snippet in Python.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
>>> 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,...
Write the same algorithm in VB as shown in this J implementation.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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 WS...
Generate a VB translation of this J snippet without changing its computational steps.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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 WS...
Generate an equivalent Go version of this J code.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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)) } ...
Please provide an equivalent version of this J code in Go.
multifact=: */@([ - ] * i.@>.@%)&> ('';' degree'),multifact table >:i.10 ┌─────────┬──────────────────────────────────────┐ │ │ degree │ ├─────────┼──────────────────────────────────────┤ │multifact│ 1 2 3 4 5 6 7 8 9 10│ ├─────────┼────────────────...
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)) } ...
Rewrite this program in C while keeping its functionality equivalent to the Julia version.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
#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(vo...
Generate an equivalent C version of this Julia code.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
#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(vo...
Transform the following Julia implementation into C#, maintaining the same output and logic.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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) ...
Change the programming language of this snippet from Julia to C# without modifying what it does.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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) ...
Produce a functionally identical C++ code for the snippet given in Julia.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
#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; }
Convert this Julia block to C++, preserving its control flow and logic.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
#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; }
Translate this program into Java but keep the logic exactly as in Julia.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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++){ ...
Maintain the same structure and functionality when rewriting this code in Java.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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++){ ...
Produce a functionally identical Python code for the snippet given in Julia.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
>>> 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,...
Produce a language-to-language conversion: from Julia to Python, same semantics.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
>>> 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,...
Port the following code from Julia to VB with equivalent syntax and logic.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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 WS...
Rewrite this program in VB while keeping its functionality equivalent to the Julia version.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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 WS...
Maintain the same structure and functionality when rewriting this code in Go.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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)) } ...
Port the provided Julia code into Go while preserving the original functionality.
using Printf function multifact(n::Integer, k::Integer) n > 0 && k > 0 || throw(DomainError()) k > 1 || factorial(n) return prod(n:-k:2) end const khi = 5 const nhi = 10 println("Showing multifactorial for n in [1, $nhi] and k in [1, $khi].") for k = 1:khi a = multifact.(1:nhi, k) lab = "n" * "!" ...
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)) } ...
Convert this Lua block to C, preserving its control flow and logic.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
#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(vo...
Convert this Lua snippet to C and keep its semantics consistent.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
#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(vo...
Translate this program into C# but keep the logic exactly as in Lua.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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) ...
Ensure the translated C# code behaves exactly like the original Lua snippet.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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) ...
Write a version of this Lua function in C++ with identical behavior.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
#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; }
Convert the following code from Lua to C++, ensuring the logic remains intact.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
#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; }
Maintain the same structure and functionality when rewriting this code in Java.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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++){ ...
Keep all operations the same but rewrite the snippet in Java.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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++){ ...
Change the programming language of this snippet from Lua to Python without modifying what it does.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
>>> 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,...
Produce a language-to-language conversion: from Lua to Python, same semantics.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
>>> 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,...
Maintain the same structure and functionality when rewriting this code in VB.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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 WS...
Convert this Lua snippet to VB and keep its semantics consistent.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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 WS...
Produce a functionally identical Go code for the snippet given in Lua.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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)) } ...
Keep all operations the same but rewrite the snippet in Go.
function multiFact (n, degree) local fact = 1 for i = n, 2, -degree do fact = fact * i end return fact end print("Degree\t|\tMultifactorials 1 to 10") print(string.rep("-", 52)) for d = 1, 5 do io.write(" " .. d, "\t| ") for n = 1, 10 do io.write(multiFact(n, d) .. " ") end ...
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)) } ...
Generate a C translation of this Mathematica snippet without changing its computational steps.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
#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(vo...
Produce a functionally identical C code for the snippet given in Mathematica.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
#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(vo...
Write the same code in C# as shown below in Mathematica.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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) ...
Rewrite this program in C# while keeping its functionality equivalent to the Mathematica version.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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) ...
Ensure the translated C++ code behaves exactly like the original Mathematica snippet.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
#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; }
Keep all operations the same but rewrite the snippet in C++.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
#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; }
Write the same code in Java as shown below in Mathematica.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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++){ ...
Produce a language-to-language conversion: from Mathematica to Java, same semantics.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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++){ ...
Generate a Python translation of this Mathematica snippet without changing its computational steps.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
>>> 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,...
Please provide an equivalent version of this Mathematica code in Python.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
>>> 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,...
Write the same algorithm in VB as shown in this Mathematica implementation.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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 WS...
Transform the following Mathematica implementation into VB, maintaining the same output and logic.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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 WS...
Rewrite the snippet below in Go so it works the same as the original Mathematica code.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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)) } ...
Generate an equivalent Go version of this Mathematica code.
Multifactorial[n_, d_] := Product[x, {x, n, 1, -d}] Table[Multifactorial[j, i], {i, 5}, {j, 10}]//TableForm
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)) } ...
Change the following Nim code into C without altering its purpose.
proc multifact(n, deg: int): int = result = (if n <= deg: n else: n * multifact(n - deg, deg)) proc multifactI(n, deg: int): int = result = n var n = n while n >= deg + 1: result *= n - deg n -= deg for i in 1..5: stdout.write "Degree ", i, ": " for j in 1..10: stdout.write multifactI(j, i...
#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(vo...
Please provide an equivalent version of this Nim code in C.
proc multifact(n, deg: int): int = result = (if n <= deg: n else: n * multifact(n - deg, deg)) proc multifactI(n, deg: int): int = result = n var n = n while n >= deg + 1: result *= n - deg n -= deg for i in 1..5: stdout.write "Degree ", i, ": " for j in 1..10: stdout.write multifactI(j, i...
#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(vo...
Generate an equivalent C# version of this Nim code.
proc multifact(n, deg: int): int = result = (if n <= deg: n else: n * multifact(n - deg, deg)) proc multifactI(n, deg: int): int = result = n var n = n while n >= deg + 1: result *= n - deg n -= deg for i in 1..5: stdout.write "Degree ", i, ": " for j in 1..10: stdout.write multifactI(j, i...
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) ...
Please provide an equivalent version of this Nim code in C#.
proc multifact(n, deg: int): int = result = (if n <= deg: n else: n * multifact(n - deg, deg)) proc multifactI(n, deg: int): int = result = n var n = n while n >= deg + 1: result *= n - deg n -= deg for i in 1..5: stdout.write "Degree ", i, ": " for j in 1..10: stdout.write multifactI(j, i...
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) ...
Ensure the translated C++ code behaves exactly like the original Nim snippet.
proc multifact(n, deg: int): int = result = (if n <= deg: n else: n * multifact(n - deg, deg)) proc multifactI(n, deg: int): int = result = n var n = n while n >= deg + 1: result *= n - deg n -= deg for i in 1..5: stdout.write "Degree ", i, ": " for j in 1..10: stdout.write multifactI(j, i...
#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; }