Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Ensure the translated PHP code behaves exactly like the original Julia snippet. | x = [1, 2, 3, 7]
parr = pointer(x)
xx = unsafe_load(parr, 4)
println(xx)
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Generate an equivalent PHP version of this Lua code. | local table1 = {1,2,3}
local table2 = table1
table2[3] = 4
print(unpack(table1))
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Port the provided Nim code into PHP while preserving the original functionality. | type Foo = ref object
x, y: float
var f: Foo
new f
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Ensure the translated PHP code behaves exactly like the original OCaml snippet. | let p = ref 1;;
let k = !p;;
p := k + 1;;
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Preserve the algorithm and functionality while converting the code from Pascal to PHP. | program pointerDemo;
type
integerReference = ^integer;
var
integerLocation: integerReference;
begin
new(integerLocation);
integerLocation^ := 42;
dispose(integerLocation);
end.
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Port the following code from Perl to PHP with equivalent syntax and logic. |
my $scalar = 'aa';
my @array = ('bb', 'cc');
my %hash = ( dd => 'DD', ee => 'EE' );
my $scalarref = \$scalar;
my $arrayref = \@array;
my $hashref = \%hash;
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Write a version of this Racket function in PHP with identical behavior. | #lang racket
(define (inc! b) (set-box! b (add1 (unbox b))))
(define b (box 0))
(inc! b)
(inc! b)
(inc! b)
(unbox b)
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Rewrite the snippet below in PHP so it works the same as the original COBOL code. | 01 ptr USAGE POINTER TO Some-Type.
01 prog-ptr USAGE PROGRAM-POINTER "some-program".
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Convert this REXX block to PHP, preserving its control flow and logic. | ::class Foo
::method init
expose x
x = 0
::attribute x
::routine somefunction
a = .Foo~new -- assigns a to point to a new Foo object
b = a -- b and a now point to the same object
a~x = 5 -- modifies the X variable inside the object pointer to by a
say b~x -... | <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Preserve the algorithm and functionality while converting the code from Ruby to PHP. | func assign2ref(ref, value) {
*ref = value;
}
var x = 10;
assign2ref(\x, 20);
say x;
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Port the provided Scala code into PHP while preserving the original functionality. |
import kotlinx.cinterop.*
fun main(args: Array<String>) {
val intVar: IntVar = nativeHeap.alloc<IntVar>()
intVar.value = 3
println(intVar.value)
println(intVar.ptr)
println(intVar.rawPtr)
intVar.value = 333
println()
pri... | <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Ensure the translated PHP code behaves exactly like the original Tcl snippet. | set var 3
set pointer var;
set pointer;
set $pointer;
set $pointer 42;
| <?php
$a = 1;
$b =& $a; // $b and $a are now linked together
$b = 2; //both $b and $a now equal 2
$c = $b;
$c = 7; //$c is not a reference; no change to $a or $b
unset($a); //won't unset $b, just $a.
function &pass_out() {
global $filestr; //$exactly equivalent to: $filestr =& $_GLOBALS['filestr'];
$filest... |
Can you help me rewrite this code in C# instead of Ada, keeping it the same logically? | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Change the following Ada code into C without altering its purpose. | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Write the same algorithm in C++ as shown in this Ada implementation. | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Transform the following Ada implementation into Go, maintaining the same output and logic. | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Write the same code in Java as shown below in Ada. | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Preserve the algorithm and functionality while converting the code from Ada to Python. | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Please provide an equivalent version of this Ada code in VB. | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Produce a functionally identical C code for the snippet given in Arturo. | sierpinski: function [order][
s: shl 1 order
loop (s-1)..0 'y [
do.times: y -> prints " "
loop 0..dec s-y 'x [
if? zero? and x y -> prints "* "
else -> prints " "
]
print ""
]
]
sierpinski 4
| #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in C#. | sierpinski: function [order][
s: shl 1 order
loop (s-1)..0 'y [
do.times: y -> prints " "
loop 0..dec s-y 'x [
if? zero? and x y -> prints "* "
else -> prints " "
]
print ""
]
]
sierpinski 4
| using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Translate this program into C++ but keep the logic exactly as in Arturo. | sierpinski: function [order][
s: shl 1 order
loop (s-1)..0 'y [
do.times: y -> prints " "
loop 0..dec s-y 'x [
if? zero? and x y -> prints "* "
else -> prints " "
]
print ""
]
]
sierpinski 4
| #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Write a version of this Arturo function in Java with identical behavior. | sierpinski: function [order][
s: shl 1 order
loop (s-1)..0 'y [
do.times: y -> prints " "
loop 0..dec s-y 'x [
if? zero? and x y -> prints "* "
else -> prints " "
]
print ""
]
]
sierpinski 4
| public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Translate the given Arturo code snippet into Python without altering its behavior. | sierpinski: function [order][
s: shl 1 order
loop (s-1)..0 'y [
do.times: y -> prints " "
loop 0..dec s-y 'x [
if? zero? and x y -> prints "* "
else -> prints " "
]
print ""
]
]
sierpinski 4
| def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Produce a language-to-language conversion: from Arturo to VB, same semantics. | sierpinski: function [order][
s: shl 1 order
loop (s-1)..0 'y [
do.times: y -> prints " "
loop 0..dec s-y 'x [
if? zero? and x y -> prints "* "
else -> prints " "
]
print ""
]
]
sierpinski 4
| Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Preserve the algorithm and functionality while converting the code from Arturo to Go. | sierpinski: function [order][
s: shl 1 order
loop (s-1)..0 'y [
do.times: y -> prints " "
loop 0..dec s-y 'x [
if? zero? and x y -> prints "* "
else -> prints " "
]
print ""
]
]
sierpinski 4
| package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Translate the given AutoHotKey code snippet into C without altering its behavior. | Loop 6
MsgBox % Triangle(A_Index)
Triangle(n,x=0,y=1) {
Static t, l
If (x < 1) {
l := 2*x := 1<<(n-1)
VarSetCapacity(t,l*x,32)
Loop %x%
NumPut(13,t,A_Index*l-1,"char") ... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Change the following AutoHotKey code into C# without altering its purpose. | Loop 6
MsgBox % Triangle(A_Index)
Triangle(n,x=0,y=1) {
Static t, l
If (x < 1) {
l := 2*x := 1<<(n-1)
VarSetCapacity(t,l*x,32)
Loop %x%
NumPut(13,t,A_Index*l-1,"char") ... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Change the programming language of this snippet from AutoHotKey to C++ without modifying what it does. | Loop 6
MsgBox % Triangle(A_Index)
Triangle(n,x=0,y=1) {
Static t, l
If (x < 1) {
l := 2*x := 1<<(n-1)
VarSetCapacity(t,l*x,32)
Loop %x%
NumPut(13,t,A_Index*l-1,"char") ... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Port the following code from AutoHotKey to Java with equivalent syntax and logic. | Loop 6
MsgBox % Triangle(A_Index)
Triangle(n,x=0,y=1) {
Static t, l
If (x < 1) {
l := 2*x := 1<<(n-1)
VarSetCapacity(t,l*x,32)
Loop %x%
NumPut(13,t,A_Index*l-1,"char") ... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Change the programming language of this snippet from AutoHotKey to Python without modifying what it does. | Loop 6
MsgBox % Triangle(A_Index)
Triangle(n,x=0,y=1) {
Static t, l
If (x < 1) {
l := 2*x := 1<<(n-1)
VarSetCapacity(t,l*x,32)
Loop %x%
NumPut(13,t,A_Index*l-1,"char") ... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Rewrite this program in VB while keeping its functionality equivalent to the AutoHotKey version. | Loop 6
MsgBox % Triangle(A_Index)
Triangle(n,x=0,y=1) {
Static t, l
If (x < 1) {
l := 2*x := 1<<(n-1)
VarSetCapacity(t,l*x,32)
Loop %x%
NumPut(13,t,A_Index*l-1,"char") ... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Translate this program into Go but keep the logic exactly as in AutoHotKey. | Loop 6
MsgBox % Triangle(A_Index)
Triangle(n,x=0,y=1) {
Static t, l
If (x < 1) {
l := 2*x := 1<<(n-1)
VarSetCapacity(t,l*x,32)
Loop %x%
NumPut(13,t,A_Index*l-1,"char") ... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Can you help me rewrite this code in C instead of AWK, keeping it the same logically? |
BEGIN {
n = ARGV[1] + 0
if (n !~ /^[0-9]+$/) { exit(1) }
if (n == 0) { width = 3 }
row = split("X,X X,X X,X X X X",A,",")
for (i=1; i<=n; i++) {
width = length(A[row])
for (j=1; j<=row; j++) {
str = A[j]
A[j+row] = sprintf("%-*s %-*s",width,str,width,str)
}
... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Rewrite the snippet below in C# so it works the same as the original AWK code. |
BEGIN {
n = ARGV[1] + 0
if (n !~ /^[0-9]+$/) { exit(1) }
if (n == 0) { width = 3 }
row = split("X,X X,X X,X X X X",A,",")
for (i=1; i<=n; i++) {
width = length(A[row])
for (j=1; j<=row; j++) {
str = A[j]
A[j+row] = sprintf("%-*s %-*s",width,str,width,str)
}
... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Transform the following AWK implementation into C++, maintaining the same output and logic. |
BEGIN {
n = ARGV[1] + 0
if (n !~ /^[0-9]+$/) { exit(1) }
if (n == 0) { width = 3 }
row = split("X,X X,X X,X X X X",A,",")
for (i=1; i<=n; i++) {
width = length(A[row])
for (j=1; j<=row; j++) {
str = A[j]
A[j+row] = sprintf("%-*s %-*s",width,str,width,str)
}
... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Convert this AWK block to Java, preserving its control flow and logic. |
BEGIN {
n = ARGV[1] + 0
if (n !~ /^[0-9]+$/) { exit(1) }
if (n == 0) { width = 3 }
row = split("X,X X,X X,X X X X",A,",")
for (i=1; i<=n; i++) {
width = length(A[row])
for (j=1; j<=row; j++) {
str = A[j]
A[j+row] = sprintf("%-*s %-*s",width,str,width,str)
}
... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Change the following AWK code into Python without altering its purpose. |
BEGIN {
n = ARGV[1] + 0
if (n !~ /^[0-9]+$/) { exit(1) }
if (n == 0) { width = 3 }
row = split("X,X X,X X,X X X X",A,",")
for (i=1; i<=n; i++) {
width = length(A[row])
for (j=1; j<=row; j++) {
str = A[j]
A[j+row] = sprintf("%-*s %-*s",width,str,width,str)
}
... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Translate this program into VB but keep the logic exactly as in AWK. |
BEGIN {
n = ARGV[1] + 0
if (n !~ /^[0-9]+$/) { exit(1) }
if (n == 0) { width = 3 }
row = split("X,X X,X X,X X X X",A,",")
for (i=1; i<=n; i++) {
width = length(A[row])
for (j=1; j<=row; j++) {
str = A[j]
A[j+row] = sprintf("%-*s %-*s",width,str,width,str)
}
... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Write a version of this AWK function in Go with identical behavior. |
BEGIN {
n = ARGV[1] + 0
if (n !~ /^[0-9]+$/) { exit(1) }
if (n == 0) { width = 3 }
row = split("X,X X,X X,X X X X",A,",")
for (i=1; i<=n; i++) {
width = length(A[row])
for (j=1; j<=row; j++) {
str = A[j]
A[j+row] = sprintf("%-*s %-*s",width,str,width,str)
}
... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Write the same algorithm in C as shown in this BBC_Basic implementation. | MODE 8
OFF
order% = 5
PROCsierpinski(0, 0, 2^(order%-1))
REPEAT UNTIL GET
END
DEF PROCsierpinski(x%, y%, l%)
IF l% = 0 THEN
PRINT TAB(x%,y%) "*";
ELSE
PROCsierpinski(x%, y%+l%, l% DIV 2)
PROCsierpinski(x%+l%, y%, l% DIV 2)
... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Convert this BBC_Basic block to C#, preserving its control flow and logic. | MODE 8
OFF
order% = 5
PROCsierpinski(0, 0, 2^(order%-1))
REPEAT UNTIL GET
END
DEF PROCsierpinski(x%, y%, l%)
IF l% = 0 THEN
PRINT TAB(x%,y%) "*";
ELSE
PROCsierpinski(x%, y%+l%, l% DIV 2)
PROCsierpinski(x%+l%, y%, l% DIV 2)
... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Please provide an equivalent version of this BBC_Basic code in C++. | MODE 8
OFF
order% = 5
PROCsierpinski(0, 0, 2^(order%-1))
REPEAT UNTIL GET
END
DEF PROCsierpinski(x%, y%, l%)
IF l% = 0 THEN
PRINT TAB(x%,y%) "*";
ELSE
PROCsierpinski(x%, y%+l%, l% DIV 2)
PROCsierpinski(x%+l%, y%, l% DIV 2)
... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Generate an equivalent Java version of this BBC_Basic code. | MODE 8
OFF
order% = 5
PROCsierpinski(0, 0, 2^(order%-1))
REPEAT UNTIL GET
END
DEF PROCsierpinski(x%, y%, l%)
IF l% = 0 THEN
PRINT TAB(x%,y%) "*";
ELSE
PROCsierpinski(x%, y%+l%, l% DIV 2)
PROCsierpinski(x%+l%, y%, l% DIV 2)
... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Can you help me rewrite this code in Python instead of BBC_Basic, keeping it the same logically? | MODE 8
OFF
order% = 5
PROCsierpinski(0, 0, 2^(order%-1))
REPEAT UNTIL GET
END
DEF PROCsierpinski(x%, y%, l%)
IF l% = 0 THEN
PRINT TAB(x%,y%) "*";
ELSE
PROCsierpinski(x%, y%+l%, l% DIV 2)
PROCsierpinski(x%+l%, y%, l% DIV 2)
... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Translate this program into VB but keep the logic exactly as in BBC_Basic. | MODE 8
OFF
order% = 5
PROCsierpinski(0, 0, 2^(order%-1))
REPEAT UNTIL GET
END
DEF PROCsierpinski(x%, y%, l%)
IF l% = 0 THEN
PRINT TAB(x%,y%) "*";
ELSE
PROCsierpinski(x%, y%+l%, l% DIV 2)
PROCsierpinski(x%+l%, y%, l% DIV 2)
... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Transform the following BBC_Basic implementation into Go, maintaining the same output and logic. | MODE 8
OFF
order% = 5
PROCsierpinski(0, 0, 2^(order%-1))
REPEAT UNTIL GET
END
DEF PROCsierpinski(x%, y%, l%)
IF l% = 0 THEN
PRINT TAB(x%,y%) "*";
ELSE
PROCsierpinski(x%, y%+l%, l% DIV 2)
PROCsierpinski(x%+l%, y%, l% DIV 2)
... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Port the following code from Clojure to C with equivalent syntax and logic. | (ns example
(:require [clojure.contrib.math :as math]))
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java.lang.Long [n]
(count (Long/toBinaryString n)))
(defmethod integer-length java.math.BigInt... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Change the programming language of this snippet from Clojure to C# without modifying what it does. | (ns example
(:require [clojure.contrib.math :as math]))
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java.lang.Long [n]
(count (Long/toBinaryString n)))
(defmethod integer-length java.math.BigInt... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Convert this Clojure snippet to C++ and keep its semantics consistent. | (ns example
(:require [clojure.contrib.math :as math]))
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java.lang.Long [n]
(count (Long/toBinaryString n)))
(defmethod integer-length java.math.BigInt... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Port the provided Clojure code into Java while preserving the original functionality. | (ns example
(:require [clojure.contrib.math :as math]))
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java.lang.Long [n]
(count (Long/toBinaryString n)))
(defmethod integer-length java.math.BigInt... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Preserve the algorithm and functionality while converting the code from Clojure to Python. | (ns example
(:require [clojure.contrib.math :as math]))
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java.lang.Long [n]
(count (Long/toBinaryString n)))
(defmethod integer-length java.math.BigInt... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Can you help me rewrite this code in VB instead of Clojure, keeping it the same logically? | (ns example
(:require [clojure.contrib.math :as math]))
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java.lang.Long [n]
(count (Long/toBinaryString n)))
(defmethod integer-length java.math.BigInt... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Generate a Go translation of this Clojure snippet without changing its computational steps. | (ns example
(:require [clojure.contrib.math :as math]))
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java.lang.Long [n]
(count (Long/toBinaryString n)))
(defmethod integer-length java.math.BigInt... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Produce a functionally identical C code for the snippet given in Common_Lisp. | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) curr... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Generate an equivalent C# version of this Common_Lisp code. | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) curr... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Ensure the translated C++ code behaves exactly like the original Common_Lisp snippet. | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) curr... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Generate an equivalent Java version of this Common_Lisp code. | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) curr... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Keep all operations the same but rewrite the snippet in Python. | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) curr... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Write a version of this Common_Lisp function in VB with identical behavior. | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) curr... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Change the following Common_Lisp code into Go without altering its purpose. | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) curr... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Can you help me rewrite this code in C instead of D, keeping it the same logically? | void main() {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\n').writel... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Convert this D block to C#, preserving its control flow and logic. | void main() {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\n').writel... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Convert this D block to C++, preserving its control flow and logic. | void main() {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\n').writel... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Change the programming language of this snippet from D to Java without modifying what it does. | void main() {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\n').writel... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Ensure the translated Python code behaves exactly like the original D snippet. | void main() {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\n').writel... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Change the programming language of this snippet from D to VB without modifying what it does. | void main() {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\n').writel... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Produce a functionally identical Go code for the snippet given in D. | void main() {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\n').writel... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Write the same code in C as shown below in Delphi. | program SierpinskiTriangle;
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
else
Write(' ... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Convert this Delphi block to C#, preserving its control flow and logic. | program SierpinskiTriangle;
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
else
Write(' ... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Rewrite the snippet below in C++ so it works the same as the original Delphi code. | program SierpinskiTriangle;
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
else
Write(' ... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Change the programming language of this snippet from Delphi to Java without modifying what it does. | program SierpinskiTriangle;
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
else
Write(' ... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Translate the given Delphi code snippet into Python without altering its behavior. | program SierpinskiTriangle;
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
else
Write(' ... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Convert the following code from Delphi to VB, ensuring the logic remains intact. | program SierpinskiTriangle;
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
else
Write(' ... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Keep all operations the same but rewrite the snippet in Go. | program SierpinskiTriangle;
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
else
Write(' ... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Write the same algorithm in C as shown in this Elixir implementation. | defmodule RC do
def sierpinski_triangle(n) do
f = fn(x) -> IO.puts "
Enum.each(triangle(n, ["*"], " "), f)
end
defp triangle(0, down, _), do: down
defp triangle(n, down, sp) do
newDown = (for x <- down, do: sp<>x<>sp) ++ (for x <- down, do: x<>" "<>x)
triangle(n-1, newDown, sp<>sp)
end
end
... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Write the same algorithm in C# as shown in this Elixir implementation. | defmodule RC do
def sierpinski_triangle(n) do
f = fn(x) -> IO.puts "
Enum.each(triangle(n, ["*"], " "), f)
end
defp triangle(0, down, _), do: down
defp triangle(n, down, sp) do
newDown = (for x <- down, do: sp<>x<>sp) ++ (for x <- down, do: x<>" "<>x)
triangle(n-1, newDown, sp<>sp)
end
end
... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Can you help me rewrite this code in C++ instead of Elixir, keeping it the same logically? | defmodule RC do
def sierpinski_triangle(n) do
f = fn(x) -> IO.puts "
Enum.each(triangle(n, ["*"], " "), f)
end
defp triangle(0, down, _), do: down
defp triangle(n, down, sp) do
newDown = (for x <- down, do: sp<>x<>sp) ++ (for x <- down, do: x<>" "<>x)
triangle(n-1, newDown, sp<>sp)
end
end
... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Write a version of this Elixir function in Java with identical behavior. | defmodule RC do
def sierpinski_triangle(n) do
f = fn(x) -> IO.puts "
Enum.each(triangle(n, ["*"], " "), f)
end
defp triangle(0, down, _), do: down
defp triangle(n, down, sp) do
newDown = (for x <- down, do: sp<>x<>sp) ++ (for x <- down, do: x<>" "<>x)
triangle(n-1, newDown, sp<>sp)
end
end
... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Keep all operations the same but rewrite the snippet in VB. | defmodule RC do
def sierpinski_triangle(n) do
f = fn(x) -> IO.puts "
Enum.each(triangle(n, ["*"], " "), f)
end
defp triangle(0, down, _), do: down
defp triangle(n, down, sp) do
newDown = (for x <- down, do: sp<>x<>sp) ++ (for x <- down, do: x<>" "<>x)
triangle(n-1, newDown, sp<>sp)
end
end
... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Please provide an equivalent version of this Elixir code in Go. | defmodule RC do
def sierpinski_triangle(n) do
f = fn(x) -> IO.puts "
Enum.each(triangle(n, ["*"], " "), f)
end
defp triangle(0, down, _), do: down
defp triangle(n, down, sp) do
newDown = (for x <- down, do: sp<>x<>sp) ++ (for x <- down, do: x<>" "<>x)
triangle(n-1, newDown, sp<>sp)
end
end
... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Rewrite the snippet below in C so it works the same as the original Erlang code. | -module(sierpinski).
-export([triangle/1]).
triangle(N) ->
F = fun(X) -> io:format("~s~n",[X]) end,
lists:foreach(F, triangle(N, ["*"], " ")).
triangle(0, Down, _) -> Down;
triangle(N, Down, Sp) ->
NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down],
triangle(N-1, NewDown, Sp++Sp).
| #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Convert this Erlang snippet to C# and keep its semantics consistent. | -module(sierpinski).
-export([triangle/1]).
triangle(N) ->
F = fun(X) -> io:format("~s~n",[X]) end,
lists:foreach(F, triangle(N, ["*"], " ")).
triangle(0, Down, _) -> Down;
triangle(N, Down, Sp) ->
NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down],
triangle(N-1, NewDown, Sp++Sp).
| using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Change the programming language of this snippet from Erlang to C++ without modifying what it does. | -module(sierpinski).
-export([triangle/1]).
triangle(N) ->
F = fun(X) -> io:format("~s~n",[X]) end,
lists:foreach(F, triangle(N, ["*"], " ")).
triangle(0, Down, _) -> Down;
triangle(N, Down, Sp) ->
NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down],
triangle(N-1, NewDown, Sp++Sp).
| #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Maintain the same structure and functionality when rewriting this code in Java. | -module(sierpinski).
-export([triangle/1]).
triangle(N) ->
F = fun(X) -> io:format("~s~n",[X]) end,
lists:foreach(F, triangle(N, ["*"], " ")).
triangle(0, Down, _) -> Down;
triangle(N, Down, Sp) ->
NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down],
triangle(N-1, NewDown, Sp++Sp).
| public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Rewrite the snippet below in Python so it works the same as the original Erlang code. | -module(sierpinski).
-export([triangle/1]).
triangle(N) ->
F = fun(X) -> io:format("~s~n",[X]) end,
lists:foreach(F, triangle(N, ["*"], " ")).
triangle(0, Down, _) -> Down;
triangle(N, Down, Sp) ->
NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down],
triangle(N-1, NewDown, Sp++Sp).
| def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Generate a VB translation of this Erlang snippet without changing its computational steps. | -module(sierpinski).
-export([triangle/1]).
triangle(N) ->
F = fun(X) -> io:format("~s~n",[X]) end,
lists:foreach(F, triangle(N, ["*"], " ")).
triangle(0, Down, _) -> Down;
triangle(N, Down, Sp) ->
NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down],
triangle(N-1, NewDown, Sp++Sp).
| Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Translate the given Erlang code snippet into Go without altering its behavior. | -module(sierpinski).
-export([triangle/1]).
triangle(N) ->
F = fun(X) -> io:format("~s~n",[X]) end,
lists:foreach(F, triangle(N, ["*"], " ")).
triangle(0, Down, _) -> Down;
triangle(N, Down, Sp) ->
NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down],
triangle(N-1, NewDown, Sp++Sp).
| package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Translate this program into C but keep the logic exactly as in F#. | let sierpinski n =
let rec loop down space n =
if n = 0 then
down
else
loop (List.map (fun x -> space + x + space) down @
List.map (fun x -> x + " " + x) down)
(space + space)
(n - 1)
in loop ["*"] " " n
let () =
List.iter (fun (i:string) -> System.Console.Write... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Transform the following F# implementation into C#, maintaining the same output and logic. | let sierpinski n =
let rec loop down space n =
if n = 0 then
down
else
loop (List.map (fun x -> space + x + space) down @
List.map (fun x -> x + " " + x) down)
(space + space)
(n - 1)
in loop ["*"] " " n
let () =
List.iter (fun (i:string) -> System.Console.Write... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Transform the following F# implementation into C++, maintaining the same output and logic. | let sierpinski n =
let rec loop down space n =
if n = 0 then
down
else
loop (List.map (fun x -> space + x + space) down @
List.map (fun x -> x + " " + x) down)
(space + space)
(n - 1)
in loop ["*"] " " n
let () =
List.iter (fun (i:string) -> System.Console.Write... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Write a version of this F# function in Java with identical behavior. | let sierpinski n =
let rec loop down space n =
if n = 0 then
down
else
loop (List.map (fun x -> space + x + space) down @
List.map (fun x -> x + " " + x) down)
(space + space)
(n - 1)
in loop ["*"] " " n
let () =
List.iter (fun (i:string) -> System.Console.Write... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Rewrite the snippet below in Python so it works the same as the original F# code. | let sierpinski n =
let rec loop down space n =
if n = 0 then
down
else
loop (List.map (fun x -> space + x + space) down @
List.map (fun x -> x + " " + x) down)
(space + space)
(n - 1)
in loop ["*"] " " n
let () =
List.iter (fun (i:string) -> System.Console.Write... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Translate this program into VB but keep the logic exactly as in F#. | let sierpinski n =
let rec loop down space n =
if n = 0 then
down
else
loop (List.map (fun x -> space + x + space) down @
List.map (fun x -> x + " " + x) down)
(space + space)
(n - 1)
in loop ["*"] " " n
let () =
List.iter (fun (i:string) -> System.Console.Write... | Sub sierpinski(n As Integer)
Dim lim As Integer: lim = 2 ^ n - 1
For y = lim To 0 Step -1
Debug.Print String$(y, " ")
For x = 0 To lim - y
Debug.Print IIf(x And y, " ", "# ");
Next
Debug.Print
Next y
End Sub
Public Sub main()
Dim i As Integer
For i = 1 To... |
Please provide an equivalent version of this F# code in Go. | let sierpinski n =
let rec loop down space n =
if n = 0 then
down
else
loop (List.map (fun x -> space + x + space) down @
List.map (fun x -> x + " " + x) down)
(space + space)
(n - 1)
in loop ["*"] " " n
let () =
List.iter (fun (i:string) -> System.Console.Write... | package main
import (
"fmt"
"strings"
"unicode/utf8"
)
var order = 4
var grain = "*"
func main() {
t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))}
for ; order > 0; order-- {
sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2)
top := make([]string, l... |
Translate the given Factor code snippet into C without altering its behavior. | USING: io kernel math sequences ;
IN: sierpinski
: iterate-triangle ( triange spaces -- triangle' )
[ [ dup surround ] curry map ]
[ drop [ dup " " glue ] map ] 2bi append ;
: (sierpinski) ( triangle spaces n -- triangle' )
dup 0 = [ 2drop "\n" join ] [
[
[ iterate-triangle ]
... | #include <stdio.h>
#define SIZE (1 << 4)
int main()
{
int x, y, i;
for (y = SIZE - 1; y >= 0; y--, putchar('\n')) {
for (i = 0; i < y; i++) putchar(' ');
for (x = 0; x + y < SIZE; x++)
printf((x & y) ? " " : "* ");
}
return 0;
}
|
Keep all operations the same but rewrite the snippet in C#. | USING: io kernel math sequences ;
IN: sierpinski
: iterate-triangle ( triange spaces -- triangle' )
[ [ dup surround ] curry map ]
[ drop [ dup " " glue ] map ] 2bi append ;
: (sierpinski) ( triangle spaces n -- triangle' )
dup 0 = [ 2drop "\n" join ] [
[
[ iterate-triangle ]
... | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
le... |
Ensure the translated C++ code behaves exactly like the original Factor snippet. | USING: io kernel math sequences ;
IN: sierpinski
: iterate-triangle ( triange spaces -- triangle' )
[ [ dup surround ] curry map ]
[ drop [ dup " " glue ] map ] 2bi append ;
: (sierpinski) ( triangle spaces n -- triangle' )
dup 0 = [ 2drop "\n" join ] [
[
[ iterate-triangle ]
... | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(prev... |
Write the same code in Java as shown below in Factor. | USING: io kernel math sequences ;
IN: sierpinski
: iterate-triangle ( triange spaces -- triangle' )
[ [ dup surround ] curry map ]
[ drop [ dup " " glue ] map ] 2bi append ;
: (sierpinski) ( triangle spaces n -- triangle' )
dup 0 = [ 2drop "\n" join ] [
[
[ iterate-triangle ]
... | public class SierpinskiTriangle {
public static void main(String[] args) {
System.out.println(getSierpinskiTriangle(4));
}
private static final String getSierpinskiTriangle(int n) {
if ( n == 0 ) {
return "*";
}
String s = getSierpinskiTriangle(n-1);
... |
Rewrite this program in Python while keeping its functionality equivalent to the Factor version. | USING: io kernel math sequences ;
IN: sierpinski
: iterate-triangle ( triange spaces -- triangle' )
[ [ dup surround ] curry map ]
[ drop [ dup " " glue ] map ] 2bi append ;
: (sierpinski) ( triangle spaces n -- triangle' )
dup 0 = [ 2drop "\n" join ] [
[
[ iterate-triangle ]
... | def sierpinski(n):
d = ["*"]
for i in xrange(n):
sp = " " * (2 ** i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print "\n".join(sierpinski(4))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.