Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Change the following Common_Lisp code into PHP without altering its purpose. | (defun flatten (tr)
(cond ((null tr) nil)
((atom tr) (list tr))
(t (append (flatten (first tr))
(flatten (rest tr))))))
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Write a version of this D function in PHP with identical behavior. | 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)) {
... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Change the following D code into PHP 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)) {
... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Produce a language-to-language conversion: from Elixir to PHP, same semantics. | 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)
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Can you help me rewrite this code in PHP 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)
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Write a version of this Erlang function in PHP with identical behavior. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Rewrite the snippet below in PHP so it works the same as the original Erlang code. | flatten([]) -> [];
flatten([H|T]) -> flatten(H) ++ flatten(T);
flatten(H) -> [H].
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Change the following F# code into PHP without altering its purpose. | 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([... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Convert this F# block to PHP, preserving its control flow 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([... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Convert this Forth snippet to PHP and keep its semantics consistent. |
:
then
drop
) a:each drop ;
: flatten
[] >r r> ;
[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
dup . cr
flatten
. cr
bye
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Please provide an equivalent version of this Forth code in PHP. |
:
then
drop
) a:each drop ;
: flatten
[] >r r> ;
[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
dup . cr
flatten
. cr
bye
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Change the following Fortran code into PHP without altering its purpose. |
module flat
implicit none
type n
integer :: a
type(n), dimension(:), pointer :: p => null()
logical :: empty = .false.
end type
contains
recursive subroutine del(this)
type(n), intent(inout) :: this
integer :: i... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Generate a PHP translation of this Fortran snippet without changing its computational steps. |
module flat
implicit none
type n
integer :: a
type(n), dimension(:), pointer :: p => null()
logical :: empty = .false.
end type
contains
recursive subroutine del(this)
type(n), intent(inout) :: this
integer :: i... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Maintain the same structure and functionality when rewriting this code in PHP. | assert [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []].flatten() == [1, 2, 3, 4, 5, 6, 7, 8]
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Transform the following Groovy implementation into PHP, maintaining the same output and logic. | assert [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []].flatten() == [1, 2, 3, 4, 5, 6, 7, 8]
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Can you help me rewrite this code in PHP instead of Haskell, keeping it the same logically? | import Graphics.Element exposing (show)
type Tree a
= Leaf a
| Node (List (Tree a))
flatten : Tree a -> List a
flatten tree =
case tree of
Leaf a -> [a]
Node list -> List.concatMap flatten list
tree : Tree Int
tree = Node
[ Node [Leaf 1]
, Leaf 2
, Node [Node [Leaf 3, Leaf 4], Leaf 5]
, Node [... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Write the same code in PHP as shown below in Haskell. | import Graphics.Element exposing (show)
type Tree a
= Leaf a
| Node (List (Tree a))
flatten : Tree a -> List a
flatten tree =
case tree of
Leaf a -> [a]
Node list -> List.concatMap flatten list
tree : Tree Int
tree = Node
[ Node [Leaf 1]
, Leaf 2
, Node [Node [Leaf 3, Leaf 4], Leaf 5]
, Node [... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Transform the following Icon implementation into PHP, maintaining the same output and logic. | link strings
procedure sflatten(s)
return pretrim(trim(compress(deletec(s,'[ ]'),',') ,','),',')
end
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Produce a language-to-language conversion: from Icon to PHP, same semantics. | link strings
procedure sflatten(s)
return pretrim(trim(compress(deletec(s,'[ ]'),',') ,','),',')
end
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Convert the following code from J to PHP, ensuring the logic remains intact. | flatten =: [: ; <S:0
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Write a version of this J function in PHP with identical behavior. | flatten =: [: ; <S:0
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Convert the following code from Julia to PHP, ensuring the logic remains intact. | isflat(x) = isempty(x) || first(x) === x
function flat_mapreduce(arr)
mapreduce(vcat, arr, init=[]) do x
isflat(x) ? x : flat(x)
end
end
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Preserve the algorithm and functionality while converting the code from Julia to PHP. | isflat(x) = isempty(x) || first(x) === x
function flat_mapreduce(arr)
mapreduce(vcat, arr, init=[]) do x
isflat(x) ? x : flat(x)
end
end
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Port the following code from Lua to PHP with equivalent syntax and logic. | function flatten(list)
if type(list) ~= "table" then return {list} end
local flat_list = {}
for _, elem in ipairs(list) do
for _, val in ipairs(flatten(elem)) do
flat_list[#flat_list + 1] = val
end
end
return flat_list
end
test_list = {{1}, 2, {{3,4}, 5}, {{{}}}, {{{6}}}, 7, 8, {}}
print(table... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Produce a language-to-language conversion: from Lua to PHP, same semantics. | function flatten(list)
if type(list) ~= "table" then return {list} end
local flat_list = {}
for _, elem in ipairs(list) do
for _, val in ipairs(flatten(elem)) do
flat_list[#flat_list + 1] = val
end
end
return flat_list
end
test_list = {{1}, 2, {{3,4}, 5}, {{{}}}, {{{6}}}, 7, 8, {}}
print(table... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Keep all operations the same but rewrite the snippet in PHP. | Flatten[{{1}, 2, {{3, 4}, 5}, {{{}}}, {{{6}}}, 7, 8, {}}]
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Maintain the same structure and functionality when rewriting this code in PHP. | Flatten[{{1}, 2, {{3, 4}, 5}, {{{}}}, {{{6}}}, 7, 8, {}}]
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Write the same code in PHP as shown below in Nim. | type
TreeList[T] = object
case isLeaf: bool
of true: data: T
of false: list: seq[TreeList[T]]
proc L[T](list: varargs[TreeList[T]]): TreeList[T] =
for x in list:
result.list.add x
proc N[T](data: T): TreeList[T] =
TreeList[T](isLeaf: true, data: data)
proc flatten[T](n: TreeList[T]): seq[T] =
... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Port the following code from Nim to PHP with equivalent syntax and logic. | type
TreeList[T] = object
case isLeaf: bool
of true: data: T
of false: list: seq[TreeList[T]]
proc L[T](list: varargs[TreeList[T]]): TreeList[T] =
for x in list:
result.list.add x
proc N[T](data: T): TreeList[T] =
TreeList[T](isLeaf: true, data: data)
proc flatten[T](n: TreeList[T]): seq[T] =
... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Write a version of this OCaml function in PHP with identical behavior. | # let flatten = List.concat ;;
val flatten : 'a list list -> 'a list = <fun>
# let li = [[1]; 2; [[3;4]; 5]; [[[]]]; [[[6]]]; 7; 8; []] ;;
^^^
Error: This expression has type int but is here used with type int list
#
flatten [[1]; [2; 3; 4]; []; [5; 6]; [7]; [8]] ;;
- : int list = [1; 2; 3; 4; 5; 6... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Rewrite this program in PHP while keeping its functionality equivalent to the OCaml version. | # let flatten = List.concat ;;
val flatten : 'a list list -> 'a list = <fun>
# let li = [[1]; 2; [[3;4]; 5]; [[[]]]; [[[6]]]; 7; 8; []] ;;
^^^
Error: This expression has type int but is here used with type int list
#
flatten [[1]; [2; 3; 4]; []; [5; 6]; [7]; [8]] ;;
- : int list = [1; 2; 3; 4; 5; 6... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Produce a functionally identical PHP code for the snippet given in Perl. | sub flatten {
map { ref eq 'ARRAY' ? flatten(@$_) : $_ } @_
}
my @lst = ([1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []);
print flatten(@lst), "\n";
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Transform the following Perl implementation into PHP, maintaining the same output and logic. | sub flatten {
map { ref eq 'ARRAY' ? flatten(@$_) : $_ } @_
}
my @lst = ([1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []);
print flatten(@lst), "\n";
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Maintain the same structure and functionality when rewriting this code in PHP. | function flatten($a) {
if($a.Count -gt 1) {
$a | foreach{ $(flatten $_)}
} else {$a}
}
$a = @(@(1), 2, @(@(3,4), 5), @(@(@())), @(@(@(6))), 7, 8, @())
"$(flatten $a)"
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Rewrite this program in PHP while keeping its functionality equivalent to the PowerShell version. | function flatten($a) {
if($a.Count -gt 1) {
$a | foreach{ $(flatten $_)}
} else {$a}
}
$a = @(@(1), 2, @(@(3,4), 5), @(@(@())), @(@(@(6))), 7, 8, @())
"$(flatten $a)"
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Translate this program into PHP but keep the logic exactly as in R. | x <- list(list(1), 2, list(list(3, 4), 5), list(list(list())), list(list(list(6))), 7, 8, list())
unlist(x)
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Rewrite this program in PHP while keeping its functionality equivalent to the R version. | x <- list(list(1), 2, list(list(3, 4), 5), list(list(list())), list(list(list(6))), 7, 8, list())
unlist(x)
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Keep all operations the same but rewrite the snippet in PHP. | #lang racket
(flatten '(1 (2 (3 4 5) (6 7)) 8 9))
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Port the provided Racket code into PHP while preserving the original functionality. | #lang racket
(flatten '(1 (2 (3 4 5) (6 7)) 8 9))
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Rewrite the snippet below in PHP so it works the same as the original REXX code. | sub1 = .array~of(1)
sub2 = .array~of(3, 4)
sub3 = .array~of(sub2, 5)
sub4 = .array~of(.array~of(.array~new))
sub5 = .array~of(.array~of(.array~of(6)))
sub6 = .array~new
-- final list construction
list = .array~of(sub1, 2, sub3, sub4, sub5, 7, 8, sub6)
-- flatten
flatlist = flattenList(list)
say "["flatlist~toString(... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Keep all operations the same but rewrite the snippet in PHP. | sub1 = .array~of(1)
sub2 = .array~of(3, 4)
sub3 = .array~of(sub2, 5)
sub4 = .array~of(.array~of(.array~new))
sub5 = .array~of(.array~of(.array~of(6)))
sub6 = .array~new
-- final list construction
list = .array~of(sub1, 2, sub3, sub4, sub5, 7, 8, sub6)
-- flatten
flatlist = flattenList(list)
say "["flatlist~toString(... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Rewrite the snippet below in PHP so it works the same as the original Ruby code. | [[1], 2, [[3, 4], 5], [[[] of Int32]], [[[6]]], 7, 8, [] of Int32].flatten()
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Write the same code in PHP as shown below in Ruby. | [[1], 2, [[3, 4], 5], [[[] of Int32]], [[[6]]], 7, 8, [] of Int32].flatten()
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Generate a PHP translation of this Scala snippet without changing its computational steps. |
@Suppress("UNCHECKED_CAST")
fun flattenList(nestList: List<Any>, flatList: MutableList<Int>) {
for (e in nestList)
if (e is Int)
flatList.add(e)
else
flattenList(e as List<Any>, flatList)
}
fun main(args: Array<String>) {
val nestList : List<... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Translate the given Scala code snippet into PHP without altering its behavior. |
@Suppress("UNCHECKED_CAST")
fun flattenList(nestList: List<Any>, flatList: MutableList<Int>) {
for (e in nestList)
if (e is Int)
flatList.add(e)
else
flattenList(e as List<Any>, flatList)
}
fun main(args: Array<String>) {
val nestList : List<... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Generate a PHP translation of this Swift snippet without changing its computational steps. | func list(s: Any...) -> [Any] {
return s
}
func flatten<T>(s: [Any]) -> [T] {
var r = [T]()
for e in s {
switch e {
case let a as [Any]:
r += flatten(a)
case let x as T:
r.append(x)
default:
assert(false, "value of wrong type")
}
}
return r
}
let s = list(list(1),
2,
... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Ensure the translated PHP code behaves exactly like the original Swift snippet. | func list(s: Any...) -> [Any] {
return s
}
func flatten<T>(s: [Any]) -> [T] {
var r = [T]()
for e in s {
switch e {
case let a as [Any]:
r += flatten(a)
case let x as T:
r.append(x)
default:
assert(false, "value of wrong type")
}
}
return r
}
let s = list(list(1),
2,
... |
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Rewrite the snippet below in PHP so it works the same as the original Tcl code. | proc flatten list {
for {set old {}} {$old ne $list} {} {
set old $list
set list [join $list]
}
return $list
}
puts [flatten {{1} 2 {{3 4} 5} {{{}}} {{{6}}} 7 8 {}}]
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Generate a PHP translation of this Tcl snippet without changing its computational steps. | proc flatten list {
for {set old {}} {$old ne $list} {} {
set old $list
set list [join $list]
}
return $list
}
puts [flatten {{1} 2 {{3 4} 5} {{{}}} {{{6}}} 7 8 {}}]
|
while (array_filter($lst, 'is_array'))
$lst = call_user_func_array('array_merge', $lst);
|
Change the following C code into Rust without altering its purpose. | #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... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Convert this C++ snippet to Rust and keep its semantics consistent. | #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;
... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Generate a Rust translation of this C# snippet without changing its computational steps. | 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... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Translate the given Go code snippet into Rust without altering its behavior. | 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... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Rewrite the snippet below in Python so it works the same as the original Rust code. | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... | >>> 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 Rust snippet to Python and keep its semantics consistent. | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... | >>> 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]
|
Translate this program into VB but keep the logic exactly as in Rust. | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... | 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 VB so it works the same as the original Rust code. | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... | 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 Rust. | 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 (... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Translate the given Java code snippet into Rust without altering its behavior. | 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 (... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Maintain the same structure and functionality when rewriting this code in Rust. | 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... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Rewrite the snippet below in Rust so it works the same as the original C code. | #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... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Can you help me rewrite this code in Rust instead of C++, keeping it the same logically? | #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;
... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Preserve the algorithm and functionality while converting the code from C# to Rust. | 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... | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
Convert this Ada block to C#, preserving its control flow and logic. | with Ada.Calendar.Formatting;
package Printable_Calendar is
subtype String20 is String(1 .. 20);
type Month_Rep_Type is array (Ada.Calendar.Month_Number) of String20;
type Description is record
Weekday_Rep: String20;
Month_Rep: Month_Rep_Type;
end record;
Default_Description: constant... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Please provide an equivalent version of this Ada code in C. | with Ada.Calendar.Formatting;
package Printable_Calendar is
subtype String20 is String(1 .. 20);
type Month_Rep_Type is array (Ada.Calendar.Month_Number) of String20;
type Description is record
Weekday_Rep: String20;
Month_Rep: Month_Rep_Type;
end record;
Default_Description: constant... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Maintain the same structure and functionality when rewriting this code in C++. | with Ada.Calendar.Formatting;
package Printable_Calendar is
subtype String20 is String(1 .. 20);
type Month_Rep_Type is array (Ada.Calendar.Month_Number) of String20;
type Description is record
Weekday_Rep: String20;
Month_Rep: Month_Rep_Type;
end record;
Default_Description: constant... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Write a version of this Ada function in Go with identical behavior. | with Ada.Calendar.Formatting;
package Printable_Calendar is
subtype String20 is String(1 .. 20);
type Month_Rep_Type is array (Ada.Calendar.Month_Number) of String20;
type Description is record
Weekday_Rep: String20;
Month_Rep: Month_Rep_Type;
end record;
Default_Description: constant... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Write the same code in Java as shown below in Ada. | with Ada.Calendar.Formatting;
package Printable_Calendar is
subtype String20 is String(1 .. 20);
type Month_Rep_Type is array (Ada.Calendar.Month_Number) of String20;
type Description is record
Weekday_Rep: String20;
Month_Rep: Month_Rep_Type;
end record;
Default_Description: constant... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Preserve the algorithm and functionality while converting the code from Ada to Python. | with Ada.Calendar.Formatting;
package Printable_Calendar is
subtype String20 is String(1 .. 20);
type Month_Rep_Type is array (Ada.Calendar.Month_Number) of String20;
type Description is record
Weekday_Rep: String20;
Month_Rep: Month_Rep_Type;
end record;
Default_Description: constant... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Produce a functionally identical VB code for the snippet given in Ada. | with Ada.Calendar.Formatting;
package Printable_Calendar is
subtype String20 is String(1 .. 20);
type Month_Rep_Type is array (Ada.Calendar.Month_Number) of String20;
type Description is record
Weekday_Rep: String20;
Month_Rep: Month_Rep_Type;
end record;
Default_Description: constant... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Can you help me rewrite this code in C instead of Arturo, keeping it the same logically? | Rebol []
do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year]
foreach m system/locale/months [
prin rejoin ["^/^/ " m "^/^/ "]
foreach day system/locale/days [prin join copy/part day 2 " "]
print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "]
repeat i 31 [
if attempt... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Transform the following Arturo implementation into C#, maintaining the same output and logic. | Rebol []
do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year]
foreach m system/locale/months [
prin rejoin ["^/^/ " m "^/^/ "]
foreach day system/locale/days [prin join copy/part day 2 " "]
print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "]
repeat i 31 [
if attempt... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Write the same code in C++ as shown below in Arturo. | Rebol []
do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year]
foreach m system/locale/months [
prin rejoin ["^/^/ " m "^/^/ "]
foreach day system/locale/days [prin join copy/part day 2 " "]
print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "]
repeat i 31 [
if attempt... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Translate this program into Java but keep the logic exactly as in Arturo. | Rebol []
do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year]
foreach m system/locale/months [
prin rejoin ["^/^/ " m "^/^/ "]
foreach day system/locale/days [prin join copy/part day 2 " "]
print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "]
repeat i 31 [
if attempt... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Preserve the algorithm and functionality while converting the code from Arturo to Python. | Rebol []
do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year]
foreach m system/locale/months [
prin rejoin ["^/^/ " m "^/^/ "]
foreach day system/locale/days [prin join copy/part day 2 " "]
print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "]
repeat i 31 [
if attempt... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Please provide an equivalent version of this Arturo code in VB. | Rebol []
do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year]
foreach m system/locale/months [
prin rejoin ["^/^/ " m "^/^/ "]
foreach day system/locale/days [prin join copy/part day 2 " "]
print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "]
repeat i 31 [
if attempt... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Transform the following Arturo implementation into Go, maintaining the same output and logic. | Rebol []
do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year]
foreach m system/locale/months [
prin rejoin ["^/^/ " m "^/^/ "]
foreach day system/locale/days [prin join copy/part day 2 " "]
print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "]
repeat i 31 [
if attempt... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Port the provided AutoHotKey code into C while preserving the original functionality. | Calendar(Yr){
LastDay := [], Day := []
Titles =
(ltrim
______January_________________February_________________March_______
_______April____________________May____________________June________
________July___________________August_________________September_____
______October_________________November_______________... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Write the same code in C# as shown below in AutoHotKey. | Calendar(Yr){
LastDay := [], Day := []
Titles =
(ltrim
______January_________________February_________________March_______
_______April____________________May____________________June________
________July___________________August_________________September_____
______October_________________November_______________... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Ensure the translated C++ code behaves exactly like the original AutoHotKey snippet. | Calendar(Yr){
LastDay := [], Day := []
Titles =
(ltrim
______January_________________February_________________March_______
_______April____________________May____________________June________
________July___________________August_________________September_____
______October_________________November_______________... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Can you help me rewrite this code in Java instead of AutoHotKey, keeping it the same logically? | Calendar(Yr){
LastDay := [], Day := []
Titles =
(ltrim
______January_________________February_________________March_______
_______April____________________May____________________June________
________July___________________August_________________September_____
______October_________________November_______________... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Keep all operations the same but rewrite the snippet in Python. | Calendar(Yr){
LastDay := [], Day := []
Titles =
(ltrim
______January_________________February_________________March_______
_______April____________________May____________________June________
________July___________________August_________________September_____
______October_________________November_______________... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Rewrite this program in VB while keeping its functionality equivalent to the AutoHotKey version. | Calendar(Yr){
LastDay := [], Day := []
Titles =
(ltrim
______January_________________February_________________March_______
_______April____________________May____________________June________
________July___________________August_________________September_____
______October_________________November_______________... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Write a version of this AutoHotKey function in Go with identical behavior. | Calendar(Yr){
LastDay := [], Day := []
Titles =
(ltrim
______January_________________February_________________March_______
_______April____________________May____________________June________
________July___________________August_________________September_____
______October_________________November_______________... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Please provide an equivalent version of this AWK code in C. | Works with Gnu awk version 3.1.5 and with BusyBox v1.20.0.git awk
To change the output width, change the value assigned to variable pagewide
BEGIN{
wkdays = "Su Mo Tu We Th Fr Sa"
pagewide = 80
blank=" "
for (i=1; i<pagewide; i++) blank = blank " "
month= " January February March Apr... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Change the programming language of this snippet from AWK to C# without modifying what it does. | Works with Gnu awk version 3.1.5 and with BusyBox v1.20.0.git awk
To change the output width, change the value assigned to variable pagewide
BEGIN{
wkdays = "Su Mo Tu We Th Fr Sa"
pagewide = 80
blank=" "
for (i=1; i<pagewide; i++) blank = blank " "
month= " January February March Apr... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Keep all operations the same but rewrite the snippet in C++. | Works with Gnu awk version 3.1.5 and with BusyBox v1.20.0.git awk
To change the output width, change the value assigned to variable pagewide
BEGIN{
wkdays = "Su Mo Tu We Th Fr Sa"
pagewide = 80
blank=" "
for (i=1; i<pagewide; i++) blank = blank " "
month= " January February March Apr... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Write a version of this AWK function in Python with identical behavior. | Works with Gnu awk version 3.1.5 and with BusyBox v1.20.0.git awk
To change the output width, change the value assigned to variable pagewide
BEGIN{
wkdays = "Su Mo Tu We Th Fr Sa"
pagewide = 80
blank=" "
for (i=1; i<pagewide; i++) blank = blank " "
month= " January February March Apr... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Port the following code from AWK to VB with equivalent syntax and logic. | Works with Gnu awk version 3.1.5 and with BusyBox v1.20.0.git awk
To change the output width, change the value assigned to variable pagewide
BEGIN{
wkdays = "Su Mo Tu We Th Fr Sa"
pagewide = 80
blank=" "
for (i=1; i<pagewide; i++) blank = blank " "
month= " January February March Apr... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Translate the given AWK code snippet into Go without altering its behavior. | Works with Gnu awk version 3.1.5 and with BusyBox v1.20.0.git awk
To change the output width, change the value assigned to variable pagewide
BEGIN{
wkdays = "Su Mo Tu We Th Fr Sa"
pagewide = 80
blank=" "
for (i=1; i<pagewide; i++) blank = blank " "
month= " January February March Apr... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Translate this program into C but keep the logic exactly as in BBC_Basic. | INSTALL @lib$+"DATELIB"
VDU 23,22,640;570;8,15,16,128
year% = 1969
PRINT TAB(38); year%
DIM dom%(2), mjd%(2), dim%(2)
FOR day% = 1 TO 7
days$ += LEFT$(FN_date$(FN_mjd(day%, 1, 1905), "ddd"), 2) + " "
NEXT
FOR month% = 1 TO 10 STEP 3
PR... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Change the following BBC_Basic code into C# without altering its purpose. | INSTALL @lib$+"DATELIB"
VDU 23,22,640;570;8,15,16,128
year% = 1969
PRINT TAB(38); year%
DIM dom%(2), mjd%(2), dim%(2)
FOR day% = 1 TO 7
days$ += LEFT$(FN_date$(FN_mjd(day%, 1, 1905), "ddd"), 2) + " "
NEXT
FOR month% = 1 TO 10 STEP 3
PR... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Translate the given BBC_Basic code snippet into C++ without altering its behavior. | INSTALL @lib$+"DATELIB"
VDU 23,22,640;570;8,15,16,128
year% = 1969
PRINT TAB(38); year%
DIM dom%(2), mjd%(2), dim%(2)
FOR day% = 1 TO 7
days$ += LEFT$(FN_date$(FN_mjd(day%, 1, 1905), "ddd"), 2) + " "
NEXT
FOR month% = 1 TO 10 STEP 3
PR... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Rewrite the snippet below in Java so it works the same as the original BBC_Basic code. | INSTALL @lib$+"DATELIB"
VDU 23,22,640;570;8,15,16,128
year% = 1969
PRINT TAB(38); year%
DIM dom%(2), mjd%(2), dim%(2)
FOR day% = 1 TO 7
days$ += LEFT$(FN_date$(FN_mjd(day%, 1, 1905), "ddd"), 2) + " "
NEXT
FOR month% = 1 TO 10 STEP 3
PR... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Can you help me rewrite this code in Python instead of BBC_Basic, keeping it the same logically? | INSTALL @lib$+"DATELIB"
VDU 23,22,640;570;8,15,16,128
year% = 1969
PRINT TAB(38); year%
DIM dom%(2), mjd%(2), dim%(2)
FOR day% = 1 TO 7
days$ += LEFT$(FN_date$(FN_mjd(day%, 1, 1905), "ddd"), 2) + " "
NEXT
FOR month% = 1 TO 10 STEP 3
PR... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Convert this BBC_Basic block to VB, preserving its control flow and logic. | INSTALL @lib$+"DATELIB"
VDU 23,22,640;570;8,15,16,128
year% = 1969
PRINT TAB(38); year%
DIM dom%(2), mjd%(2), dim%(2)
FOR day% = 1 TO 7
days$ += LEFT$(FN_date$(FN_mjd(day%, 1, 1905), "ddd"), 2) + " "
NEXT
FOR month% = 1 TO 10 STEP 3
PR... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Ensure the translated Go code behaves exactly like the original BBC_Basic snippet. | INSTALL @lib$+"DATELIB"
VDU 23,22,640;570;8,15,16,128
year% = 1969
PRINT TAB(38); year%
DIM dom%(2), mjd%(2), dim%(2)
FOR day% = 1 TO 7
days$ += LEFT$(FN_date$(FN_mjd(day%, 1, 1905), "ddd"), 2) + " "
NEXT
FOR month% = 1 TO 10 STEP 3
PR... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Produce a language-to-language conversion: from Clojure to C, same semantics. | (require '[clojure.string :only [join] :refer [join]])
(def day-row "Su Mo Tu We Th Fr Sa")
(def col-width (count day-row))
(defn month-to-word
"Translate a month from 0 to 11 into its word representation."
[month]
((vec (.getMonths (new java.text.DateFormatSymbols))) month))
(defn month [date]
(.get date ... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Preserve the algorithm and functionality while converting the code from Clojure to C#. | (require '[clojure.string :only [join] :refer [join]])
(def day-row "Su Mo Tu We Th Fr Sa")
(def col-width (count day-row))
(defn month-to-word
"Translate a month from 0 to 11 into its word representation."
[month]
((vec (.getMonths (new java.text.DateFormatSymbols))) month))
(defn month [date]
(.get date ... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Please provide an equivalent version of this Clojure code in C++. | (require '[clojure.string :only [join] :refer [join]])
(def day-row "Su Mo Tu We Th Fr Sa")
(def col-width (count day-row))
(defn month-to-word
"Translate a month from 0 to 11 into its word representation."
[month]
((vec (.getMonths (new java.text.DateFormatSymbols))) month))
(defn month [date]
(.get date ... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.