Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Produce a functionally identical VB code for the snippet given 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 ]
... | 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 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 ]
... | 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 Forth. | : stars
begin
dup 1 and if [char] * else bl then emit
1 rshift dup
while space repeat drop ;
: triangle
1 swap lshift
1 over 0 do
cr over i - spaces dup stars
dup 2* xor
loop 2drop ;
5 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;
}
|
Change the following Forth code into C# without altering its purpose. | : stars
begin
dup 1 and if [char] * else bl then emit
1 rshift dup
while space repeat drop ;
: triangle
1 swap lshift
1 over 0 do
cr over i - spaces dup stars
dup 2* xor
loop 2drop ;
5 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... |
Can you help me rewrite this code in C++ instead of Forth, keeping it the same logically? | : stars
begin
dup 1 and if [char] * else bl then emit
1 rshift dup
while space repeat drop ;
: triangle
1 swap lshift
1 over 0 do
cr over i - spaces dup stars
dup 2* xor
loop 2drop ;
5 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... |
Generate a Java translation of this Forth snippet without changing its computational steps. | : stars
begin
dup 1 and if [char] * else bl then emit
1 rshift dup
while space repeat drop ;
: triangle
1 swap lshift
1 over 0 do
cr over i - spaces dup stars
dup 2* xor
loop 2drop ;
5 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);
... |
Produce a language-to-language conversion: from Forth to Python, same semantics. | : stars
begin
dup 1 and if [char] * else bl then emit
1 rshift dup
while space repeat drop ;
: triangle
1 swap lshift
1 over 0 do
cr over i - spaces dup stars
dup 2* xor
loop 2drop ;
5 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))
|
Port the provided Forth code into VB while preserving the original functionality. | : stars
begin
dup 1 and if [char] * else bl then emit
1 rshift dup
while space repeat drop ;
: triangle
1 swap lshift
1 over 0 do
cr over i - spaces dup stars
dup 2* xor
loop 2drop ;
5 triangle
| 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... |
Port the following code from Forth to Go with equivalent syntax and logic. | : stars
begin
dup 1 and if [char] * else bl then emit
1 rshift dup
while space repeat drop ;
: triangle
1 swap lshift
1 over 0 do
cr over i - spaces dup stars
dup 2* xor
loop 2drop ;
5 triangle
| 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 Fortran code. | program Sierpinski_triangle
implicit none
call Triangle(4)
contains
subroutine Triangle(n)
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer, intent(in) :: n
integer :: i, k
integer(i64) :: c
do i = 0, n*4-1
c = 1
write(*, "(a)", advance="no") repeat(" ", 2 * (n*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... |
Port the following code from Fortran to C++ with equivalent syntax and logic. | program Sierpinski_triangle
implicit none
call Triangle(4)
contains
subroutine Triangle(n)
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer, intent(in) :: n
integer :: i, k
integer(i64) :: c
do i = 0, n*4-1
c = 1
write(*, "(a)", advance="no") repeat(" ", 2 * (n*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... |
Maintain the same structure and functionality when rewriting this code in C. | program Sierpinski_triangle
implicit none
call Triangle(4)
contains
subroutine Triangle(n)
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer, intent(in) :: n
integer :: i, k
integer(i64) :: c
do i = 0, n*4-1
c = 1
write(*, "(a)", advance="no") repeat(" ", 2 * (n*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;
}
|
Write a version of this Fortran function in Java with identical behavior. | program Sierpinski_triangle
implicit none
call Triangle(4)
contains
subroutine Triangle(n)
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer, intent(in) :: n
integer :: i, k
integer(i64) :: c
do i = 0, n*4-1
c = 1
write(*, "(a)", advance="no") repeat(" ", 2 * (n*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);
... |
Generate a Python translation of this Fortran snippet without changing its computational steps. | program Sierpinski_triangle
implicit none
call Triangle(4)
contains
subroutine Triangle(n)
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer, intent(in) :: n
integer :: i, k
integer(i64) :: c
do i = 0, n*4-1
c = 1
write(*, "(a)", advance="no") repeat(" ", 2 * (n*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))
|
Maintain the same structure and functionality when rewriting this code in VB. | program Sierpinski_triangle
implicit none
call Triangle(4)
contains
subroutine Triangle(n)
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer, intent(in) :: n
integer :: i, k
integer(i64) :: c
do i = 0, n*4-1
c = 1
write(*, "(a)", advance="no") repeat(" ", 2 * (n*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... |
Translate this program into PHP but keep the logic exactly as in Fortran. | program Sierpinski_triangle
implicit none
call Triangle(4)
contains
subroutine Triangle(n)
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer, intent(in) :: n
integer :: i, k
integer(i64) :: c
do i = 0, n*4-1
c = 1
write(*, "(a)", advance="no") repeat(" ", 2 * (n*4 -... | <?php
function sierpinskiTriangle($order) {
$char = '#';
$n = 1 << $order;
$line = array();
for ($i = 0 ; $i <= 2 * $n ; $i++) {
$line[$i] = ' ';
}
$line[$n] = $char;
for ($i = 0 ; $i < $n ; $i++) {
echo implode('', $line), PHP_EOL;
$u = $char;
for ($j = $n -... |
Change the following Groovy code into C without altering its purpose. | def stPoints;
stPoints = { order, base=[0,0] ->
def right = [base[0], base[1]+2**order]
def up = [base[0]+2**(order-1), base[1]+2**(order-1)]
(order == 0) \
? [base]
: (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up))
}
def stGrid = { order ->
def h = 2**order... | #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;
}
|
Translate this program into C# but keep the logic exactly as in Groovy. | def stPoints;
stPoints = { order, base=[0,0] ->
def right = [base[0], base[1]+2**order]
def up = [base[0]+2**(order-1), base[1]+2**(order-1)]
(order == 0) \
? [base]
: (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up))
}
def stGrid = { order ->
def h = 2**order... | 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 Groovy snippet to C++ and keep its semantics consistent. | def stPoints;
stPoints = { order, base=[0,0] ->
def right = [base[0], base[1]+2**order]
def up = [base[0]+2**(order-1), base[1]+2**(order-1)]
(order == 0) \
? [base]
: (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up))
}
def stGrid = { order ->
def h = 2**order... | #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 Groovy to Java with equivalent syntax and logic. | def stPoints;
stPoints = { order, base=[0,0] ->
def right = [base[0], base[1]+2**order]
def up = [base[0]+2**(order-1), base[1]+2**(order-1)]
(order == 0) \
? [base]
: (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up))
}
def stGrid = { order ->
def h = 2**order... | 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);
... |
Write the same code in Python as shown below in Groovy. | def stPoints;
stPoints = { order, base=[0,0] ->
def right = [base[0], base[1]+2**order]
def up = [base[0]+2**(order-1), base[1]+2**(order-1)]
(order == 0) \
? [base]
: (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up))
}
def stGrid = { order ->
def h = 2**order... | 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))
|
Port the following code from Groovy to VB with equivalent syntax and logic. | def stPoints;
stPoints = { order, base=[0,0] ->
def right = [base[0], base[1]+2**order]
def up = [base[0]+2**(order-1), base[1]+2**(order-1)]
(order == 0) \
? [base]
: (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up))
}
def stGrid = { order ->
def h = 2**order... | 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. | def stPoints;
stPoints = { order, base=[0,0] ->
def right = [base[0], base[1]+2**order]
def up = [base[0]+2**(order-1), base[1]+2**(order-1)]
(order == 0) \
? [base]
: (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up))
}
def stGrid = { order ->
def h = 2**order... | 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... |
Change the following Haskell code into C without altering its purpose. | sierpinski 0 = ["*"]
sierpinski n = map ((space ++) . (++ space)) down ++
map (unwords . replicate 2) down
where down = sierpinski (n - 1)
space = replicate (2 ^ (n - 1)) ' '
main = mapM_ putStrLn $ 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;
}
|
Rewrite the snippet below in C++ so it works the same as the original Haskell code. | sierpinski 0 = ["*"]
sierpinski n = map ((space ++) . (++ space)) down ++
map (unwords . replicate 2) down
where down = sierpinski (n - 1)
space = replicate (2 ^ (n - 1)) ' '
main = mapM_ putStrLn $ 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... |
Convert the following code from Haskell to Java, ensuring the logic remains intact. | sierpinski 0 = ["*"]
sierpinski n = map ((space ++) . (++ space)) down ++
map (unwords . replicate 2) down
where down = sierpinski (n - 1)
space = replicate (2 ^ (n - 1)) ' '
main = mapM_ putStrLn $ 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);
... |
Convert the following code from Haskell to Python, ensuring the logic remains intact. | sierpinski 0 = ["*"]
sierpinski n = map ((space ++) . (++ space)) down ++
map (unwords . replicate 2) down
where down = sierpinski (n - 1)
space = replicate (2 ^ (n - 1)) ' '
main = mapM_ putStrLn $ 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))
|
Please provide an equivalent version of this Haskell code in VB. | sierpinski 0 = ["*"]
sierpinski n = map ((space ++) . (++ space)) down ++
map (unwords . replicate 2) down
where down = sierpinski (n - 1)
space = replicate (2 ^ (n - 1)) ' '
main = mapM_ putStrLn $ 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... |
Please provide an equivalent version of this Haskell code in Go. | sierpinski 0 = ["*"]
sierpinski n = map ((space ++) . (++ space)) down ++
map (unwords . replicate 2) down
where down = sierpinski (n - 1)
space = replicate (2 ^ (n - 1)) ' '
main = mapM_ putStrLn $ 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... |
Change the following Icon code into C without altering its purpose. |
procedure main(A)
width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))
write("Triangle order= ",order)
every !(canvas := list(width)) := list(width," ")
every y := 1 to width & x := 1 to width do
if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"
every x := 1 to width &... | #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 Icon code. |
procedure main(A)
width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))
write("Triangle order= ",order)
every !(canvas := list(width)) := list(width," ")
every y := 1 to width & x := 1 to width do
if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"
every x := 1 to width &... | 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... |
Maintain the same structure and functionality when rewriting this code in C++. |
procedure main(A)
width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))
write("Triangle order= ",order)
every !(canvas := list(width)) := list(width," ")
every y := 1 to width & x := 1 to width do
if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"
every x := 1 to width &... | #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... |
Rewrite this program in Java while keeping its functionality equivalent to the Icon version. |
procedure main(A)
width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))
write("Triangle order= ",order)
every !(canvas := list(width)) := list(width," ")
every y := 1 to width & x := 1 to width do
if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"
every x := 1 to width &... | 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);
... |
Port the provided Icon code into Python while preserving the original functionality. |
procedure main(A)
width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))
write("Triangle order= ",order)
every !(canvas := list(width)) := list(width," ")
every y := 1 to width & x := 1 to width do
if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"
every x := 1 to width &... | 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 Icon to VB, same semantics. |
procedure main(A)
width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))
write("Triangle order= ",order)
every !(canvas := list(width)) := list(width," ")
every y := 1 to width & x := 1 to width do
if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"
every x := 1 to width &... | 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 the same code in Go as shown below in Icon. |
procedure main(A)
width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))
write("Triangle order= ",order)
every !(canvas := list(width)) := list(width," ")
every y := 1 to width & x := 1 to width do
if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"
every x := 1 to width &... | 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... |
Preserve the algorithm and functionality while converting the code from J to C. | |. _31]\ ,(,.~ , ])^: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;
}
|
Rewrite the snippet below in C# so it works the same as the original J code. | |. _31]\ ,(,.~ , ])^: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... |
Keep all operations the same but rewrite the snippet in C++. | |. _31]\ ,(,.~ , ])^: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... |
Please provide an equivalent version of this J code in Java. | |. _31]\ ,(,.~ , ])^: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 J code snippet into Python without altering its behavior. | |. _31]\ ,(,.~ , ])^: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))
|
Rewrite the snippet below in VB so it works the same as the original J code. | |. _31]\ ,(,.~ , ])^: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... |
Ensure the translated Go code behaves exactly like the original J snippet. | |. _31]\ ,(,.~ , ])^: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 this program into C but keep the logic exactly as in Julia. | function sierpinski(n, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
h, w = size(x)
s = fill(" ", h,(w + 1) ÷ 2)
t = fill(" ", h,1)
x = [[s x s] ; [x t x]]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
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;
}
|
Rewrite the snippet below in C# so it works the same as the original Julia code. | function sierpinski(n, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
h, w = size(x)
s = fill(" ", h,(w + 1) ÷ 2)
t = fill(" ", h,1)
x = [[s x s] ; [x t x]]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
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... |
Change the following Julia code into C++ without altering its purpose. | function sierpinski(n, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
h, w = size(x)
s = fill(" ", h,(w + 1) ÷ 2)
t = fill(" ", h,1)
x = [[s x s] ; [x t x]]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
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... |
Please provide an equivalent version of this Julia code in Java. | function sierpinski(n, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
h, w = size(x)
s = fill(" ", h,(w + 1) ÷ 2)
t = fill(" ", h,1)
x = [[s x s] ; [x t x]]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
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);
... |
Generate a Python translation of this Julia snippet without changing its computational steps. | function sierpinski(n, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
h, w = size(x)
s = fill(" ", h,(w + 1) ÷ 2)
t = fill(" ", h,1)
x = [[s x s] ; [x t x]]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
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))
|
Preserve the algorithm and functionality while converting the code from Julia to VB. | function sierpinski(n, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
h, w = size(x)
s = fill(" ", h,(w + 1) ÷ 2)
t = fill(" ", h,1)
x = [[s x s] ; [x t x]]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
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... |
Convert this Julia block to Go, preserving its control flow and logic. | function sierpinski(n, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
h, w = size(x)
s = fill(" ", h,(w + 1) ÷ 2)
t = fill(" ", h,1)
x = [[s x s] ; [x t x]]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
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... |
Produce a functionally identical C code for the snippet given in Lua. | function sierpinski(depth)
lines = {}
lines[1] = '*'
for i = 2, depth+1 do
sp = string.rep(' ', 2^(i-2))
tmp = {}
for idx, line in ipairs(lines) do
tmp[idx] = sp .. line .. sp
tmp[idx+#lines] = line .. ' ' .. line
end
lines = tmp
end
return table.concat(li... | #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;
}
|
Port the following code from Lua to C# with equivalent syntax and logic. | function sierpinski(depth)
lines = {}
lines[1] = '*'
for i = 2, depth+1 do
sp = string.rep(' ', 2^(i-2))
tmp = {}
for idx, line in ipairs(lines) do
tmp[idx] = sp .. line .. sp
tmp[idx+#lines] = line .. ' ' .. line
end
lines = tmp
end
return table.concat(li... | 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 Lua, keeping it the same logically? | function sierpinski(depth)
lines = {}
lines[1] = '*'
for i = 2, depth+1 do
sp = string.rep(' ', 2^(i-2))
tmp = {}
for idx, line in ipairs(lines) do
tmp[idx] = sp .. line .. sp
tmp[idx+#lines] = line .. ' ' .. line
end
lines = tmp
end
return table.concat(li... | #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 following Lua code into Java without altering its purpose. | function sierpinski(depth)
lines = {}
lines[1] = '*'
for i = 2, depth+1 do
sp = string.rep(' ', 2^(i-2))
tmp = {}
for idx, line in ipairs(lines) do
tmp[idx] = sp .. line .. sp
tmp[idx+#lines] = line .. ' ' .. line
end
lines = tmp
end
return table.concat(li... | 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);
... |
Convert this Lua snippet to Python and keep its semantics consistent. | function sierpinski(depth)
lines = {}
lines[1] = '*'
for i = 2, depth+1 do
sp = string.rep(' ', 2^(i-2))
tmp = {}
for idx, line in ipairs(lines) do
tmp[idx] = sp .. line .. sp
tmp[idx+#lines] = line .. ' ' .. line
end
lines = tmp
end
return table.concat(li... | 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 Lua version. | function sierpinski(depth)
lines = {}
lines[1] = '*'
for i = 2, depth+1 do
sp = string.rep(' ', 2^(i-2))
tmp = {}
for idx, line in ipairs(lines) do
tmp[idx] = sp .. line .. sp
tmp[idx+#lines] = line .. ' ' .. line
end
lines = tmp
end
return table.concat(li... | 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 programming language of this snippet from Lua to Go without modifying what it does. | function sierpinski(depth)
lines = {}
lines[1] = '*'
for i = 2, depth+1 do
sp = string.rep(' ', 2^(i-2))
tmp = {}
for idx, line in ipairs(lines) do
tmp[idx] = sp .. line .. sp
tmp[idx+#lines] = line .. ' ' .. line
end
lines = tmp
end
return table.concat(li... | 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... |
Please provide an equivalent version of this Mathematica code in C. | n=4;Grid[CellularAutomaton[90,{{1},0},2^n-1]/.{0->" ",1->"*"},ItemSize->All]
| #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 Mathematica code into C# without altering its purpose. | n=4;Grid[CellularAutomaton[90,{{1},0},2^n-1]/.{0->" ",1->"*"},ItemSize->All]
| 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 Mathematica, keeping it the same logically? | n=4;Grid[CellularAutomaton[90,{{1},0},2^n-1]/.{0->" ",1->"*"},ItemSize->All]
| #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 algorithm in Java as shown in this Mathematica implementation. | n=4;Grid[CellularAutomaton[90,{{1},0},2^n-1]/.{0->" ",1->"*"},ItemSize->All]
| 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);
... |
Write a version of this Mathematica function in Python with identical behavior. | n=4;Grid[CellularAutomaton[90,{{1},0},2^n-1]/.{0->" ",1->"*"},ItemSize->All]
| 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 the given Mathematica code snippet into VB without altering its behavior. | n=4;Grid[CellularAutomaton[90,{{1},0},2^n-1]/.{0->" ",1->"*"},ItemSize->All]
| 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 language-to-language conversion: from Mathematica to Go, same semantics. | n=4;Grid[CellularAutomaton[90,{{1},0},2^n-1]/.{0->" ",1->"*"},ItemSize->All]
| 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... |
Please provide an equivalent version of this MATLAB code in C. | n = 4;
d = string('*');
for k = 0 : n - 1
sp = repelem(' ', 2 ^ k);
d = [sp + d + sp, d + ' ' + d];
end
disp(d.join(char(10)))
| #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 code in C# as shown below in MATLAB. | n = 4;
d = string('*');
for k = 0 : n - 1
sp = repelem(' ', 2 ^ k);
d = [sp + d + sp, d + ' ' + d];
end
disp(d.join(char(10)))
| 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 MATLAB code into C++ without altering its purpose. | n = 4;
d = string('*');
for k = 0 : n - 1
sp = repelem(' ', 2 ^ k);
d = [sp + d + sp, d + ' ' + d];
end
disp(d.join(char(10)))
| #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... |
Translate the given MATLAB code snippet into Java without altering its behavior. | n = 4;
d = string('*');
for k = 0 : n - 1
sp = repelem(' ', 2 ^ k);
d = [sp + d + sp, d + ' ' + d];
end
disp(d.join(char(10)))
| 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);
... |
Write a version of this MATLAB function in Python with identical behavior. | n = 4;
d = string('*');
for k = 0 : n - 1
sp = repelem(' ', 2 ^ k);
d = [sp + d + sp, d + ' ' + d];
end
disp(d.join(char(10)))
| 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 MATLAB snippet without changing its computational steps. | n = 4;
d = string('*');
for k = 0 : n - 1
sp = repelem(' ', 2 ^ k);
d = [sp + d + sp, d + ' ' + d];
end
disp(d.join(char(10)))
| 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 the same algorithm in Go as shown in this MATLAB implementation. | n = 4;
d = string('*');
for k = 0 : n - 1
sp = repelem(' ', 2 ^ k);
d = [sp + d + sp, d + ' ' + d];
end
disp(d.join(char(10)))
| 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 Nim, keeping it the same logically? | const size = 1 shl 4 - 1
for y in countdown(size, 0):
for i in 0 .. <y:
stdout.write " "
for x in 0 .. size-y:
if (x and y) != 0:
stdout.write " "
else:
stdout.write "* "
stdout.write "\n"
| #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;
}
|
Port the following code from Nim to C# with equivalent syntax and logic. | const size = 1 shl 4 - 1
for y in countdown(size, 0):
for i in 0 .. <y:
stdout.write " "
for x in 0 .. size-y:
if (x and y) != 0:
stdout.write " "
else:
stdout.write "* "
stdout.write "\n"
| 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 Nim block to C++, preserving its control flow and logic. | const size = 1 shl 4 - 1
for y in countdown(size, 0):
for i in 0 .. <y:
stdout.write " "
for x in 0 .. size-y:
if (x and y) != 0:
stdout.write " "
else:
stdout.write "* "
stdout.write "\n"
| #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 Nim function in Java with identical behavior. | const size = 1 shl 4 - 1
for y in countdown(size, 0):
for i in 0 .. <y:
stdout.write " "
for x in 0 .. size-y:
if (x and y) != 0:
stdout.write " "
else:
stdout.write "* "
stdout.write "\n"
| 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);
... |
Maintain the same structure and functionality when rewriting this code in Python. | const size = 1 shl 4 - 1
for y in countdown(size, 0):
for i in 0 .. <y:
stdout.write " "
for x in 0 .. size-y:
if (x and y) != 0:
stdout.write " "
else:
stdout.write "* "
stdout.write "\n"
| 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 this Nim block to VB, preserving its control flow and logic. | const size = 1 shl 4 - 1
for y in countdown(size, 0):
for i in 0 .. <y:
stdout.write " "
for x in 0 .. size-y:
if (x and y) != 0:
stdout.write " "
else:
stdout.write "* "
stdout.write "\n"
| 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 Nim code snippet into Go without altering its behavior. | const size = 1 shl 4 - 1
for y in countdown(size, 0):
for i in 0 .. <y:
stdout.write " "
for x in 0 .. size-y:
if (x and y) != 0:
stdout.write " "
else:
stdout.write "* "
stdout.write "\n"
| 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 OCaml implementation. | 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 print_endline (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;
}
|
Translate the given OCaml code snippet into C# without altering its 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 print_endline (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... |
Can you help me rewrite this code in C++ instead of OCaml, keeping it the same logically? | 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 print_endline (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... |
Preserve the algorithm and functionality while converting the code from OCaml to Java. | 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 print_endline (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);
... |
Generate a Python translation of this OCaml snippet without changing its computational steps. | 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 print_endline (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))
|
Rewrite this program in VB while keeping its functionality equivalent to the OCaml version. | 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 print_endline (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... |
Maintain the same structure and functionality when rewriting this 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 print_endline (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 this program into C but keep the logic exactly as in Pascal. | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
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;
}
|
Convert the following code from Pascal to C#, ensuring the logic remains intact. | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
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... |
Port the provided Pascal code into C++ while preserving the original functionality. | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
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... |
Convert this Pascal snippet to Java and keep its semantics consistent. | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
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);
... |
Write the same algorithm in Python as shown in this Pascal implementation. | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
end;
| 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))
|
Maintain the same structure and functionality when rewriting this code in VB. | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
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... |
Produce a language-to-language conversion: from Pascal to Go, same semantics. | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
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... |
Write the same algorithm in C as shown in this Perl implementation. | sub sierpinski {
my ($n) = @_;
my @down = '*';
my $space = ' ';
foreach (1..$n) {
@down = (map("$space$_$space", @down), map("$_ $_", @down));
$space = "$space$space";
}
return @down;
}
print "$_\n" foreach 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;
}
|
Rewrite this program in C# while keeping its functionality equivalent to the Perl version. | sub sierpinski {
my ($n) = @_;
my @down = '*';
my $space = ' ';
foreach (1..$n) {
@down = (map("$space$_$space", @down), map("$_ $_", @down));
$space = "$space$space";
}
return @down;
}
print "$_\n" foreach 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... |
Please provide an equivalent version of this Perl code in C++. | sub sierpinski {
my ($n) = @_;
my @down = '*';
my $space = ' ';
foreach (1..$n) {
@down = (map("$space$_$space", @down), map("$_ $_", @down));
$space = "$space$space";
}
return @down;
}
print "$_\n" foreach 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... |
Rewrite the snippet below in Java so it works the same as the original Perl code. | sub sierpinski {
my ($n) = @_;
my @down = '*';
my $space = ' ';
foreach (1..$n) {
@down = (map("$space$_$space", @down), map("$_ $_", @down));
$space = "$space$space";
}
return @down;
}
print "$_\n" foreach 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);
... |
Convert this Perl snippet to Python and keep its semantics consistent. | sub sierpinski {
my ($n) = @_;
my @down = '*';
my $space = ' ';
foreach (1..$n) {
@down = (map("$space$_$space", @down), map("$_ $_", @down));
$space = "$space$space";
}
return @down;
}
print "$_\n" foreach 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))
|
Translate the given Perl code snippet into VB without altering its behavior. | sub sierpinski {
my ($n) = @_;
my @down = '*';
my $space = ' ';
foreach (1..$n) {
@down = (map("$space$_$space", @down), map("$_ $_", @down));
$space = "$space$space";
}
return @down;
}
print "$_\n" foreach 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... |
Convert this Perl snippet to Go and keep its semantics consistent. | sub sierpinski {
my ($n) = @_;
my @down = '*';
my $space = ' ';
foreach (1..$n) {
@down = (map("$space$_$space", @down), map("$_ $_", @down));
$space = "$space$space";
}
return @down;
}
print "$_\n" foreach 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... |
Keep all operations the same but rewrite the snippet in C. | function triangle($o) {
$n = [Math]::Pow(2, $o)
$line = ,' '*(2*$n+1)
$line[$n] = '█'
$OFS = ''
for ($i = 0; $i -lt $n; $i++) {
Write-Host $line
$u = '█'
for ($j = $n - $i; $j -lt $n + $i + 1; $j++) {
if ($line[$j-1] -eq $line[$j+1]) {
$t = ' '
... | #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;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.