Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Convert this AWK snippet to Go and keep its semantics consistent.
a[0]="hello"
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Please provide an equivalent version of this BBC_Basic code in C.
DIM text$(1) text$(0) = "Hello " text$(1) = "world!"
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Produce a language-to-language conversion: from BBC_Basic to C#, same semantics.
DIM text$(1) text$(0) = "Hello " text$(1) = "world!"
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Convert this BBC_Basic snippet to C++ and keep its semantics consistent.
DIM text$(1) text$(0) = "Hello " text$(1) = "world!"
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Preserve the algorithm and functionality while converting the code from BBC_Basic to Java.
DIM text$(1) text$(0) = "Hello " text$(1) = "world!"
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Translate the given BBC_Basic code snippet into Python without altering its behavior.
DIM text$(1) text$(0) = "Hello " text$(1) = "world!"
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Convert this BBC_Basic snippet to VB and keep its semantics consistent.
DIM text$(1) text$(0) = "Hello " text$(1) = "world!"
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Translate this program into Go but keep the logic exactly as in BBC_Basic.
DIM text$(1) text$(0) = "Hello " text$(1) = "world!"
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Convert this Clojure snippet to C and keep its semantics consistent.
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Transform the following Clojure implementation into C#, maintaining the same output and logic.
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Transform the following Clojure implementation into C++, maintaining the same output and logic.
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Write a version of this Clojure function in Java with identical behavior.
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Please provide an equivalent version of this Clojure code in Python.
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Keep all operations the same but rewrite the snippet in VB.
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Port the following code from Clojure to Go with equivalent syntax and logic.
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Change the programming language of this snippet from Common_Lisp to C without modifying what it does.
CL-USER> (let ((list '()) (hash-table (make-hash-table))) (push 1 list) (push 2 list) (push 3 list) (format t "~S~%" (reverse list)) (setf (gethash 'foo hash-table) 42) (setf (gethash 'bar hash-table) 69) (maphash (lambda (key value) (format t "~S => ~S~%" key value)) hash-table) (write hash-table :readably t) (describe hash-table) (describe list)) (1 2 3) FOO => 42 BAR => 69 #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST 'EQL :SIZE '16 :REHASH-SIZE '1.5 :REHASH-THRESHOLD '1.0 :WEAKNESS 'NIL) '((BAR . 69) (FOO . 42))) #<HASH-TABLE :TEST EQL :COUNT 2 {1002B6F391}> [hash-table] Occupancy: 0.1 Rehash-threshold: 1.0 Rehash-size: 1.5 Size: 16 Synchronized: no (3 2 1) [list]
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Write the same code in C# as shown below in Common_Lisp.
CL-USER> (let ((list '()) (hash-table (make-hash-table))) (push 1 list) (push 2 list) (push 3 list) (format t "~S~%" (reverse list)) (setf (gethash 'foo hash-table) 42) (setf (gethash 'bar hash-table) 69) (maphash (lambda (key value) (format t "~S => ~S~%" key value)) hash-table) (write hash-table :readably t) (describe hash-table) (describe list)) (1 2 3) FOO => 42 BAR => 69 #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST 'EQL :SIZE '16 :REHASH-SIZE '1.5 :REHASH-THRESHOLD '1.0 :WEAKNESS 'NIL) '((BAR . 69) (FOO . 42))) #<HASH-TABLE :TEST EQL :COUNT 2 {1002B6F391}> [hash-table] Occupancy: 0.1 Rehash-threshold: 1.0 Rehash-size: 1.5 Size: 16 Synchronized: no (3 2 1) [list]
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Maintain the same structure and functionality when rewriting this code in C++.
CL-USER> (let ((list '()) (hash-table (make-hash-table))) (push 1 list) (push 2 list) (push 3 list) (format t "~S~%" (reverse list)) (setf (gethash 'foo hash-table) 42) (setf (gethash 'bar hash-table) 69) (maphash (lambda (key value) (format t "~S => ~S~%" key value)) hash-table) (write hash-table :readably t) (describe hash-table) (describe list)) (1 2 3) FOO => 42 BAR => 69 #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST 'EQL :SIZE '16 :REHASH-SIZE '1.5 :REHASH-THRESHOLD '1.0 :WEAKNESS 'NIL) '((BAR . 69) (FOO . 42))) #<HASH-TABLE :TEST EQL :COUNT 2 {1002B6F391}> [hash-table] Occupancy: 0.1 Rehash-threshold: 1.0 Rehash-size: 1.5 Size: 16 Synchronized: no (3 2 1) [list]
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Can you help me rewrite this code in Java instead of Common_Lisp, keeping it the same logically?
CL-USER> (let ((list '()) (hash-table (make-hash-table))) (push 1 list) (push 2 list) (push 3 list) (format t "~S~%" (reverse list)) (setf (gethash 'foo hash-table) 42) (setf (gethash 'bar hash-table) 69) (maphash (lambda (key value) (format t "~S => ~S~%" key value)) hash-table) (write hash-table :readably t) (describe hash-table) (describe list)) (1 2 3) FOO => 42 BAR => 69 #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST 'EQL :SIZE '16 :REHASH-SIZE '1.5 :REHASH-THRESHOLD '1.0 :WEAKNESS 'NIL) '((BAR . 69) (FOO . 42))) #<HASH-TABLE :TEST EQL :COUNT 2 {1002B6F391}> [hash-table] Occupancy: 0.1 Rehash-threshold: 1.0 Rehash-size: 1.5 Size: 16 Synchronized: no (3 2 1) [list]
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Keep all operations the same but rewrite the snippet in Python.
CL-USER> (let ((list '()) (hash-table (make-hash-table))) (push 1 list) (push 2 list) (push 3 list) (format t "~S~%" (reverse list)) (setf (gethash 'foo hash-table) 42) (setf (gethash 'bar hash-table) 69) (maphash (lambda (key value) (format t "~S => ~S~%" key value)) hash-table) (write hash-table :readably t) (describe hash-table) (describe list)) (1 2 3) FOO => 42 BAR => 69 #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST 'EQL :SIZE '16 :REHASH-SIZE '1.5 :REHASH-THRESHOLD '1.0 :WEAKNESS 'NIL) '((BAR . 69) (FOO . 42))) #<HASH-TABLE :TEST EQL :COUNT 2 {1002B6F391}> [hash-table] Occupancy: 0.1 Rehash-threshold: 1.0 Rehash-size: 1.5 Size: 16 Synchronized: no (3 2 1) [list]
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Convert this Common_Lisp block to VB, preserving its control flow and logic.
CL-USER> (let ((list '()) (hash-table (make-hash-table))) (push 1 list) (push 2 list) (push 3 list) (format t "~S~%" (reverse list)) (setf (gethash 'foo hash-table) 42) (setf (gethash 'bar hash-table) 69) (maphash (lambda (key value) (format t "~S => ~S~%" key value)) hash-table) (write hash-table :readably t) (describe hash-table) (describe list)) (1 2 3) FOO => 42 BAR => 69 #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST 'EQL :SIZE '16 :REHASH-SIZE '1.5 :REHASH-THRESHOLD '1.0 :WEAKNESS 'NIL) '((BAR . 69) (FOO . 42))) #<HASH-TABLE :TEST EQL :COUNT 2 {1002B6F391}> [hash-table] Occupancy: 0.1 Rehash-threshold: 1.0 Rehash-size: 1.5 Size: 16 Synchronized: no (3 2 1) [list]
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Port the provided Common_Lisp code into Go while preserving the original functionality.
CL-USER> (let ((list '()) (hash-table (make-hash-table))) (push 1 list) (push 2 list) (push 3 list) (format t "~S~%" (reverse list)) (setf (gethash 'foo hash-table) 42) (setf (gethash 'bar hash-table) 69) (maphash (lambda (key value) (format t "~S => ~S~%" key value)) hash-table) (write hash-table :readably t) (describe hash-table) (describe list)) (1 2 3) FOO => 42 BAR => 69 #.(SB-IMPL::%STUFF-HASH-TABLE (MAKE-HASH-TABLE :TEST 'EQL :SIZE '16 :REHASH-SIZE '1.5 :REHASH-THRESHOLD '1.0 :WEAKNESS 'NIL) '((BAR . 69) (FOO . 42))) #<HASH-TABLE :TEST EQL :COUNT 2 {1002B6F391}> [hash-table] Occupancy: 0.1 Rehash-threshold: 1.0 Rehash-size: 1.5 Size: 16 Synchronized: no (3 2 1) [list]
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Please provide an equivalent version of this D code in C.
int[3] array; array[0] = 5;
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Rewrite this program in C# while keeping its functionality equivalent to the D version.
int[3] array; array[0] = 5;
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Port the provided D code into C++ while preserving the original functionality.
int[3] array; array[0] = 5;
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Produce a functionally identical Java code for the snippet given in D.
int[3] array; array[0] = 5;
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Convert the following code from D to Go, ensuring the logic remains intact.
int[3] array; array[0] = 5;
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Write the same algorithm in C as shown in this Delphi implementation.
var intArray: TArray<Integer> = [1, 2, 3, 4, 5]; intArray2: array of Integer = [1, 2, 3, 4, 5]; intArray3: array [0..4]of Integer; intArray4: array [10..14]of Integer; procedure var intArray5: TArray<Integer>; begin intArray := [1,2,3]; intArray2 := [1,2,3]; intArray[0] := 1; SetLength(intArray,5); var intArray6 := [1, 2, 3]; var intArray7: TArray<Integer> := [1, 2, 3]; end;
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Ensure the translated C# code behaves exactly like the original Delphi snippet.
var intArray: TArray<Integer> = [1, 2, 3, 4, 5]; intArray2: array of Integer = [1, 2, 3, 4, 5]; intArray3: array [0..4]of Integer; intArray4: array [10..14]of Integer; procedure var intArray5: TArray<Integer>; begin intArray := [1,2,3]; intArray2 := [1,2,3]; intArray[0] := 1; SetLength(intArray,5); var intArray6 := [1, 2, 3]; var intArray7: TArray<Integer> := [1, 2, 3]; end;
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Write a version of this Delphi function in C++ with identical behavior.
var intArray: TArray<Integer> = [1, 2, 3, 4, 5]; intArray2: array of Integer = [1, 2, 3, 4, 5]; intArray3: array [0..4]of Integer; intArray4: array [10..14]of Integer; procedure var intArray5: TArray<Integer>; begin intArray := [1,2,3]; intArray2 := [1,2,3]; intArray[0] := 1; SetLength(intArray,5); var intArray6 := [1, 2, 3]; var intArray7: TArray<Integer> := [1, 2, 3]; end;
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Can you help me rewrite this code in Java instead of Delphi, keeping it the same logically?
var intArray: TArray<Integer> = [1, 2, 3, 4, 5]; intArray2: array of Integer = [1, 2, 3, 4, 5]; intArray3: array [0..4]of Integer; intArray4: array [10..14]of Integer; procedure var intArray5: TArray<Integer>; begin intArray := [1,2,3]; intArray2 := [1,2,3]; intArray[0] := 1; SetLength(intArray,5); var intArray6 := [1, 2, 3]; var intArray7: TArray<Integer> := [1, 2, 3]; end;
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Port the following code from Delphi to Python with equivalent syntax and logic.
var intArray: TArray<Integer> = [1, 2, 3, 4, 5]; intArray2: array of Integer = [1, 2, 3, 4, 5]; intArray3: array [0..4]of Integer; intArray4: array [10..14]of Integer; procedure var intArray5: TArray<Integer>; begin intArray := [1,2,3]; intArray2 := [1,2,3]; intArray[0] := 1; SetLength(intArray,5); var intArray6 := [1, 2, 3]; var intArray7: TArray<Integer> := [1, 2, 3]; end;
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Convert the following code from Delphi to VB, ensuring the logic remains intact.
var intArray: TArray<Integer> = [1, 2, 3, 4, 5]; intArray2: array of Integer = [1, 2, 3, 4, 5]; intArray3: array [0..4]of Integer; intArray4: array [10..14]of Integer; procedure var intArray5: TArray<Integer>; begin intArray := [1,2,3]; intArray2 := [1,2,3]; intArray[0] := 1; SetLength(intArray,5); var intArray6 := [1, 2, 3]; var intArray7: TArray<Integer> := [1, 2, 3]; end;
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Port the provided Delphi code into Go while preserving the original functionality.
var intArray: TArray<Integer> = [1, 2, 3, 4, 5]; intArray2: array of Integer = [1, 2, 3, 4, 5]; intArray3: array [0..4]of Integer; intArray4: array [10..14]of Integer; procedure var intArray5: TArray<Integer>; begin intArray := [1,2,3]; intArray2 := [1,2,3]; intArray[0] := 1; SetLength(intArray,5); var intArray6 := [1, 2, 3]; var intArray7: TArray<Integer> := [1, 2, 3]; end;
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Produce a functionally identical C code for the snippet given in Elixir.
empty_list = [] list = [1,2,3,4,5] length(list) [0 | list] hd(list) tl(list) Enum.at(list,3) list ++ [6,7] list -- [4,2]
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Port the provided Elixir code into C# while preserving the original functionality.
empty_list = [] list = [1,2,3,4,5] length(list) [0 | list] hd(list) tl(list) Enum.at(list,3) list ++ [6,7] list -- [4,2]
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Produce a language-to-language conversion: from Elixir to C++, same semantics.
empty_list = [] list = [1,2,3,4,5] length(list) [0 | list] hd(list) tl(list) Enum.at(list,3) list ++ [6,7] list -- [4,2]
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Write the same code in Java as shown below in Elixir.
empty_list = [] list = [1,2,3,4,5] length(list) [0 | list] hd(list) tl(list) Enum.at(list,3) list ++ [6,7] list -- [4,2]
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Preserve the algorithm and functionality while converting the code from Elixir to Python.
empty_list = [] list = [1,2,3,4,5] length(list) [0 | list] hd(list) tl(list) Enum.at(list,3) list ++ [6,7] list -- [4,2]
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Convert the following code from Elixir to VB, ensuring the logic remains intact.
empty_list = [] list = [1,2,3,4,5] length(list) [0 | list] hd(list) tl(list) Enum.at(list,3) list ++ [6,7] list -- [4,2]
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Write the same algorithm in Go as shown in this Elixir implementation.
empty_list = [] list = [1,2,3,4,5] length(list) [0 | list] hd(list) tl(list) Enum.at(list,3) list ++ [6,7] list -- [4,2]
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Convert this Factor block to C, preserving its control flow and logic.
USING: assocs deques dlists lists lists.lazy sequences sets ; { 1 2 "foo" 3 } [ 1 2 3 + * ] "Hello, world B{ 1 2 3 } ?{ f t t } { 1 2 3 } 4 suffix { 1 2 3 } { 4 5 6 } append { 1 1 2 3 } { 2 5 7 8 } intersect "Hello" { } like { 72 101 108 108 111 } "" like V{ 1 2 "foo" 3 } BV{ 1 2 255 } SBUF" Hello, world V{ 1 2 3 } 4 suffix V{ 1 2 3 } { 4 5 6 } append V{ 1 2 3 } pop { { "hamburger" 150 } { "soda" 99 } { "fries" 99 } } H{ { 1 "a" } { 2 "b" } } 3 "c" H{ { 1 "a" } { 2 "b" } } [ set-at ] keep T{ cons-state f 1 +nil+ } T{ cons-state { car 1 } { cdr +nil+ } } 1 2 3 4 +nil+ cons cons cons cons 1 2 2list { 1 2 3 4 } sequence>list 0 lfrom 0 [ 2 + ] lfrom-by DL{ 1 2 3 } 3 DL{ 1 2 } [ push-front ] keep 3 DL{ 1 2 } [ push-back ] keep
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Produce a functionally identical C# code for the snippet given in Factor.
USING: assocs deques dlists lists lists.lazy sequences sets ; { 1 2 "foo" 3 } [ 1 2 3 + * ] "Hello, world B{ 1 2 3 } ?{ f t t } { 1 2 3 } 4 suffix { 1 2 3 } { 4 5 6 } append { 1 1 2 3 } { 2 5 7 8 } intersect "Hello" { } like { 72 101 108 108 111 } "" like V{ 1 2 "foo" 3 } BV{ 1 2 255 } SBUF" Hello, world V{ 1 2 3 } 4 suffix V{ 1 2 3 } { 4 5 6 } append V{ 1 2 3 } pop { { "hamburger" 150 } { "soda" 99 } { "fries" 99 } } H{ { 1 "a" } { 2 "b" } } 3 "c" H{ { 1 "a" } { 2 "b" } } [ set-at ] keep T{ cons-state f 1 +nil+ } T{ cons-state { car 1 } { cdr +nil+ } } 1 2 3 4 +nil+ cons cons cons cons 1 2 2list { 1 2 3 4 } sequence>list 0 lfrom 0 [ 2 + ] lfrom-by DL{ 1 2 3 } 3 DL{ 1 2 } [ push-front ] keep 3 DL{ 1 2 } [ push-back ] keep
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Port the provided Factor code into C++ while preserving the original functionality.
USING: assocs deques dlists lists lists.lazy sequences sets ; { 1 2 "foo" 3 } [ 1 2 3 + * ] "Hello, world B{ 1 2 3 } ?{ f t t } { 1 2 3 } 4 suffix { 1 2 3 } { 4 5 6 } append { 1 1 2 3 } { 2 5 7 8 } intersect "Hello" { } like { 72 101 108 108 111 } "" like V{ 1 2 "foo" 3 } BV{ 1 2 255 } SBUF" Hello, world V{ 1 2 3 } 4 suffix V{ 1 2 3 } { 4 5 6 } append V{ 1 2 3 } pop { { "hamburger" 150 } { "soda" 99 } { "fries" 99 } } H{ { 1 "a" } { 2 "b" } } 3 "c" H{ { 1 "a" } { 2 "b" } } [ set-at ] keep T{ cons-state f 1 +nil+ } T{ cons-state { car 1 } { cdr +nil+ } } 1 2 3 4 +nil+ cons cons cons cons 1 2 2list { 1 2 3 4 } sequence>list 0 lfrom 0 [ 2 + ] lfrom-by DL{ 1 2 3 } 3 DL{ 1 2 } [ push-front ] keep 3 DL{ 1 2 } [ push-back ] keep
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Change the following Factor code into Java without altering its purpose.
USING: assocs deques dlists lists lists.lazy sequences sets ; { 1 2 "foo" 3 } [ 1 2 3 + * ] "Hello, world B{ 1 2 3 } ?{ f t t } { 1 2 3 } 4 suffix { 1 2 3 } { 4 5 6 } append { 1 1 2 3 } { 2 5 7 8 } intersect "Hello" { } like { 72 101 108 108 111 } "" like V{ 1 2 "foo" 3 } BV{ 1 2 255 } SBUF" Hello, world V{ 1 2 3 } 4 suffix V{ 1 2 3 } { 4 5 6 } append V{ 1 2 3 } pop { { "hamburger" 150 } { "soda" 99 } { "fries" 99 } } H{ { 1 "a" } { 2 "b" } } 3 "c" H{ { 1 "a" } { 2 "b" } } [ set-at ] keep T{ cons-state f 1 +nil+ } T{ cons-state { car 1 } { cdr +nil+ } } 1 2 3 4 +nil+ cons cons cons cons 1 2 2list { 1 2 3 4 } sequence>list 0 lfrom 0 [ 2 + ] lfrom-by DL{ 1 2 3 } 3 DL{ 1 2 } [ push-front ] keep 3 DL{ 1 2 } [ push-back ] keep
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Ensure the translated Python code behaves exactly like the original Factor snippet.
USING: assocs deques dlists lists lists.lazy sequences sets ; { 1 2 "foo" 3 } [ 1 2 3 + * ] "Hello, world B{ 1 2 3 } ?{ f t t } { 1 2 3 } 4 suffix { 1 2 3 } { 4 5 6 } append { 1 1 2 3 } { 2 5 7 8 } intersect "Hello" { } like { 72 101 108 108 111 } "" like V{ 1 2 "foo" 3 } BV{ 1 2 255 } SBUF" Hello, world V{ 1 2 3 } 4 suffix V{ 1 2 3 } { 4 5 6 } append V{ 1 2 3 } pop { { "hamburger" 150 } { "soda" 99 } { "fries" 99 } } H{ { 1 "a" } { 2 "b" } } 3 "c" H{ { 1 "a" } { 2 "b" } } [ set-at ] keep T{ cons-state f 1 +nil+ } T{ cons-state { car 1 } { cdr +nil+ } } 1 2 3 4 +nil+ cons cons cons cons 1 2 2list { 1 2 3 4 } sequence>list 0 lfrom 0 [ 2 + ] lfrom-by DL{ 1 2 3 } 3 DL{ 1 2 } [ push-front ] keep 3 DL{ 1 2 } [ push-back ] keep
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Preserve the algorithm and functionality while converting the code from Factor to VB.
USING: assocs deques dlists lists lists.lazy sequences sets ; { 1 2 "foo" 3 } [ 1 2 3 + * ] "Hello, world B{ 1 2 3 } ?{ f t t } { 1 2 3 } 4 suffix { 1 2 3 } { 4 5 6 } append { 1 1 2 3 } { 2 5 7 8 } intersect "Hello" { } like { 72 101 108 108 111 } "" like V{ 1 2 "foo" 3 } BV{ 1 2 255 } SBUF" Hello, world V{ 1 2 3 } 4 suffix V{ 1 2 3 } { 4 5 6 } append V{ 1 2 3 } pop { { "hamburger" 150 } { "soda" 99 } { "fries" 99 } } H{ { 1 "a" } { 2 "b" } } 3 "c" H{ { 1 "a" } { 2 "b" } } [ set-at ] keep T{ cons-state f 1 +nil+ } T{ cons-state { car 1 } { cdr +nil+ } } 1 2 3 4 +nil+ cons cons cons cons 1 2 2list { 1 2 3 4 } sequence>list 0 lfrom 0 [ 2 + ] lfrom-by DL{ 1 2 3 } 3 DL{ 1 2 } [ push-front ] keep 3 DL{ 1 2 } [ push-back ] keep
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Rewrite this program in Go while keeping its functionality equivalent to the Factor version.
USING: assocs deques dlists lists lists.lazy sequences sets ; { 1 2 "foo" 3 } [ 1 2 3 + * ] "Hello, world B{ 1 2 3 } ?{ f t t } { 1 2 3 } 4 suffix { 1 2 3 } { 4 5 6 } append { 1 1 2 3 } { 2 5 7 8 } intersect "Hello" { } like { 72 101 108 108 111 } "" like V{ 1 2 "foo" 3 } BV{ 1 2 255 } SBUF" Hello, world V{ 1 2 3 } 4 suffix V{ 1 2 3 } { 4 5 6 } append V{ 1 2 3 } pop { { "hamburger" 150 } { "soda" 99 } { "fries" 99 } } H{ { 1 "a" } { 2 "b" } } 3 "c" H{ { 1 "a" } { 2 "b" } } [ set-at ] keep T{ cons-state f 1 +nil+ } T{ cons-state { car 1 } { cdr +nil+ } } 1 2 3 4 +nil+ cons cons cons cons 1 2 2list { 1 2 3 4 } sequence>list 0 lfrom 0 [ 2 + ] lfrom-by DL{ 1 2 3 } 3 DL{ 1 2 } [ push-front ] keep 3 DL{ 1 2 } [ push-back ] keep
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Ensure the translated C code behaves exactly like the original Forth snippet.
include ffl/car.fs 10 car-create ar 2 0 ar car-set 3 1 ar car-set 1 0 ar car-insert
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Write the same algorithm in C# as shown in this Forth implementation.
include ffl/car.fs 10 car-create ar 2 0 ar car-set 3 1 ar car-set 1 0 ar car-insert
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Convert this Forth block to C++, preserving its control flow and logic.
include ffl/car.fs 10 car-create ar 2 0 ar car-set 3 1 ar car-set 1 0 ar car-insert
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Generate an equivalent Java version of this Forth code.
include ffl/car.fs 10 car-create ar 2 0 ar car-set 3 1 ar car-set 1 0 ar car-insert
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Port the following code from Forth to Python with equivalent syntax and logic.
include ffl/car.fs 10 car-create ar 2 0 ar car-set 3 1 ar car-set 1 0 ar car-insert
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Write a version of this Forth function in VB with identical behavior.
include ffl/car.fs 10 car-create ar 2 0 ar car-set 3 1 ar car-set 1 0 ar car-insert
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Write the same code in Go as shown below in Forth.
include ffl/car.fs 10 car-create ar 2 0 ar car-set 3 1 ar car-set 1 0 ar car-insert
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Write the same algorithm in C# as shown in this Fortran implementation.
REAL A(36) A(1) = 1 A(2) = 3*A(1) + 5
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Produce a functionally identical C++ code for the snippet given in Fortran.
REAL A(36) A(1) = 1 A(2) = 3*A(1) + 5
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Can you help me rewrite this code in C instead of Fortran, keeping it the same logically?
REAL A(36) A(1) = 1 A(2) = 3*A(1) + 5
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Can you help me rewrite this code in Java instead of Fortran, keeping it the same logically?
REAL A(36) A(1) = 1 A(2) = 3*A(1) + 5
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Translate the given Fortran code snippet into Python without altering its behavior.
REAL A(36) A(1) = 1 A(2) = 3*A(1) + 5
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Write the same code in VB as shown below in Fortran.
REAL A(36) A(1) = 1 A(2) = 3*A(1) + 5
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Produce a functionally identical PHP code for the snippet given in Fortran.
REAL A(36) A(1) = 1 A(2) = 3*A(1) + 5
<?php $a = array(); # add elements "at the end" array_push($a, 55, 10, 20); print_r($a); # using an explicit key $a['one'] = 1; $a['two'] = 2; print_r($a); ?>
Translate the given Groovy code snippet into C without altering its behavior.
def emptyList = [] assert emptyList.isEmpty() : "These are not the items you're looking for" assert emptyList.size() == 0 : "Empty list has size 0" assert ! emptyList : "Empty list evaluates as boolean 'false'" def initializedList = [ 1, "b", java.awt.Color.BLUE ] assert initializedList.size() == 3 assert initializedList : "Non-empty list evaluates as boolean 'true'" assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)" assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)" def combinedList = initializedList + [ "more stuff", "even more stuff" ] assert combinedList.size() == 5 assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements" combinedList << "even more stuff" assert combinedList.size() == 6 assert combinedList[-1..-3] == \ ["even more stuff", "even more stuff", "more stuff"] \ : "reverse referencing last 3 elements" println ([combinedList: combinedList])
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Write the same algorithm in C# as shown in this Groovy implementation.
def emptyList = [] assert emptyList.isEmpty() : "These are not the items you're looking for" assert emptyList.size() == 0 : "Empty list has size 0" assert ! emptyList : "Empty list evaluates as boolean 'false'" def initializedList = [ 1, "b", java.awt.Color.BLUE ] assert initializedList.size() == 3 assert initializedList : "Non-empty list evaluates as boolean 'true'" assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)" assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)" def combinedList = initializedList + [ "more stuff", "even more stuff" ] assert combinedList.size() == 5 assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements" combinedList << "even more stuff" assert combinedList.size() == 6 assert combinedList[-1..-3] == \ ["even more stuff", "even more stuff", "more stuff"] \ : "reverse referencing last 3 elements" println ([combinedList: combinedList])
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Preserve the algorithm and functionality while converting the code from Groovy to C++.
def emptyList = [] assert emptyList.isEmpty() : "These are not the items you're looking for" assert emptyList.size() == 0 : "Empty list has size 0" assert ! emptyList : "Empty list evaluates as boolean 'false'" def initializedList = [ 1, "b", java.awt.Color.BLUE ] assert initializedList.size() == 3 assert initializedList : "Non-empty list evaluates as boolean 'true'" assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)" assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)" def combinedList = initializedList + [ "more stuff", "even more stuff" ] assert combinedList.size() == 5 assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements" combinedList << "even more stuff" assert combinedList.size() == 6 assert combinedList[-1..-3] == \ ["even more stuff", "even more stuff", "more stuff"] \ : "reverse referencing last 3 elements" println ([combinedList: combinedList])
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Keep all operations the same but rewrite the snippet in Java.
def emptyList = [] assert emptyList.isEmpty() : "These are not the items you're looking for" assert emptyList.size() == 0 : "Empty list has size 0" assert ! emptyList : "Empty list evaluates as boolean 'false'" def initializedList = [ 1, "b", java.awt.Color.BLUE ] assert initializedList.size() == 3 assert initializedList : "Non-empty list evaluates as boolean 'true'" assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)" assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)" def combinedList = initializedList + [ "more stuff", "even more stuff" ] assert combinedList.size() == 5 assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements" combinedList << "even more stuff" assert combinedList.size() == 6 assert combinedList[-1..-3] == \ ["even more stuff", "even more stuff", "more stuff"] \ : "reverse referencing last 3 elements" println ([combinedList: combinedList])
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Produce a language-to-language conversion: from Groovy to Python, same semantics.
def emptyList = [] assert emptyList.isEmpty() : "These are not the items you're looking for" assert emptyList.size() == 0 : "Empty list has size 0" assert ! emptyList : "Empty list evaluates as boolean 'false'" def initializedList = [ 1, "b", java.awt.Color.BLUE ] assert initializedList.size() == 3 assert initializedList : "Non-empty list evaluates as boolean 'true'" assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)" assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)" def combinedList = initializedList + [ "more stuff", "even more stuff" ] assert combinedList.size() == 5 assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements" combinedList << "even more stuff" assert combinedList.size() == 6 assert combinedList[-1..-3] == \ ["even more stuff", "even more stuff", "more stuff"] \ : "reverse referencing last 3 elements" println ([combinedList: combinedList])
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Maintain the same structure and functionality when rewriting this code in VB.
def emptyList = [] assert emptyList.isEmpty() : "These are not the items you're looking for" assert emptyList.size() == 0 : "Empty list has size 0" assert ! emptyList : "Empty list evaluates as boolean 'false'" def initializedList = [ 1, "b", java.awt.Color.BLUE ] assert initializedList.size() == 3 assert initializedList : "Non-empty list evaluates as boolean 'true'" assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)" assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)" def combinedList = initializedList + [ "more stuff", "even more stuff" ] assert combinedList.size() == 5 assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements" combinedList << "even more stuff" assert combinedList.size() == 6 assert combinedList[-1..-3] == \ ["even more stuff", "even more stuff", "more stuff"] \ : "reverse referencing last 3 elements" println ([combinedList: combinedList])
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Translate this program into Go but keep the logic exactly as in Groovy.
def emptyList = [] assert emptyList.isEmpty() : "These are not the items you're looking for" assert emptyList.size() == 0 : "Empty list has size 0" assert ! emptyList : "Empty list evaluates as boolean 'false'" def initializedList = [ 1, "b", java.awt.Color.BLUE ] assert initializedList.size() == 3 assert initializedList : "Non-empty list evaluates as boolean 'true'" assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)" assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)" def combinedList = initializedList + [ "more stuff", "even more stuff" ] assert combinedList.size() == 5 assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements" combinedList << "even more stuff" assert combinedList.size() == 6 assert combinedList[-1..-3] == \ ["even more stuff", "even more stuff", "more stuff"] \ : "reverse referencing last 3 elements" println ([combinedList: combinedList])
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Please provide an equivalent version of this Haskell code in C.
[1, 2, 3, 4, 5]
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Generate an equivalent C++ version of this Haskell code.
[1, 2, 3, 4, 5]
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Convert this Haskell snippet to Java and keep its semantics consistent.
[1, 2, 3, 4, 5]
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Convert the following code from Haskell to Python, ensuring the logic remains intact.
[1, 2, 3, 4, 5]
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Port the provided Haskell code into Go while preserving the original functionality.
[1, 2, 3, 4, 5]
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Generate an equivalent C version of this Icon code.
s := "abccd" c := 'abcd' S := set() T := table() L := [] record constructorname(field1,field2,fieldetc) R := constructorname()
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Rewrite this program in C# while keeping its functionality equivalent to the Icon version.
s := "abccd" c := 'abcd' S := set() T := table() L := [] record constructorname(field1,field2,fieldetc) R := constructorname()
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Rewrite this program in C++ while keeping its functionality equivalent to the Icon version.
s := "abccd" c := 'abcd' S := set() T := table() L := [] record constructorname(field1,field2,fieldetc) R := constructorname()
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Convert this Icon block to Java, preserving its control flow and logic.
s := "abccd" c := 'abcd' S := set() T := table() L := [] record constructorname(field1,field2,fieldetc) R := constructorname()
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Convert the following code from Icon to Python, ensuring the logic remains intact.
s := "abccd" c := 'abcd' S := set() T := table() L := [] record constructorname(field1,field2,fieldetc) R := constructorname()
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Ensure the translated VB code behaves exactly like the original Icon snippet.
s := "abccd" c := 'abcd' S := set() T := table() L := [] record constructorname(field1,field2,fieldetc) R := constructorname()
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Rewrite the snippet below in Go so it works the same as the original Icon code.
s := "abccd" c := 'abcd' S := set() T := table() L := [] record constructorname(field1,field2,fieldetc) R := constructorname()
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Preserve the algorithm and functionality while converting the code from J to C.
c =: 0 10 20 30 40 c, 50 0 10 20 30 40 50 _20 _10 , c _20 _10 0 10 20 30 40 ,~ c 0 10 20 30 40 0 10 20 30 40 ,:~ c 0 10 20 30 40 0 10 20 30 40 30 e. c 1 30 i.~c 3 30 80 e. c 1 0 2 1 4 2 { c 20 10 40 20 |.c 40 30 20 10 0 1+c 1 11 21 31 41 c%10 0 1 2 3 4 {. c 0 {: c 40 3{.c 0 10 20 3}.c 30 40 _3{.c 20 30 40 _3}.c 0 10 keys_map_ =: 'one';'two';'three' vals_map_ =: 'alpha';'beta';'gamma' lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen exists_map_ =: verb def 'y e. keys'&boxopen exists_map_ 'bad key' 0 exists_map_ 'two';'bad key' 1 0 lookup_map_ 'one' +-----+ |alpha| +-----+ lookup_map_ 'three';'one';'two';'one' +-----+-----+----+-----+ |gamma|alpha|beta|alpha| +-----+-----+----+-----+ lookup_map_ 'bad key' ++ || ++ 'some other default' lookup_map_ 'bad key' +------------------+ |some other default| +------------------+ 'some other default' lookup_map_ 'two';'bad key' +----+------------------+ |beta|some other default| +----+------------------+ +/ c 100 */ c 0 i.5 0 1 2 3 4 10*i.5 0 10 20 30 40 c = 10*i.5 1 1 1 1 1 c -: 10 i.5 1
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Change the following J code into C# without altering its purpose.
c =: 0 10 20 30 40 c, 50 0 10 20 30 40 50 _20 _10 , c _20 _10 0 10 20 30 40 ,~ c 0 10 20 30 40 0 10 20 30 40 ,:~ c 0 10 20 30 40 0 10 20 30 40 30 e. c 1 30 i.~c 3 30 80 e. c 1 0 2 1 4 2 { c 20 10 40 20 |.c 40 30 20 10 0 1+c 1 11 21 31 41 c%10 0 1 2 3 4 {. c 0 {: c 40 3{.c 0 10 20 3}.c 30 40 _3{.c 20 30 40 _3}.c 0 10 keys_map_ =: 'one';'two';'three' vals_map_ =: 'alpha';'beta';'gamma' lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen exists_map_ =: verb def 'y e. keys'&boxopen exists_map_ 'bad key' 0 exists_map_ 'two';'bad key' 1 0 lookup_map_ 'one' +-----+ |alpha| +-----+ lookup_map_ 'three';'one';'two';'one' +-----+-----+----+-----+ |gamma|alpha|beta|alpha| +-----+-----+----+-----+ lookup_map_ 'bad key' ++ || ++ 'some other default' lookup_map_ 'bad key' +------------------+ |some other default| +------------------+ 'some other default' lookup_map_ 'two';'bad key' +----+------------------+ |beta|some other default| +----+------------------+ +/ c 100 */ c 0 i.5 0 1 2 3 4 10*i.5 0 10 20 30 40 c = 10*i.5 1 1 1 1 1 c -: 10 i.5 1
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Keep all operations the same but rewrite the snippet in C++.
c =: 0 10 20 30 40 c, 50 0 10 20 30 40 50 _20 _10 , c _20 _10 0 10 20 30 40 ,~ c 0 10 20 30 40 0 10 20 30 40 ,:~ c 0 10 20 30 40 0 10 20 30 40 30 e. c 1 30 i.~c 3 30 80 e. c 1 0 2 1 4 2 { c 20 10 40 20 |.c 40 30 20 10 0 1+c 1 11 21 31 41 c%10 0 1 2 3 4 {. c 0 {: c 40 3{.c 0 10 20 3}.c 30 40 _3{.c 20 30 40 _3}.c 0 10 keys_map_ =: 'one';'two';'three' vals_map_ =: 'alpha';'beta';'gamma' lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen exists_map_ =: verb def 'y e. keys'&boxopen exists_map_ 'bad key' 0 exists_map_ 'two';'bad key' 1 0 lookup_map_ 'one' +-----+ |alpha| +-----+ lookup_map_ 'three';'one';'two';'one' +-----+-----+----+-----+ |gamma|alpha|beta|alpha| +-----+-----+----+-----+ lookup_map_ 'bad key' ++ || ++ 'some other default' lookup_map_ 'bad key' +------------------+ |some other default| +------------------+ 'some other default' lookup_map_ 'two';'bad key' +----+------------------+ |beta|some other default| +----+------------------+ +/ c 100 */ c 0 i.5 0 1 2 3 4 10*i.5 0 10 20 30 40 c = 10*i.5 1 1 1 1 1 c -: 10 i.5 1
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Produce a functionally identical Java code for the snippet given in J.
c =: 0 10 20 30 40 c, 50 0 10 20 30 40 50 _20 _10 , c _20 _10 0 10 20 30 40 ,~ c 0 10 20 30 40 0 10 20 30 40 ,:~ c 0 10 20 30 40 0 10 20 30 40 30 e. c 1 30 i.~c 3 30 80 e. c 1 0 2 1 4 2 { c 20 10 40 20 |.c 40 30 20 10 0 1+c 1 11 21 31 41 c%10 0 1 2 3 4 {. c 0 {: c 40 3{.c 0 10 20 3}.c 30 40 _3{.c 20 30 40 _3}.c 0 10 keys_map_ =: 'one';'two';'three' vals_map_ =: 'alpha';'beta';'gamma' lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen exists_map_ =: verb def 'y e. keys'&boxopen exists_map_ 'bad key' 0 exists_map_ 'two';'bad key' 1 0 lookup_map_ 'one' +-----+ |alpha| +-----+ lookup_map_ 'three';'one';'two';'one' +-----+-----+----+-----+ |gamma|alpha|beta|alpha| +-----+-----+----+-----+ lookup_map_ 'bad key' ++ || ++ 'some other default' lookup_map_ 'bad key' +------------------+ |some other default| +------------------+ 'some other default' lookup_map_ 'two';'bad key' +----+------------------+ |beta|some other default| +----+------------------+ +/ c 100 */ c 0 i.5 0 1 2 3 4 10*i.5 0 10 20 30 40 c = 10*i.5 1 1 1 1 1 c -: 10 i.5 1
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Ensure the translated Python code behaves exactly like the original J snippet.
c =: 0 10 20 30 40 c, 50 0 10 20 30 40 50 _20 _10 , c _20 _10 0 10 20 30 40 ,~ c 0 10 20 30 40 0 10 20 30 40 ,:~ c 0 10 20 30 40 0 10 20 30 40 30 e. c 1 30 i.~c 3 30 80 e. c 1 0 2 1 4 2 { c 20 10 40 20 |.c 40 30 20 10 0 1+c 1 11 21 31 41 c%10 0 1 2 3 4 {. c 0 {: c 40 3{.c 0 10 20 3}.c 30 40 _3{.c 20 30 40 _3}.c 0 10 keys_map_ =: 'one';'two';'three' vals_map_ =: 'alpha';'beta';'gamma' lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen exists_map_ =: verb def 'y e. keys'&boxopen exists_map_ 'bad key' 0 exists_map_ 'two';'bad key' 1 0 lookup_map_ 'one' +-----+ |alpha| +-----+ lookup_map_ 'three';'one';'two';'one' +-----+-----+----+-----+ |gamma|alpha|beta|alpha| +-----+-----+----+-----+ lookup_map_ 'bad key' ++ || ++ 'some other default' lookup_map_ 'bad key' +------------------+ |some other default| +------------------+ 'some other default' lookup_map_ 'two';'bad key' +----+------------------+ |beta|some other default| +----+------------------+ +/ c 100 */ c 0 i.5 0 1 2 3 4 10*i.5 0 10 20 30 40 c = 10*i.5 1 1 1 1 1 c -: 10 i.5 1
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Preserve the algorithm and functionality while converting the code from J to VB.
c =: 0 10 20 30 40 c, 50 0 10 20 30 40 50 _20 _10 , c _20 _10 0 10 20 30 40 ,~ c 0 10 20 30 40 0 10 20 30 40 ,:~ c 0 10 20 30 40 0 10 20 30 40 30 e. c 1 30 i.~c 3 30 80 e. c 1 0 2 1 4 2 { c 20 10 40 20 |.c 40 30 20 10 0 1+c 1 11 21 31 41 c%10 0 1 2 3 4 {. c 0 {: c 40 3{.c 0 10 20 3}.c 30 40 _3{.c 20 30 40 _3}.c 0 10 keys_map_ =: 'one';'two';'three' vals_map_ =: 'alpha';'beta';'gamma' lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen exists_map_ =: verb def 'y e. keys'&boxopen exists_map_ 'bad key' 0 exists_map_ 'two';'bad key' 1 0 lookup_map_ 'one' +-----+ |alpha| +-----+ lookup_map_ 'three';'one';'two';'one' +-----+-----+----+-----+ |gamma|alpha|beta|alpha| +-----+-----+----+-----+ lookup_map_ 'bad key' ++ || ++ 'some other default' lookup_map_ 'bad key' +------------------+ |some other default| +------------------+ 'some other default' lookup_map_ 'two';'bad key' +----+------------------+ |beta|some other default| +----+------------------+ +/ c 100 */ c 0 i.5 0 1 2 3 4 10*i.5 0 10 20 30 40 c = 10*i.5 1 1 1 1 1 c -: 10 i.5 1
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Convert this J snippet to Go and keep its semantics consistent.
c =: 0 10 20 30 40 c, 50 0 10 20 30 40 50 _20 _10 , c _20 _10 0 10 20 30 40 ,~ c 0 10 20 30 40 0 10 20 30 40 ,:~ c 0 10 20 30 40 0 10 20 30 40 30 e. c 1 30 i.~c 3 30 80 e. c 1 0 2 1 4 2 { c 20 10 40 20 |.c 40 30 20 10 0 1+c 1 11 21 31 41 c%10 0 1 2 3 4 {. c 0 {: c 40 3{.c 0 10 20 3}.c 30 40 _3{.c 20 30 40 _3}.c 0 10 keys_map_ =: 'one';'two';'three' vals_map_ =: 'alpha';'beta';'gamma' lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen exists_map_ =: verb def 'y e. keys'&boxopen exists_map_ 'bad key' 0 exists_map_ 'two';'bad key' 1 0 lookup_map_ 'one' +-----+ |alpha| +-----+ lookup_map_ 'three';'one';'two';'one' +-----+-----+----+-----+ |gamma|alpha|beta|alpha| +-----+-----+----+-----+ lookup_map_ 'bad key' ++ || ++ 'some other default' lookup_map_ 'bad key' +------------------+ |some other default| +------------------+ 'some other default' lookup_map_ 'two';'bad key' +----+------------------+ |beta|some other default| +----+------------------+ +/ c 100 */ c 0 i.5 0 1 2 3 4 10*i.5 0 10 20 30 40 c = 10*i.5 1 1 1 1 1 c -: 10 i.5 1
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Maintain the same structure and functionality when rewriting this code in C.
julia> collection = [] 0-element Array{Any,1} julia> push!(collection, 1,2,4,7) 4-element Array{Any,1}: 1 2 4 7
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Write the same code in C# as shown below in Julia.
julia> collection = [] 0-element Array{Any,1} julia> push!(collection, 1,2,4,7) 4-element Array{Any,1}: 1 2 4 7
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Ensure the translated C++ code behaves exactly like the original Julia snippet.
julia> collection = [] 0-element Array{Any,1} julia> push!(collection, 1,2,4,7) 4-element Array{Any,1}: 1 2 4 7
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Convert this Julia snippet to Java and keep its semantics consistent.
julia> collection = [] 0-element Array{Any,1} julia> push!(collection, 1,2,4,7) 4-element Array{Any,1}: 1 2 4 7
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Convert this Julia snippet to Python and keep its semantics consistent.
julia> collection = [] 0-element Array{Any,1} julia> push!(collection, 1,2,4,7) 4-element Array{Any,1}: 1 2 4 7
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])
Translate the given Julia code snippet into VB without altering its behavior.
julia> collection = [] 0-element Array{Any,1} julia> push!(collection, 1,2,4,7) 4-element Array{Any,1}: 1 2 4 7
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
Transform the following Julia implementation into Go, maintaining the same output and logic.
julia> collection = [] 0-element Array{Any,1} julia> push!(collection, 1,2,4,7) 4-element Array{Any,1}: 1 2 4 7
package main import "fmt" func main() { var a []interface{} a = append(a, 3) a = append(a, "apples", "oranges") fmt.Println(a) }
Rewrite the snippet below in C so it works the same as the original Lua code.
collection = {0, '1'} print(collection[1]) collection = {["foo"] = 0, ["bar"] = '1'} print(collection["foo"]) print(collection.foo) collection = {0, '1', ["foo"] = 0, ["bar"] = '1'}
#define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf("%d\n",*p); }
Convert the following code from Lua to C#, ensuring the logic remains intact.
collection = {0, '1'} print(collection[1]) collection = {["foo"] = 0, ["bar"] = '1'} print(collection["foo"]) print(collection.foo) collection = {0, '1', ["foo"] = 0, ["bar"] = '1'}
int[] intArray = new int[5] { 1, 2, 3, 4, 5 }; int[] intArray = new int[]{ 1, 2, 3, 4, 5 }; int[] intArray = { 1, 2, 3, 4, 5 }; string[] stringArr = new string[5]; stringArr[0] = "string";
Maintain the same structure and functionality when rewriting this code in C++.
collection = {0, '1'} print(collection[1]) collection = {["foo"] = 0, ["bar"] = '1'} print(collection["foo"]) print(collection.foo) collection = {0, '1', ["foo"] = 0, ["bar"] = '1'}
int a[5]; a[0] = 1; int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; #include <string> std::string strings[4];
Write the same code in Java as shown below in Lua.
collection = {0, '1'} print(collection[1]) collection = {["foo"] = 0, ["bar"] = '1'} print(collection["foo"]) print(collection.foo) collection = {0, '1', ["foo"] = 0, ["bar"] = '1'}
List arrayList = new ArrayList(); arrayList.add(new Integer(0)); arrayList.add(0); List<Integer> myarrlist = new ArrayList<Integer>(); int sum; for(int i = 0; i < 10; i++) { myarrlist.add(i); }
Translate this program into Python but keep the logic exactly as in Lua.
collection = {0, '1'} print(collection[1]) collection = {["foo"] = 0, ["bar"] = '1'} print(collection["foo"]) print(collection.foo) collection = {0, '1', ["foo"] = 0, ["bar"] = '1'}
collection = [0, '1'] x = collection[0] collection.append(2) collection.insert(0, '-1') y = collection[0] collection.extend([2,'3']) collection += [2,'3'] collection[2:6] len(collection) collection = (0, 1) collection[:] collection[-4:-1] collection[::2] collection="some string" x = collection[::-1] collection[::2] == "some string"[::2] collection.__getitem__(slice(0,len(collection),2)) collection = {0: "zero", 1: "one"} collection['zero'] = 2 collection = set([0, '1'])