Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Generate a C# translation of this Arturo snippet without changing its computational steps. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Port the provided Arturo code into C# while preserving the original functionality. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Maintain the same structure and functionality when rewriting this code in C++. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Port the following code from Arturo to C++ with equivalent syntax and logic. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Convert this Arturo block to Java, preserving its control flow and logic. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Port the following code from Arturo to Java with equivalent syntax and logic. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Generate a Python translation of this Arturo snippet without changing its computational steps. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Convert this Arturo snippet to Python and keep its semantics consistent. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Transform the following Arturo implementation into VB, maintaining the same output and logic. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Produce a language-to-language conversion: from Arturo to VB, same semantics. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Rewrite the snippet below in Go so it works the same as the original Arturo code. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Produce a functionally identical Go code for the snippet given in Arturo. | print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Ensure the translated C code behaves exactly like the original AutoHotKey snippet. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Rewrite this program in C while keeping its functionality equivalent to the AutoHotKey version. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Ensure the translated C# code behaves exactly like the original AutoHotKey snippet. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Maintain the same structure and functionality when rewriting this code in C#. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Rewrite this program in C++ while keeping its functionality equivalent to the AutoHotKey version. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Produce a functionally identical C++ code for the snippet given in AutoHotKey. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Change the following AutoHotKey code into Java without altering its purpose. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Transform the following AutoHotKey implementation into Java, maintaining the same output and logic. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Write the same code in Python as shown below in AutoHotKey. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Generate an equivalent Python version of this AutoHotKey code. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Write the same code in VB as shown below in AutoHotKey. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Keep all operations the same but rewrite the snippet in VB. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Translate the given AutoHotKey code snippet into Go without altering its behavior. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Generate an equivalent Go version of this AutoHotKey code. | list := object(1, object(1, 1), 2, 2, 3, object(1, object(1, 3, 2, 4)
, 2, 5), 4, object(1, object(1, object(1, object()))), 5
, object(1, object(1, 6)), 6, 7, 7, 8, 9, object())
msgbox % objPrint(list)
msgbox % objPrint(objFlatten(list))
return
!r::reload
!q::exitapp
objPrint(ast, reserved=0)
{
if !isobject(ast)... | package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Ensure the translated C code behaves exactly like the original Clojure snippet. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Please provide an equivalent version of this Clojure code in C. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Produce a language-to-language conversion: from Clojure to C#, same semantics. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Translate this program into C# but keep the logic exactly as in Clojure. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Translate the given Clojure code snippet into C++ without altering its behavior. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Convert this Clojure snippet to C++ and keep its semantics consistent. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Translate this program into Java but keep the logic exactly as in Clojure. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Change the programming language of this snippet from Clojure to Java without modifying what it does. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Keep all operations the same but rewrite the snippet in Python. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Port the following code from Clojure to Python with equivalent syntax and logic. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Produce a language-to-language conversion: from Clojure to VB, same semantics. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Please provide an equivalent version of this Clojure code in VB. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Write a version of this Clojure function in Go with identical behavior. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Maintain the same structure and functionality when rewriting this code in Go. | (defn flatten [lst]
(sum (genexpr (if (isinstance x list)
(flatten x)
[x])
[x lst])
[]))
(print (flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]))
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Generate a C translation of this Common_Lisp snippet without changing its computational steps. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Port the following code from Common_Lisp to C with equivalent syntax and logic. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Write the same code in C# as shown below in Common_Lisp. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Produce a functionally identical C# code for the snippet given in Common_Lisp. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Convert the following code from Common_Lisp to C++, ensuring the logic remains intact. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Write the same algorithm in C++ as shown in this Common_Lisp implementation. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Convert the following code from Common_Lisp to Java, ensuring the logic remains intact. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Change the programming language of this snippet from Common_Lisp to Java without modifying what it does. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Port the following code from Common_Lisp to Python with equivalent syntax and logic. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Transform the following Common_Lisp implementation into Python, maintaining the same output and logic. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Rewrite the snippet below in VB so it works the same as the original Common_Lisp code. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Rewrite this program in VB while keeping its functionality equivalent to the Common_Lisp version. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Rewrite the snippet below in Go so it works the same as the original Common_Lisp code. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Change the programming language of this snippet from Common_Lisp to Go without modifying what it does. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Preserve the algorithm and functionality while converting the code from D to C. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Convert the following code from D to C, ensuring the logic remains intact. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Preserve the algorithm and functionality while converting the code from D to C#. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Write the same algorithm in C# as shown in this D implementation. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Convert this D snippet to C++ and keep its semantics consistent. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Keep all operations the same but rewrite the snippet in C++. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Write the same algorithm in Java as shown in this D implementation. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Maintain the same structure and functionality when rewriting this code in Java. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Convert this D block to Python, preserving its control flow and logic. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Write the same code in Python as shown below in D. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Maintain the same structure and functionality when rewriting this code in VB. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Can you help me rewrite this code in VB instead of D, keeping it the same logically? | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Port the provided D code into Go while preserving the original functionality. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Change the following D code into Go without altering its purpose. | import std.stdio, std.algorithm, std.conv, std.range;
struct TreeList(T) {
union {
TreeList[] arr;
T data;
}
bool isArray = true;
static TreeList opCall(A...)(A items) pure nothrow {
TreeList result;
foreach (i, el; items)
static if (is(A[i] == T)) {
... | package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Translate this program into C but keep the logic exactly as in Elixir. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Write a version of this Elixir function in C with identical behavior. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Write the same algorithm in C# as shown in this Elixir implementation. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Please provide an equivalent version of this Elixir code in C#. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Write a version of this Elixir function in C++ with identical behavior. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Port the provided Elixir code into C++ while preserving the original functionality. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Generate a Java translation of this Elixir snippet without changing its computational steps. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Rewrite the snippet below in Java so it works the same as the original Elixir code. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Translate the given Elixir code snippet into Python without altering its behavior. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Generate an equivalent Python version of this Elixir code. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Please provide an equivalent version of this Elixir code in VB. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Generate a VB translation of this Elixir snippet without changing its computational steps. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Can you help me rewrite this code in Go instead of Elixir, keeping it the same logically? | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Translate this program into Go but keep the logic exactly as in Elixir. | defmodule RC do
def flatten([]), do: []
def flatten([h|t]), do: flatten(h) ++ flatten(t)
def flatten(h), do: [h]
end
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
IO.inspect RC.flatten(list)
IO.inspect List.flatten(list)
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Generate an equivalent C version of this Erlang code. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Transform the following Erlang implementation into C, maintaining the same output and logic. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Write a version of this Erlang function in C# with identical behavior. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Preserve the algorithm and functionality while converting the code from Erlang to C#. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Port the provided Erlang code into C++ while preserving the original functionality. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Translate this program into C++ but keep the logic exactly as in Erlang. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| #include <list>
#include <boost/any.hpp>
typedef std::list<boost::any> anylist;
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
... |
Convert the following code from Erlang to Java, ensuring the logic remains intact. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Port the following code from Erlang to Java with equivalent syntax and logic. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| import java.util.LinkedList;
import java.util.List;
public final class FlattenUtil {
public static List<Object> flatten(List<?> list) {
List<Object> retVal = new LinkedList<Object>();
flatten(list, retVal);
return retVal;
}
public static void flatten(List<?> fromTreeList, List<Object> toFlatList) {
for (... |
Generate a Python translation of this Erlang snippet without changing its computational steps. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Generate an equivalent Python version of this Erlang code. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8]
|
Rewrite the snippet below in VB so it works the same as the original Erlang code. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Maintain the same structure and functionality when rewriting this code in VB. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| class flattener
dim separator
sub class_initialize
separator = ","
end sub
private function makeflat( a )
dim i
dim res
for i = lbound( a ) to ubound( a )
if isarray( a( i ) ) then
res = res & makeflat( a( i ) )
else
res = res & a( i ) & separator
end if
next
makeflat = res
end f... |
Produce a functionally identical Go code for the snippet given in Erlang. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Keep all operations the same but rewrite the snippet in Go. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
| package main
import "fmt"
func list(s ...interface{}) []interface{} {
return s
}
func main() {
s := list(list(1),
2,
list(list(3, 4), 5),
list(list(list())),
list(list(list(6))),
7,
8,
list(),
)
fmt.Println(s)
fmt.Println(flatten(s))
}
func... |
Produce a language-to-language conversion: from F# to C, same semantics. | type 'a ll =
| I of 'a
| L of 'a ll list
let rec flatten = function
| [] -> []
| (I x)::y -> x :: (flatten y)
| (L x)::y -> List.append (flatten x) (flatten y)
printfn "%A" (flatten [L([I(1)]); I(2); L([L([I(3);I(4)]); I(5)]); L([L([L([])])]); L([L([L([I(6)])])]); I(7); I(8); L([... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Rewrite this program in C while keeping its functionality equivalent to the F# version. | type 'a ll =
| I of 'a
| L of 'a ll list
let rec flatten = function
| [] -> []
| (I x)::y -> x :: (flatten y)
| (L x)::y -> List.append (flatten x) (flatten y)
printfn "%A" (flatten [L([I(1)]); I(2); L([L([I(3);I(4)]); I(5)]); L([L([L([])])]); L([L([L([I(6)])])]); I(7); I(8); L([... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc... |
Transform the following F# implementation into C#, maintaining the same output and logic. | type 'a ll =
| I of 'a
| L of 'a ll list
let rec flatten = function
| [] -> []
| (I x)::y -> x :: (flatten y)
| (L x)::y -> List.append (flatten x) (flatten y)
printfn "%A" (flatten [L([I(1)]); I(2); L([L([I(3);I(4)]); I(5)]); L([L([L([])])]); L([L([L([I(6)])])]); I(7); I(8); L([... | using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Produce a language-to-language conversion: from F# to C#, same semantics. | type 'a ll =
| I of 'a
| L of 'a ll list
let rec flatten = function
| [] -> []
| (I x)::y -> x :: (flatten y)
| (L x)::y -> List.append (flatten x) (flatten y)
printfn "%A" (flatten [L([I(1)]); I(2); L([L([I(3);I(4)]); I(5)]); L([L([L([])])]); L([L([L([I(6)])])]); I(7); I(8); L([... | using System;
using System.Collections;
using System.Linq;
namespace RosettaCodeTasks
{
static class FlattenList
{
public static ArrayList Flatten(this ArrayList List)
{
ArrayList NewList = new ArrayList ( );
NewList.AddRange ( List );
while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 )
{
int... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.