Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Produce a functionally identical VB code for the snippet given in Haskell.
comb :: Int -> [a] -> [[a]] comb 0 _ = [[]] comb _ [] = [] comb m (x:xs) = map (x:) (comb (m-1) xs) ++ comb m xs
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Generate an equivalent Go version of this Haskell code.
comb :: Int -> [a] -> [[a]] comb 0 _ = [[]] comb _ [] = [] comb m (x:xs) = map (x:) (comb (m-1) xs) ++ comb m xs
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Port the provided Icon code into C while preserving the original functionality.
procedure main() return combinations(3,5,0) end procedure combinations(m,n,z) /z := 1 write(m," combinations of ",n," integers starting from ",z) every put(L := [], z to n - 1 + z by 1) write("Intial list\n",list2string(L)) write("Combinations:") every write(list2string(lcomb(L,m))) ...
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Generate an equivalent C# version of this Icon code.
procedure main() return combinations(3,5,0) end procedure combinations(m,n,z) /z := 1 write(m," combinations of ",n," integers starting from ",z) every put(L := [], z to n - 1 + z by 1) write("Intial list\n",list2string(L)) write("Combinations:") every write(list2string(lcomb(L,m))) ...
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Produce a functionally identical C++ code for the snippet given in Icon.
procedure main() return combinations(3,5,0) end procedure combinations(m,n,z) /z := 1 write(m," combinations of ",n," integers starting from ",z) every put(L := [], z to n - 1 + z by 1) write("Intial list\n",list2string(L)) write("Combinations:") every write(list2string(lcomb(L,m))) ...
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Translate the given Icon code snippet into Java without altering its behavior.
procedure main() return combinations(3,5,0) end procedure combinations(m,n,z) /z := 1 write(m," combinations of ",n," integers starting from ",z) every put(L := [], z to n - 1 + z by 1) write("Intial list\n",list2string(L)) write("Combinations:") every write(list2string(lcomb(L,m))) ...
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Transform the following Icon implementation into Python, maintaining the same output and logic.
procedure main() return combinations(3,5,0) end procedure combinations(m,n,z) /z := 1 write(m," combinations of ",n," integers starting from ",z) every put(L := [], z to n - 1 + z by 1) write("Intial list\n",list2string(L)) write("Combinations:") every write(list2string(lcomb(L,m))) ...
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Convert this Icon block to VB, preserving its control flow and logic.
procedure main() return combinations(3,5,0) end procedure combinations(m,n,z) /z := 1 write(m," combinations of ",n," integers starting from ",z) every put(L := [], z to n - 1 + z by 1) write("Intial list\n",list2string(L)) write("Combinations:") every write(list2string(lcomb(L,m))) ...
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Generate a Go translation of this Icon snippet without changing its computational steps.
procedure main() return combinations(3,5,0) end procedure combinations(m,n,z) /z := 1 write(m," combinations of ",n," integers starting from ",z) every put(L := [], z to n - 1 + z by 1) write("Intial list\n",list2string(L)) write("Combinations:") every write(list2string(lcomb(L,m))) ...
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Translate the given J code snippet into C without altering its behavior.
require'stats'
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Change the following J code into C# without altering its purpose.
require'stats'
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Convert the following code from J to C++, ensuring the logic remains intact.
require'stats'
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Write the same algorithm in Java as shown in this J implementation.
require'stats'
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Rewrite this program in Python while keeping its functionality equivalent to the J version.
require'stats'
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Preserve the algorithm and functionality while converting the code from J to VB.
require'stats'
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Convert this J snippet to Go and keep its semantics consistent.
require'stats'
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Generate a C translation of this Julia snippet without changing its computational steps.
using Combinatorics n = 4 m = 3 for i in combinations(0:n,m) println(i') end
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Port the provided Julia code into C# while preserving the original functionality.
using Combinatorics n = 4 m = 3 for i in combinations(0:n,m) println(i') end
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Convert this Julia snippet to C++ and keep its semantics consistent.
using Combinatorics n = 4 m = 3 for i in combinations(0:n,m) println(i') end
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Convert the following code from Julia to Java, ensuring the logic remains intact.
using Combinatorics n = 4 m = 3 for i in combinations(0:n,m) println(i') end
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Please provide an equivalent version of this Julia code in Python.
using Combinatorics n = 4 m = 3 for i in combinations(0:n,m) println(i') end
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Port the following code from Julia to VB with equivalent syntax and logic.
using Combinatorics n = 4 m = 3 for i in combinations(0:n,m) println(i') end
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Translate this program into Go but keep the logic exactly as in Julia.
using Combinatorics n = 4 m = 3 for i in combinations(0:n,m) println(i') end
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Write the same algorithm in C as shown in this Lua implementation.
function map(f, a, ...) if a then return f(a), map(f, ...) end end function incr(k) return function(a) return k > a and a or a+1 end end function combs(m, n) if m * n == 0 then return {{}} end local ret, old = {}, combs(m-1, n-1) for i = 1, n do for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack...
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Preserve the algorithm and functionality while converting the code from Lua to C#.
function map(f, a, ...) if a then return f(a), map(f, ...) end end function incr(k) return function(a) return k > a and a or a+1 end end function combs(m, n) if m * n == 0 then return {{}} end local ret, old = {}, combs(m-1, n-1) for i = 1, n do for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack...
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Rewrite this program in C++ while keeping its functionality equivalent to the Lua version.
function map(f, a, ...) if a then return f(a), map(f, ...) end end function incr(k) return function(a) return k > a and a or a+1 end end function combs(m, n) if m * n == 0 then return {{}} end local ret, old = {}, combs(m-1, n-1) for i = 1, n do for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack...
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Write the same code in Java as shown below in Lua.
function map(f, a, ...) if a then return f(a), map(f, ...) end end function incr(k) return function(a) return k > a and a or a+1 end end function combs(m, n) if m * n == 0 then return {{}} end local ret, old = {}, combs(m-1, n-1) for i = 1, n do for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack...
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Translate the given Lua code snippet into Python without altering its behavior.
function map(f, a, ...) if a then return f(a), map(f, ...) end end function incr(k) return function(a) return k > a and a or a+1 end end function combs(m, n) if m * n == 0 then return {{}} end local ret, old = {}, combs(m-1, n-1) for i = 1, n do for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack...
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Produce a language-to-language conversion: from Lua to VB, same semantics.
function map(f, a, ...) if a then return f(a), map(f, ...) end end function incr(k) return function(a) return k > a and a or a+1 end end function combs(m, n) if m * n == 0 then return {{}} end local ret, old = {}, combs(m-1, n-1) for i = 1, n do for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack...
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Write a version of this Lua function in Go with identical behavior.
function map(f, a, ...) if a then return f(a), map(f, ...) end end function incr(k) return function(a) return k > a and a or a+1 end end function combs(m, n) if m * n == 0 then return {{}} end local ret, old = {}, combs(m-1, n-1) for i = 1, n do for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack...
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Rewrite the snippet below in C so it works the same as the original Mathematica code.
combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Ensure the translated C# code behaves exactly like the original Mathematica snippet.
combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Maintain the same structure and functionality when rewriting this code in C++.
combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Ensure the translated Java code behaves exactly like the original Mathematica snippet.
combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Translate the given Mathematica code snippet into Python without altering its behavior.
combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Produce a functionally identical VB code for the snippet given in Mathematica.
combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Write the same algorithm in Go as shown in this Mathematica implementation.
combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Can you help me rewrite this code in C instead of MATLAB, keeping it the same logically?
>> nchoosek((0:4),3) ans = 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Produce a functionally identical C# code for the snippet given in MATLAB.
>> nchoosek((0:4),3) ans = 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Change the programming language of this snippet from MATLAB to C++ without modifying what it does.
>> nchoosek((0:4),3) ans = 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Port the provided MATLAB code into Java while preserving the original functionality.
>> nchoosek((0:4),3) ans = 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Convert this MATLAB block to Python, preserving its control flow and logic.
>> nchoosek((0:4),3) ans = 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Preserve the algorithm and functionality while converting the code from MATLAB to VB.
>> nchoosek((0:4),3) ans = 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Change the following MATLAB code into Go without altering its purpose.
>> nchoosek((0:4),3) ans = 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Convert this Nim block to C, preserving its control flow and logic.
iterator comb(m, n: int): seq[int] = var c = newSeq[int](n) for i in 0 ..< n: c[i] = i block outer: while true: yield c var i = n - 1 inc c[i] if c[i] <= m - 1: continue while c[i] >= m - n + i: dec i if i < 0: break outer inc c[i] while i < n-1: ...
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Write the same code in C# as shown below in Nim.
iterator comb(m, n: int): seq[int] = var c = newSeq[int](n) for i in 0 ..< n: c[i] = i block outer: while true: yield c var i = n - 1 inc c[i] if c[i] <= m - 1: continue while c[i] >= m - n + i: dec i if i < 0: break outer inc c[i] while i < n-1: ...
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Preserve the algorithm and functionality while converting the code from Nim to C++.
iterator comb(m, n: int): seq[int] = var c = newSeq[int](n) for i in 0 ..< n: c[i] = i block outer: while true: yield c var i = n - 1 inc c[i] if c[i] <= m - 1: continue while c[i] >= m - n + i: dec i if i < 0: break outer inc c[i] while i < n-1: ...
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Ensure the translated Java code behaves exactly like the original Nim snippet.
iterator comb(m, n: int): seq[int] = var c = newSeq[int](n) for i in 0 ..< n: c[i] = i block outer: while true: yield c var i = n - 1 inc c[i] if c[i] <= m - 1: continue while c[i] >= m - n + i: dec i if i < 0: break outer inc c[i] while i < n-1: ...
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Port the following code from Nim to Python with equivalent syntax and logic.
iterator comb(m, n: int): seq[int] = var c = newSeq[int](n) for i in 0 ..< n: c[i] = i block outer: while true: yield c var i = n - 1 inc c[i] if c[i] <= m - 1: continue while c[i] >= m - n + i: dec i if i < 0: break outer inc c[i] while i < n-1: ...
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Generate an equivalent VB version of this Nim code.
iterator comb(m, n: int): seq[int] = var c = newSeq[int](n) for i in 0 ..< n: c[i] = i block outer: while true: yield c var i = n - 1 inc c[i] if c[i] <= m - 1: continue while c[i] >= m - n + i: dec i if i < 0: break outer inc c[i] while i < n-1: ...
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Can you help me rewrite this code in Go instead of Nim, keeping it the same logically?
iterator comb(m, n: int): seq[int] = var c = newSeq[int](n) for i in 0 ..< n: c[i] = i block outer: while true: yield c var i = n - 1 inc c[i] if c[i] <= m - 1: continue while c[i] >= m - n + i: dec i if i < 0: break outer inc c[i] while i < n-1: ...
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Ensure the translated C code behaves exactly like the original OCaml snippet.
let combinations m n = let rec c = function | (0,_) -> [[]] | (_,0) -> [] | (p,q) -> List.append (List.map (List.cons (n-q)) (c (p-1, q-1))) (c (p , q-1)) in c (m , n) let () = let rec print_list = function | [] -> print_newline () | hd :: tl -> print_int hd ; p...
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Convert this OCaml block to C#, preserving its control flow and logic.
let combinations m n = let rec c = function | (0,_) -> [[]] | (_,0) -> [] | (p,q) -> List.append (List.map (List.cons (n-q)) (c (p-1, q-1))) (c (p , q-1)) in c (m , n) let () = let rec print_list = function | [] -> print_newline () | hd :: tl -> print_int hd ; p...
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Ensure the translated Java code behaves exactly like the original OCaml snippet.
let combinations m n = let rec c = function | (0,_) -> [[]] | (_,0) -> [] | (p,q) -> List.append (List.map (List.cons (n-q)) (c (p-1, q-1))) (c (p , q-1)) in c (m , n) let () = let rec print_list = function | [] -> print_newline () | hd :: tl -> print_int hd ; p...
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Change the following OCaml code into Python without altering its purpose.
let combinations m n = let rec c = function | (0,_) -> [[]] | (_,0) -> [] | (p,q) -> List.append (List.map (List.cons (n-q)) (c (p-1, q-1))) (c (p , q-1)) in c (m , n) let () = let rec print_list = function | [] -> print_newline () | hd :: tl -> print_int hd ; p...
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Keep all operations the same but rewrite the snippet in VB.
let combinations m n = let rec c = function | (0,_) -> [[]] | (_,0) -> [] | (p,q) -> List.append (List.map (List.cons (n-q)) (c (p-1, q-1))) (c (p , q-1)) in c (m , n) let () = let rec print_list = function | [] -> print_newline () | hd :: tl -> print_int hd ; p...
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Ensure the translated Go code behaves exactly like the original OCaml snippet.
let combinations m n = let rec c = function | (0,_) -> [[]] | (_,0) -> [] | (p,q) -> List.append (List.map (List.cons (n-q)) (c (p-1, q-1))) (c (p , q-1)) in c (m , n) let () = let rec print_list = function | [] -> print_newline () | hd :: tl -> print_int hd ; p...
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Please provide an equivalent version of this Pascal code in C.
Program Combinations; const m_max = 3; n_max = 5; var combination: array [0..m_max] of integer; procedure generate(m: integer); var n, i: integer; begin if (m > m_max) then begin for i := 1 to m_max do write (combination[i], ' '); writeln; end else for n := 1 to n_max do ...
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Rewrite this program in C# while keeping its functionality equivalent to the Pascal version.
Program Combinations; const m_max = 3; n_max = 5; var combination: array [0..m_max] of integer; procedure generate(m: integer); var n, i: integer; begin if (m > m_max) then begin for i := 1 to m_max do write (combination[i], ' '); writeln; end else for n := 1 to n_max do ...
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Rewrite the snippet below in C++ so it works the same as the original Pascal code.
Program Combinations; const m_max = 3; n_max = 5; var combination: array [0..m_max] of integer; procedure generate(m: integer); var n, i: integer; begin if (m > m_max) then begin for i := 1 to m_max do write (combination[i], ' '); writeln; end else for n := 1 to n_max do ...
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Convert this Pascal snippet to Java and keep its semantics consistent.
Program Combinations; const m_max = 3; n_max = 5; var combination: array [0..m_max] of integer; procedure generate(m: integer); var n, i: integer; begin if (m > m_max) then begin for i := 1 to m_max do write (combination[i], ' '); writeln; end else for n := 1 to n_max do ...
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Convert this Pascal snippet to Python and keep its semantics consistent.
Program Combinations; const m_max = 3; n_max = 5; var combination: array [0..m_max] of integer; procedure generate(m: integer); var n, i: integer; begin if (m > m_max) then begin for i := 1 to m_max do write (combination[i], ' '); writeln; end else for n := 1 to n_max do ...
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Preserve the algorithm and functionality while converting the code from Pascal to VB.
Program Combinations; const m_max = 3; n_max = 5; var combination: array [0..m_max] of integer; procedure generate(m: integer); var n, i: integer; begin if (m > m_max) then begin for i := 1 to m_max do write (combination[i], ' '); writeln; end else for n := 1 to n_max do ...
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Convert the following code from Pascal to Go, ensuring the logic remains intact.
Program Combinations; const m_max = 3; n_max = 5; var combination: array [0..m_max] of integer; procedure generate(m: integer); var n, i: integer; begin if (m > m_max) then begin for i := 1 to m_max do write (combination[i], ' '); writeln; end else for n := 1 to n_max do ...
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Change the following Perl code into C without altering its purpose.
use ntheory qw/forcomb/; forcomb { print "@_\n" } 5,3
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Generate a C# translation of this Perl snippet without changing its computational steps.
use ntheory qw/forcomb/; forcomb { print "@_\n" } 5,3
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Write the same algorithm in C++ as shown in this Perl implementation.
use ntheory qw/forcomb/; forcomb { print "@_\n" } 5,3
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Rewrite this program in Java while keeping its functionality equivalent to the Perl version.
use ntheory qw/forcomb/; forcomb { print "@_\n" } 5,3
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Preserve the algorithm and functionality while converting the code from Perl to Python.
use ntheory qw/forcomb/; forcomb { print "@_\n" } 5,3
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Port the provided Perl code into VB while preserving the original functionality.
use ntheory qw/forcomb/; forcomb { print "@_\n" } 5,3
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Maintain the same structure and functionality when rewriting this code in Go.
use ntheory qw/forcomb/; forcomb { print "@_\n" } 5,3
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Convert this PowerShell block to C, preserving its control flow and logic.
$source = @' using System; using System.Collections.Generic; namespace Powershell { public class CSharp { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>();...
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Please provide an equivalent version of this PowerShell code in C#.
$source = @' using System; using System.Collections.Generic; namespace Powershell { public class CSharp { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>();...
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Convert this PowerShell block to C++, preserving its control flow and logic.
$source = @' using System; using System.Collections.Generic; namespace Powershell { public class CSharp { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>();...
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Produce a functionally identical Java code for the snippet given in PowerShell.
$source = @' using System; using System.Collections.Generic; namespace Powershell { public class CSharp { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>();...
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Change the following PowerShell code into Python without altering its purpose.
$source = @' using System; using System.Collections.Generic; namespace Powershell { public class CSharp { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>();...
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Port the provided PowerShell code into VB while preserving the original functionality.
$source = @' using System; using System.Collections.Generic; namespace Powershell { public class CSharp { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>();...
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Transform the following PowerShell implementation into Go, maintaining the same output and logic.
$source = @' using System; using System.Collections.Generic; namespace Powershell { public class CSharp { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>();...
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Keep all operations the same but rewrite the snippet in C.
print(combn(0:4, 3))
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Generate a C# translation of this R snippet without changing its computational steps.
print(combn(0:4, 3))
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Keep all operations the same but rewrite the snippet in C++.
print(combn(0:4, 3))
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Translate this program into Java but keep the logic exactly as in R.
print(combn(0:4, 3))
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Translate the given R code snippet into Python without altering its behavior.
print(combn(0:4, 3))
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Ensure the translated VB code behaves exactly like the original R snippet.
print(combn(0:4, 3))
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Transform the following R implementation into Go, maintaining the same output and logic.
print(combn(0:4, 3))
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Translate the given Racket code snippet into C without altering its behavior.
(define sublists (match-lambda** [(0 _) '(())] [(_ '()) '()] [(m (cons x xs)) (append (map (curry cons x) (sublists (- m 1) xs)) (sublists m xs))])) (define (combinations n m) (sublists n (range m)))
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Generate an equivalent C# version of this Racket code.
(define sublists (match-lambda** [(0 _) '(())] [(_ '()) '()] [(m (cons x xs)) (append (map (curry cons x) (sublists (- m 1) xs)) (sublists m xs))])) (define (combinations n m) (sublists n (range m)))
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Port the provided Racket code into C++ while preserving the original functionality.
(define sublists (match-lambda** [(0 _) '(())] [(_ '()) '()] [(m (cons x xs)) (append (map (curry cons x) (sublists (- m 1) xs)) (sublists m xs))])) (define (combinations n m) (sublists n (range m)))
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Write the same code in Java as shown below in Racket.
(define sublists (match-lambda** [(0 _) '(())] [(_ '()) '()] [(m (cons x xs)) (append (map (curry cons x) (sublists (- m 1) xs)) (sublists m xs))])) (define (combinations n m) (sublists n (range m)))
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Maintain the same structure and functionality when rewriting this code in Python.
(define sublists (match-lambda** [(0 _) '(())] [(_ '()) '()] [(m (cons x xs)) (append (map (curry cons x) (sublists (- m 1) xs)) (sublists m xs))])) (define (combinations n m) (sublists n (range m)))
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Write the same code in VB as shown below in Racket.
(define sublists (match-lambda** [(0 _) '(())] [(_ '()) '()] [(m (cons x xs)) (append (map (curry cons x) (sublists (- m 1) xs)) (sublists m xs))])) (define (combinations n m) (sublists n (range m)))
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Port the provided Racket code into Go while preserving the original functionality.
(define sublists (match-lambda** [(0 _) '(())] [(_ '()) '()] [(m (cons x xs)) (append (map (curry cons x) (sublists (- m 1) xs)) (sublists m xs))])) (define (combinations n m) (sublists n (range m)))
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Change the following REXX code into C without altering its purpose.
parse arg x y $ . if x=='' | x=="," then x= 5 if y=='' | y=="," then y= 3; oy= y; y= abs(y) if $=='' | $=="," then $='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', "~!@#$%^&*()_+`{}|[]\:;<>?,./β–ˆβ”Œβ”β””β”˜Β±β‰₯β‰€β‰ˆβˆ™" ...
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...
Transform the following REXX implementation into C#, maintaining the same output and logic.
parse arg x y $ . if x=='' | x=="," then x= 5 if y=='' | y=="," then y= 3; oy= y; y= abs(y) if $=='' | $=="," then $='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', "~!@#$%^&*()_+`{}|[]\:;<>?,./β–ˆβ”Œβ”β””β”˜Β±β‰₯β‰€β‰ˆβˆ™" ...
using System; using System.Collections.Generic; public class Program { public static IEnumerable<int[]> Combinations(int m, int n) { int[] result = new int[m]; Stack<int> stack = new Stack<int>(); stack.Push(0); while (stack.Count > 0) { ...
Write a version of this REXX function in C++ with identical behavior.
parse arg x y $ . if x=='' | x=="," then x= 5 if y=='' | y=="," then y= 3; oy= y; y= abs(y) if $=='' | $=="," then $='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', "~!@#$%^&*()_+`{}|[]\:;<>?,./β–ˆβ”Œβ”β””β”˜Β±β‰₯β‰€β‰ˆβˆ™" ...
#include <algorithm> #include <iostream> #include <string> void comb(int N, int K) { std::string bitmask(K, 1); bitmask.resize(N, 0); do { for (int i = 0; i < N; ++i) { if (bitmask[i]) std::cout << " " << i; } std::cout << std::endl; } while (std::pr...
Rewrite this program in Java while keeping its functionality equivalent to the REXX version.
parse arg x y $ . if x=='' | x=="," then x= 5 if y=='' | y=="," then y= 3; oy= y; y= abs(y) if $=='' | $=="," then $='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', "~!@#$%^&*()_+`{}|[]\:;<>?,./β–ˆβ”Œβ”β””β”˜Β±β‰₯β‰€β‰ˆβˆ™" ...
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
Ensure the translated Python code behaves exactly like the original REXX snippet.
parse arg x y $ . if x=='' | x=="," then x= 5 if y=='' | y=="," then y= 3; oy= y; y= abs(y) if $=='' | $=="," then $='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', "~!@#$%^&*()_+`{}|[]\:;<>?,./β–ˆβ”Œβ”β””β”˜Β±β‰₯β‰€β‰ˆβˆ™" ...
>>> from itertools import combinations >>> list(combinations(range(5),3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
Produce a functionally identical VB code for the snippet given in REXX.
parse arg x y $ . if x=='' | x=="," then x= 5 if y=='' | y=="," then y= 3; oy= y; y= abs(y) if $=='' | $=="," then $='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', "~!@#$%^&*()_+`{}|[]\:;<>?,./β–ˆβ”Œβ”β””β”˜Β±β‰₯β‰€β‰ˆβˆ™" ...
input "Enter n comb m. ", n input m outstr$ = "" call iterate (outstr$, 0, m-1, n-1) end subroutine iterate (curr$, start, stp, depth) for i = start to stp if depth = 0 then print curr$ + " " + string(i) call iterate (curr$ + " " + string(i), i+1, stp, depth-1) next i end subroutine
Change the following REXX code into Go without altering its purpose.
parse arg x y $ . if x=='' | x=="," then x= 5 if y=='' | y=="," then y= 3; oy= y; y= abs(y) if $=='' | $=="," then $='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', "~!@#$%^&*()_+`{}|[]\:;<>?,./β–ˆβ”Œβ”β””β”˜Β±β‰₯β‰€β‰ˆβˆ™" ...
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
Write the same algorithm in C as shown in this Ruby implementation.
def comb(m, n) (0...n).to_a.each_combination(m) { |p| puts(p) } end
#include <stdio.h> typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf("%d ", at); printf("\n"); return; } comb(pool, need - 1, chosen | (one ...