Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Transform the following Clojure implementation into VB, maintaining the same output and logic. | (let [rows (Integer/parseInt (read-line))
cols (Integer/parseInt (read-line))
a (to-array-2d (repeat rows (repeat cols nil)))]
(aset a 0 0 12)
(println "Element at 0,0:" (aget a 0 0)))
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Produce a language-to-language conversion: from Clojure to Go, same semantics. | (let [rows (Integer/parseInt (read-line))
cols (Integer/parseInt (read-line))
a (to-array-2d (repeat rows (repeat cols nil)))]
(aset a 0 0 12)
(println "Element at 0,0:" (aget a 0 0)))
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Maintain the same structure and functionality when rewriting this code in C. | (let ((d1 (read))
(d2 (read)))
(assert (and (typep d1 '(integer 1))
(typep d2 '(integer 1)))
(d1 d2))
(let ((array (make-array (list d1 d2) :initial-element nil))
(p1 0)
(p2 (floor d2 2)))
(setf (aref array p1 p2) t)
(print (aref array p1 p2))))
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Keep all operations the same but rewrite the snippet in C#. | (let ((d1 (read))
(d2 (read)))
(assert (and (typep d1 '(integer 1))
(typep d2 '(integer 1)))
(d1 d2))
(let ((array (make-array (list d1 d2) :initial-element nil))
(p1 0)
(p2 (floor d2 2)))
(setf (aref array p1 p2) t)
(print (aref array p1 p2))))
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Port the following code from Common_Lisp to C++ with equivalent syntax and logic. | (let ((d1 (read))
(d2 (read)))
(assert (and (typep d1 '(integer 1))
(typep d2 '(integer 1)))
(d1 d2))
(let ((array (make-array (list d1 d2) :initial-element nil))
(p1 0)
(p2 (floor d2 2)))
(setf (aref array p1 p2) t)
(print (aref array p1 p2))))
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Generate a Java translation of this Common_Lisp snippet without changing its computational steps. | (let ((d1 (read))
(d2 (read)))
(assert (and (typep d1 '(integer 1))
(typep d2 '(integer 1)))
(d1 d2))
(let ((array (make-array (list d1 d2) :initial-element nil))
(p1 0)
(p2 (floor d2 2)))
(setf (aref array p1 p2) t)
(print (aref array p1 p2))))
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Maintain the same structure and functionality when rewriting this code in Python. | (let ((d1 (read))
(d2 (read)))
(assert (and (typep d1 '(integer 1))
(typep d2 '(integer 1)))
(d1 d2))
(let ((array (make-array (list d1 d2) :initial-element nil))
(p1 0)
(p2 (floor d2 2)))
(setf (aref array p1 p2) t)
(print (aref array p1 p2))))
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Preserve the algorithm and functionality while converting the code from Common_Lisp to VB. | (let ((d1 (read))
(d2 (read)))
(assert (and (typep d1 '(integer 1))
(typep d2 '(integer 1)))
(d1 d2))
(let ((array (make-array (list d1 d2) :initial-element nil))
(p1 0)
(p2 (floor d2 2)))
(setf (aref array p1 p2) t)
(print (aref array p1 p2))))
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Translate the given Common_Lisp code snippet into Go without altering its behavior. | (let ((d1 (read))
(d2 (read)))
(assert (and (typep d1 '(integer 1))
(typep d2 '(integer 1)))
(d1 d2))
(let ((array (make-array (list d1 d2) :initial-element nil))
(p1 0)
(p2 (floor d2 2)))
(setf (aref array p1 p2) t)
(print (aref array p1 p2))))
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Generate an equivalent C version of this D code. | void main() {
import std.stdio, std.conv, std.string;
int nRow, nCol;
write("Give me the numer of rows: ");
try {
nRow = readln.strip.to!int;
} catch (StdioException) {
nRow = 3;
writeln;
}
write("Give me the numer of columns: ");
try {
nCol = readln.strip.to!int;
} catch (StdioException) {
nCol = 5;
writeln;
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Convert this D snippet to C# and keep its semantics consistent. | void main() {
import std.stdio, std.conv, std.string;
int nRow, nCol;
write("Give me the numer of rows: ");
try {
nRow = readln.strip.to!int;
} catch (StdioException) {
nRow = 3;
writeln;
}
write("Give me the numer of columns: ");
try {
nCol = readln.strip.to!int;
} catch (StdioException) {
nCol = 5;
writeln;
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Produce a functionally identical C++ code for the snippet given in D. | void main() {
import std.stdio, std.conv, std.string;
int nRow, nCol;
write("Give me the numer of rows: ");
try {
nRow = readln.strip.to!int;
} catch (StdioException) {
nRow = 3;
writeln;
}
write("Give me the numer of columns: ");
try {
nCol = readln.strip.to!int;
} catch (StdioException) {
nCol = 5;
writeln;
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Produce a functionally identical Java code for the snippet given in D. | void main() {
import std.stdio, std.conv, std.string;
int nRow, nCol;
write("Give me the numer of rows: ");
try {
nRow = readln.strip.to!int;
} catch (StdioException) {
nRow = 3;
writeln;
}
write("Give me the numer of columns: ");
try {
nCol = readln.strip.to!int;
} catch (StdioException) {
nCol = 5;
writeln;
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Rewrite this program in Python while keeping its functionality equivalent to the D version. | void main() {
import std.stdio, std.conv, std.string;
int nRow, nCol;
write("Give me the numer of rows: ");
try {
nRow = readln.strip.to!int;
} catch (StdioException) {
nRow = 3;
writeln;
}
write("Give me the numer of columns: ");
try {
nCol = readln.strip.to!int;
} catch (StdioException) {
nCol = 5;
writeln;
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Generate an equivalent VB version of this D code. | void main() {
import std.stdio, std.conv, std.string;
int nRow, nCol;
write("Give me the numer of rows: ");
try {
nRow = readln.strip.to!int;
} catch (StdioException) {
nRow = 3;
writeln;
}
write("Give me the numer of columns: ");
try {
nCol = readln.strip.to!int;
} catch (StdioException) {
nCol = 5;
writeln;
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Produce a language-to-language conversion: from D to Go, same semantics. | void main() {
import std.stdio, std.conv, std.string;
int nRow, nCol;
write("Give me the numer of rows: ");
try {
nRow = readln.strip.to!int;
} catch (StdioException) {
nRow = 3;
writeln;
}
write("Give me the numer of columns: ");
try {
nCol = readln.strip.to!int;
} catch (StdioException) {
nCol = 5;
writeln;
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Translate this program into C but keep the logic exactly as in Delphi. | program Project1;
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
Finalize(matrix);
SetLength(matrix,Random(10) + 1);
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
Readln;
end.
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in C#. | program Project1;
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
Finalize(matrix);
SetLength(matrix,Random(10) + 1);
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
Readln;
end.
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Translate the given Delphi code snippet into C++ without altering its behavior. | program Project1;
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
Finalize(matrix);
SetLength(matrix,Random(10) + 1);
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
Readln;
end.
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Keep all operations the same but rewrite the snippet in Java. | program Project1;
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
Finalize(matrix);
SetLength(matrix,Random(10) + 1);
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
Readln;
end.
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Convert this Delphi snippet to Python and keep its semantics consistent. | program Project1;
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
Finalize(matrix);
SetLength(matrix,Random(10) + 1);
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
Readln;
end.
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Convert this Delphi snippet to VB and keep its semantics consistent. | program Project1;
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
Finalize(matrix);
SetLength(matrix,Random(10) + 1);
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
Readln;
end.
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Rewrite the snippet below in Go so it works the same as the original Delphi code. | program Project1;
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
Finalize(matrix);
SetLength(matrix,Random(10) + 1);
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
Readln;
end.
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Write a version of this Elixir function in C with identical behavior. | defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Generate an equivalent C# version of this Elixir code. | defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Generate a C++ translation of this Elixir snippet without changing its computational steps. | defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Change the following Elixir code into Java without altering its purpose. | defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Keep all operations the same but rewrite the snippet in Python. | defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Maintain the same structure and functionality when rewriting this code in VB. | defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Port the following code from Elixir to Go with equivalent syntax and logic. | defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Change the following Erlang code into C without altering its purpose. | -module( two_dimensional_array ).
-export( [create/2, get/3, set/4, task/0] ).
create( X, Y ) -> array:new( [{size, X}, {default, array:new( [{size, Y}] )}] ).
get( X, Y, Array ) -> array:get( Y, array:get(X, Array) ).
set( X, Y, Value, Array ) ->
Y_array = array:get( X, Array ),
New_y_array = array:set( Y, Value, Y_array ),
array:set( X, New_y_array, Array ).
task() ->
{ok, [X, Y]} = io:fread( "Input two integers. Space delimited, please: ", "~d ~d" ),
Array = create( X, Y ),
New_array = set( X - 1, Y - 1, X * Y, Array ),
io:fwrite( "In position ~p ~p we have ~p~n", [X - 1, Y - 1, get( X - 1, Y - 1, New_array)] ).
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Can you help me rewrite this code in C# instead of Erlang, keeping it the same logically? | -module( two_dimensional_array ).
-export( [create/2, get/3, set/4, task/0] ).
create( X, Y ) -> array:new( [{size, X}, {default, array:new( [{size, Y}] )}] ).
get( X, Y, Array ) -> array:get( Y, array:get(X, Array) ).
set( X, Y, Value, Array ) ->
Y_array = array:get( X, Array ),
New_y_array = array:set( Y, Value, Y_array ),
array:set( X, New_y_array, Array ).
task() ->
{ok, [X, Y]} = io:fread( "Input two integers. Space delimited, please: ", "~d ~d" ),
Array = create( X, Y ),
New_array = set( X - 1, Y - 1, X * Y, Array ),
io:fwrite( "In position ~p ~p we have ~p~n", [X - 1, Y - 1, get( X - 1, Y - 1, New_array)] ).
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Transform the following Erlang implementation into C++, maintaining the same output and logic. | -module( two_dimensional_array ).
-export( [create/2, get/3, set/4, task/0] ).
create( X, Y ) -> array:new( [{size, X}, {default, array:new( [{size, Y}] )}] ).
get( X, Y, Array ) -> array:get( Y, array:get(X, Array) ).
set( X, Y, Value, Array ) ->
Y_array = array:get( X, Array ),
New_y_array = array:set( Y, Value, Y_array ),
array:set( X, New_y_array, Array ).
task() ->
{ok, [X, Y]} = io:fread( "Input two integers. Space delimited, please: ", "~d ~d" ),
Array = create( X, Y ),
New_array = set( X - 1, Y - 1, X * Y, Array ),
io:fwrite( "In position ~p ~p we have ~p~n", [X - 1, Y - 1, get( X - 1, Y - 1, New_array)] ).
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Port the following code from Erlang to Java with equivalent syntax and logic. | -module( two_dimensional_array ).
-export( [create/2, get/3, set/4, task/0] ).
create( X, Y ) -> array:new( [{size, X}, {default, array:new( [{size, Y}] )}] ).
get( X, Y, Array ) -> array:get( Y, array:get(X, Array) ).
set( X, Y, Value, Array ) ->
Y_array = array:get( X, Array ),
New_y_array = array:set( Y, Value, Y_array ),
array:set( X, New_y_array, Array ).
task() ->
{ok, [X, Y]} = io:fread( "Input two integers. Space delimited, please: ", "~d ~d" ),
Array = create( X, Y ),
New_array = set( X - 1, Y - 1, X * Y, Array ),
io:fwrite( "In position ~p ~p we have ~p~n", [X - 1, Y - 1, get( X - 1, Y - 1, New_array)] ).
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Translate this program into Python but keep the logic exactly as in Erlang. | -module( two_dimensional_array ).
-export( [create/2, get/3, set/4, task/0] ).
create( X, Y ) -> array:new( [{size, X}, {default, array:new( [{size, Y}] )}] ).
get( X, Y, Array ) -> array:get( Y, array:get(X, Array) ).
set( X, Y, Value, Array ) ->
Y_array = array:get( X, Array ),
New_y_array = array:set( Y, Value, Y_array ),
array:set( X, New_y_array, Array ).
task() ->
{ok, [X, Y]} = io:fread( "Input two integers. Space delimited, please: ", "~d ~d" ),
Array = create( X, Y ),
New_array = set( X - 1, Y - 1, X * Y, Array ),
io:fwrite( "In position ~p ~p we have ~p~n", [X - 1, Y - 1, get( X - 1, Y - 1, New_array)] ).
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Change the programming language of this snippet from Erlang to VB without modifying what it does. | -module( two_dimensional_array ).
-export( [create/2, get/3, set/4, task/0] ).
create( X, Y ) -> array:new( [{size, X}, {default, array:new( [{size, Y}] )}] ).
get( X, Y, Array ) -> array:get( Y, array:get(X, Array) ).
set( X, Y, Value, Array ) ->
Y_array = array:get( X, Array ),
New_y_array = array:set( Y, Value, Y_array ),
array:set( X, New_y_array, Array ).
task() ->
{ok, [X, Y]} = io:fread( "Input two integers. Space delimited, please: ", "~d ~d" ),
Array = create( X, Y ),
New_array = set( X - 1, Y - 1, X * Y, Array ),
io:fwrite( "In position ~p ~p we have ~p~n", [X - 1, Y - 1, get( X - 1, Y - 1, New_array)] ).
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Produce a functionally identical Go code for the snippet given in Erlang. | -module( two_dimensional_array ).
-export( [create/2, get/3, set/4, task/0] ).
create( X, Y ) -> array:new( [{size, X}, {default, array:new( [{size, Y}] )}] ).
get( X, Y, Array ) -> array:get( Y, array:get(X, Array) ).
set( X, Y, Value, Array ) ->
Y_array = array:get( X, Array ),
New_y_array = array:set( Y, Value, Y_array ),
array:set( X, New_y_array, Array ).
task() ->
{ok, [X, Y]} = io:fread( "Input two integers. Space delimited, please: ", "~d ~d" ),
Array = create( X, Y ),
New_array = set( X - 1, Y - 1, X * Y, Array ),
io:fwrite( "In position ~p ~p we have ~p~n", [X - 1, Y - 1, get( X - 1, Y - 1, New_array)] ).
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Write the same algorithm in C as shown in this F# implementation. | open System
let width = int( Console.ReadLine() )
let height = int( Console.ReadLine() )
let arr = Array2D.create width height 0
arr.[0,0] <- 42
printfn "%d" arr.[0,0]
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Change the following F# code into C# without altering its purpose. | open System
let width = int( Console.ReadLine() )
let height = int( Console.ReadLine() )
let arr = Array2D.create width height 0
arr.[0,0] <- 42
printfn "%d" arr.[0,0]
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Please provide an equivalent version of this F# code in C++. | open System
let width = int( Console.ReadLine() )
let height = int( Console.ReadLine() )
let arr = Array2D.create width height 0
arr.[0,0] <- 42
printfn "%d" arr.[0,0]
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Convert this F# block to Java, preserving its control flow and logic. | open System
let width = int( Console.ReadLine() )
let height = int( Console.ReadLine() )
let arr = Array2D.create width height 0
arr.[0,0] <- 42
printfn "%d" arr.[0,0]
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Maintain the same structure and functionality when rewriting this code in Python. | open System
let width = int( Console.ReadLine() )
let height = int( Console.ReadLine() )
let arr = Array2D.create width height 0
arr.[0,0] <- 42
printfn "%d" arr.[0,0]
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Change the following F# code into VB without altering its purpose. | open System
let width = int( Console.ReadLine() )
let height = int( Console.ReadLine() )
let arr = Array2D.create width height 0
arr.[0,0] <- 42
printfn "%d" arr.[0,0]
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Rewrite the snippet below in Go so it works the same as the original F# code. | open System
let width = int( Console.ReadLine() )
let height = int( Console.ReadLine() )
let arr = Array2D.create width height 0
arr.[0,0] <- 42
printfn "%d" arr.[0,0]
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Convert this Factor block to C, preserving its control flow and logic. | USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray
: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt )
[ first2 swap ] dip nth nth ;
: example ( -- )
readln readln [ string>number ] bi@ zero-matrix
[ [ 42 { 0 0 } ] dip set-Mi,j ]
[ [ { 0 0 } ] dip Mi,j . ]
bi ;
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Produce a language-to-language conversion: from Factor to C#, same semantics. | USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray
: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt )
[ first2 swap ] dip nth nth ;
: example ( -- )
readln readln [ string>number ] bi@ zero-matrix
[ [ 42 { 0 0 } ] dip set-Mi,j ]
[ [ { 0 0 } ] dip Mi,j . ]
bi ;
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Change the programming language of this snippet from Factor to C++ without modifying what it does. | USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray
: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt )
[ first2 swap ] dip nth nth ;
: example ( -- )
readln readln [ string>number ] bi@ zero-matrix
[ [ 42 { 0 0 } ] dip set-Mi,j ]
[ [ { 0 0 } ] dip Mi,j . ]
bi ;
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Rewrite this program in Java while keeping its functionality equivalent to the Factor version. | USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray
: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt )
[ first2 swap ] dip nth nth ;
: example ( -- )
readln readln [ string>number ] bi@ zero-matrix
[ [ 42 { 0 0 } ] dip set-Mi,j ]
[ [ { 0 0 } ] dip Mi,j . ]
bi ;
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Produce a functionally identical Python code for the snippet given in Factor. | USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray
: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt )
[ first2 swap ] dip nth nth ;
: example ( -- )
readln readln [ string>number ] bi@ zero-matrix
[ [ 42 { 0 0 } ] dip set-Mi,j ]
[ [ { 0 0 } ] dip Mi,j . ]
bi ;
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Rewrite the snippet below in VB so it works the same as the original Factor code. | USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray
: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt )
[ first2 swap ] dip nth nth ;
: example ( -- )
readln readln [ string>number ] bi@ zero-matrix
[ [ 42 { 0 0 } ] dip set-Mi,j ]
[ [ { 0 0 } ] dip Mi,j . ]
bi ;
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Ensure the translated Go code behaves exactly like the original Factor snippet. | USING: io kernel math.matrices math.parser prettyprint
sequences ;
IN: rosettacode.runtime2darray
: set-Mi,j ( elt {i,j} matrix -- )
[ first2 swap ] dip nth set-nth ;
: Mi,j ( {i,j} matrix -- elt )
[ first2 swap ] dip nth nth ;
: example ( -- )
readln readln [ string>number ] bi@ zero-matrix
[ [ 42 { 0 0 } ] dip set-Mi,j ]
[ [ { 0 0 } ] dip Mi,j . ]
bi ;
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Convert this Forth snippet to C and keep its semantics consistent. | : cell-matrix
create over , * cells allot
does> dup cell+ >r @ * + cells r> + ;
5 5 cell-matrix test
36 0 0 test !
0 0 test @ .
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Write the same algorithm in C# as shown in this Forth implementation. | : cell-matrix
create over , * cells allot
does> dup cell+ >r @ * + cells r> + ;
5 5 cell-matrix test
36 0 0 test !
0 0 test @ .
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Keep all operations the same but rewrite the snippet in C++. | : cell-matrix
create over , * cells allot
does> dup cell+ >r @ * + cells r> + ;
5 5 cell-matrix test
36 0 0 test !
0 0 test @ .
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Translate this program into Java but keep the logic exactly as in Forth. | : cell-matrix
create over , * cells allot
does> dup cell+ >r @ * + cells r> + ;
5 5 cell-matrix test
36 0 0 test !
0 0 test @ .
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Generate a Python translation of this Forth snippet without changing its computational steps. | : cell-matrix
create over , * cells allot
does> dup cell+ >r @ * + cells r> + ;
5 5 cell-matrix test
36 0 0 test !
0 0 test @ .
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Convert the following code from Forth to VB, ensuring the logic remains intact. | : cell-matrix
create over , * cells allot
does> dup cell+ >r @ * + cells r> + ;
5 5 cell-matrix test
36 0 0 test !
0 0 test @ .
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Write the same algorithm in Go as shown in this Forth implementation. | : cell-matrix
create over , * cells allot
does> dup cell+ >r @ * + cells r> + ;
5 5 cell-matrix test
36 0 0 test !
0 0 test @ .
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Please provide an equivalent version of this Fortran code in C#. | PROGRAM Example
IMPLICIT NONE
INTEGER :: rows, columns, errcheck
INTEGER, ALLOCATABLE :: array(:,:)
WRITE(*,*) "Enter number of rows"
READ(*,*) rows
WRITE(*,*) "Enter number of columns"
READ(*,*) columns
ALLOCATE (array(rows,columns), STAT=errcheck)
array(1,1) = 42
WRITE(*,*) array(1,1)
DEALLOCATE (array, STAT=errcheck)
END PROGRAM Example
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Change the following Fortran code into C++ without altering its purpose. | PROGRAM Example
IMPLICIT NONE
INTEGER :: rows, columns, errcheck
INTEGER, ALLOCATABLE :: array(:,:)
WRITE(*,*) "Enter number of rows"
READ(*,*) rows
WRITE(*,*) "Enter number of columns"
READ(*,*) columns
ALLOCATE (array(rows,columns), STAT=errcheck)
array(1,1) = 42
WRITE(*,*) array(1,1)
DEALLOCATE (array, STAT=errcheck)
END PROGRAM Example
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Preserve the algorithm and functionality while converting the code from Fortran to C. | PROGRAM Example
IMPLICIT NONE
INTEGER :: rows, columns, errcheck
INTEGER, ALLOCATABLE :: array(:,:)
WRITE(*,*) "Enter number of rows"
READ(*,*) rows
WRITE(*,*) "Enter number of columns"
READ(*,*) columns
ALLOCATE (array(rows,columns), STAT=errcheck)
array(1,1) = 42
WRITE(*,*) array(1,1)
DEALLOCATE (array, STAT=errcheck)
END PROGRAM Example
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Change the programming language of this snippet from Fortran to Java without modifying what it does. | PROGRAM Example
IMPLICIT NONE
INTEGER :: rows, columns, errcheck
INTEGER, ALLOCATABLE :: array(:,:)
WRITE(*,*) "Enter number of rows"
READ(*,*) rows
WRITE(*,*) "Enter number of columns"
READ(*,*) columns
ALLOCATE (array(rows,columns), STAT=errcheck)
array(1,1) = 42
WRITE(*,*) array(1,1)
DEALLOCATE (array, STAT=errcheck)
END PROGRAM Example
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Translate the given Fortran code snippet into Python without altering its behavior. | PROGRAM Example
IMPLICIT NONE
INTEGER :: rows, columns, errcheck
INTEGER, ALLOCATABLE :: array(:,:)
WRITE(*,*) "Enter number of rows"
READ(*,*) rows
WRITE(*,*) "Enter number of columns"
READ(*,*) columns
ALLOCATE (array(rows,columns), STAT=errcheck)
array(1,1) = 42
WRITE(*,*) array(1,1)
DEALLOCATE (array, STAT=errcheck)
END PROGRAM Example
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Transform the following Fortran implementation into VB, maintaining the same output and logic. | PROGRAM Example
IMPLICIT NONE
INTEGER :: rows, columns, errcheck
INTEGER, ALLOCATABLE :: array(:,:)
WRITE(*,*) "Enter number of rows"
READ(*,*) rows
WRITE(*,*) "Enter number of columns"
READ(*,*) columns
ALLOCATE (array(rows,columns), STAT=errcheck)
array(1,1) = 42
WRITE(*,*) array(1,1)
DEALLOCATE (array, STAT=errcheck)
END PROGRAM Example
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Convert this Groovy block to C, preserving its control flow and logic. | def make2d = { nrows, ncols ->
(0..<nrows).collect { [0]*ncols }
}
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Convert this Groovy snippet to C# and keep its semantics consistent. | def make2d = { nrows, ncols ->
(0..<nrows).collect { [0]*ncols }
}
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Produce a language-to-language conversion: from Groovy to C++, same semantics. | def make2d = { nrows, ncols ->
(0..<nrows).collect { [0]*ncols }
}
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in Java. | def make2d = { nrows, ncols ->
(0..<nrows).collect { [0]*ncols }
}
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Generate an equivalent Python version of this Groovy code. | def make2d = { nrows, ncols ->
(0..<nrows).collect { [0]*ncols }
}
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Port the provided Groovy code into VB while preserving the original functionality. | def make2d = { nrows, ncols ->
(0..<nrows).collect { [0]*ncols }
}
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Write the same algorithm in Go as shown in this Groovy implementation. | def make2d = { nrows, ncols ->
(0..<nrows).collect { [0]*ncols }
}
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Change the programming language of this snippet from Haskell to C without modifying what it does. | import Data.Array
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Port the provided Haskell code into C# while preserving the original functionality. | import Data.Array
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Produce a language-to-language conversion: from Haskell to Java, same semantics. | import Data.Array
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Port the provided Haskell code into Python while preserving the original functionality. | import Data.Array
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Ensure the translated VB code behaves exactly like the original Haskell snippet. | import Data.Array
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Generate a Go translation of this Haskell snippet without changing its computational steps. | import Data.Array
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Generate an equivalent C version of this Icon code. | procedure main(args)
nr := integer(args[1]) | 3
nc := integer(args[2]) | 3
A := list(nr)
every !A := list(nc)
x := ?nr
y := ?nc
A[x][y] := &pi
write("A[",x,"][",y,"] -> ",A[x][y])
end
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Produce a language-to-language conversion: from Icon to C#, same semantics. | procedure main(args)
nr := integer(args[1]) | 3
nc := integer(args[2]) | 3
A := list(nr)
every !A := list(nc)
x := ?nr
y := ?nc
A[x][y] := &pi
write("A[",x,"][",y,"] -> ",A[x][y])
end
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Write the same algorithm in C++ as shown in this Icon implementation. | procedure main(args)
nr := integer(args[1]) | 3
nc := integer(args[2]) | 3
A := list(nr)
every !A := list(nc)
x := ?nr
y := ?nc
A[x][y] := &pi
write("A[",x,"][",y,"] -> ",A[x][y])
end
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Translate the given Icon code snippet into Java without altering its behavior. | procedure main(args)
nr := integer(args[1]) | 3
nc := integer(args[2]) | 3
A := list(nr)
every !A := list(nc)
x := ?nr
y := ?nc
A[x][y] := &pi
write("A[",x,"][",y,"] -> ",A[x][y])
end
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Translate the given Icon code snippet into Python without altering its behavior. | procedure main(args)
nr := integer(args[1]) | 3
nc := integer(args[2]) | 3
A := list(nr)
every !A := list(nc)
x := ?nr
y := ?nc
A[x][y] := &pi
write("A[",x,"][",y,"] -> ",A[x][y])
end
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Write the same code in VB as shown below in Icon. | procedure main(args)
nr := integer(args[1]) | 3
nc := integer(args[2]) | 3
A := list(nr)
every !A := list(nc)
x := ?nr
y := ?nc
A[x][y] := &pi
write("A[",x,"][",y,"] -> ",A[x][y])
end
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Convert the following code from Icon to Go, ensuring the logic remains intact. | procedure main(args)
nr := integer(args[1]) | 3
nc := integer(args[2]) | 3
A := list(nr)
every !A := list(nc)
x := ?nr
y := ?nc
A[x][y] := &pi
write("A[",x,"][",y,"] -> ",A[x][y])
end
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Maintain the same structure and functionality when rewriting this code in C. | array1=:i. 3 4
array2=: 5 6 $ 2
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Convert this J snippet to C# and keep its semantics consistent. | array1=:i. 3 4
array2=: 5 6 $ 2
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Please provide an equivalent version of this J code in C++. | array1=:i. 3 4
array2=: 5 6 $ 2
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Generate a Java translation of this J snippet without changing its computational steps. | array1=:i. 3 4
array2=: 5 6 $ 2
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Port the following code from J to Python with equivalent syntax and logic. | array1=:i. 3 4
array2=: 5 6 $ 2
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Change the following J code into VB without altering its purpose. | array1=:i. 3 4
array2=: 5 6 $ 2
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Please provide an equivalent version of this J code in Go. | array1=:i. 3 4
array2=: 5 6 $ 2
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Write a version of this Julia function in C with identical behavior. | function input(prompt::AbstractString)
print(prompt)
return readline()
end
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
x = rand(n, m)
display(x)
x[3, 3]
x[3, 3] = 5.0
x::Matrix
x = 0; gc()
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Keep all operations the same but rewrite the snippet in C#. | function input(prompt::AbstractString)
print(prompt)
return readline()
end
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
x = rand(n, m)
display(x)
x[3, 3]
x[3, 3] = 5.0
x::Matrix
x = 0; gc()
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Port the following code from Julia to C++ with equivalent syntax and logic. | function input(prompt::AbstractString)
print(prompt)
return readline()
end
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
x = rand(n, m)
display(x)
x[3, 3]
x[3, 3] = 5.0
x::Matrix
x = 0; gc()
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Rewrite the snippet below in Java so it works the same as the original Julia code. | function input(prompt::AbstractString)
print(prompt)
return readline()
end
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
x = rand(n, m)
display(x)
x[3, 3]
x[3, 3] = 5.0
x::Matrix
x = 0; gc()
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Preserve the algorithm and functionality while converting the code from Julia to Python. | function input(prompt::AbstractString)
print(prompt)
return readline()
end
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
x = rand(n, m)
display(x)
x[3, 3]
x[3, 3] = 5.0
x::Matrix
x = 0; gc()
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Produce a functionally identical VB code for the snippet given in Julia. | function input(prompt::AbstractString)
print(prompt)
return readline()
end
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
x = rand(n, m)
display(x)
x[3, 3]
x[3, 3] = 5.0
x::Matrix
x = 0; gc()
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Translate the given Julia code snippet into Go without altering its behavior. | function input(prompt::AbstractString)
print(prompt)
return readline()
end
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
x = rand(n, m)
display(x)
x[3, 3]
x[3, 3] = 5.0
x::Matrix
x = 0; gc()
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Can you help me rewrite this code in C instead of Lua, keeping it the same logically? | function multiply(n, a, b) if a <= b then return n, multiply(n, a + 1, b) end end
a, b = io.read() + 0, io.read() + 0
matrix = {multiply({multiply(1, 1, b)}, 1, a)}
matrix[a][b] = 5
print(matrix[a][b])
print(matrix[1][1])
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in C#. | function multiply(n, a, b) if a <= b then return n, multiply(n, a + 1, b) end end
a, b = io.read() + 0, io.read() + 0
matrix = {multiply({multiply(1, 1, b)}, 1, a)}
matrix[a][b] = 5
print(matrix[a][b])
print(matrix[1][1])
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.