Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Transform the following COBOL implementation into Python, maintaining the same output and logic. | IDENTIFICATION DIVISION.
PROGRAM-ID. CANTOR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SETTINGS.
03 NUM-LINES PIC 9 VALUE 5.
03 FILL-CHAR PIC X VALUE '#'.
01 VARIABLES.
03 CUR-LINE.
05 CHAR PIC X OCCURS 81 TIMES.... | WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Write a version of this COBOL function in VB with identical behavior. | IDENTIFICATION DIVISION.
PROGRAM-ID. CANTOR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SETTINGS.
03 NUM-LINES PIC 9 VALUE 5.
03 FILL-CHAR PIC X VALUE '#'.
01 VARIABLES.
03 CUR-LINE.
05 CHAR PIC X OCCURS 81 TIMES.... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Please provide an equivalent version of this COBOL code in VB. | IDENTIFICATION DIVISION.
PROGRAM-ID. CANTOR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SETTINGS.
03 NUM-LINES PIC 9 VALUE 5.
03 FILL-CHAR PIC X VALUE '#'.
01 VARIABLES.
03 CUR-LINE.
05 CHAR PIC X OCCURS 81 TIMES.... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Change the following COBOL code into Go without altering its purpose. | IDENTIFICATION DIVISION.
PROGRAM-ID. CANTOR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SETTINGS.
03 NUM-LINES PIC 9 VALUE 5.
03 FILL-CHAR PIC X VALUE '#'.
01 VARIABLES.
03 CUR-LINE.
05 CHAR PIC X OCCURS 81 TIMES.... | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Keep all operations the same but rewrite the snippet in Go. | IDENTIFICATION DIVISION.
PROGRAM-ID. CANTOR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SETTINGS.
03 NUM-LINES PIC 9 VALUE 5.
03 FILL-CHAR PIC X VALUE '#'.
01 VARIABLES.
03 CUR-LINE.
05 CHAR PIC X OCCURS 81 TIMES.... | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Write the same code in C as shown below in REXX. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... |
Translate the given REXX code snippet into C without altering its behavior. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... |
Change the following REXX code into C# without altering its purpose. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... |
Convert this REXX block to C#, preserving its control flow and logic. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... |
Maintain the same structure and functionality when rewriting this code in C++. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... |
Change the programming language of this snippet from REXX to C++ without modifying what it does. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... |
Produce a language-to-language conversion: from REXX to Java, same semantics. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... |
Translate the given REXX code snippet into Java without altering its behavior. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... |
Write the same code in Python as shown below in REXX. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Produce a functionally identical Python code for the snippet given in REXX. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Can you help me rewrite this code in VB instead of REXX, keeping it the same logically? |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Generate a VB translation of this REXX snippet without changing its computational steps. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Convert the following code from REXX to Go, ensuring the logic remains intact. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Port the following code from REXX to Go with equivalent syntax and logic. |
w= linesize()
if w==0 then w= 81
do lines=0; _ = 3 ** lines
if _>w then leave
#=_
end
w= # ... | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Convert the following code from Ruby to C, ensuring the logic remains intact. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... |
Produce a functionally identical C code for the snippet given in Ruby. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... |
Write a version of this Ruby function in C# with identical behavior. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... |
Preserve the algorithm and functionality while converting the code from Ruby to C#. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... |
Ensure the translated C++ code behaves exactly like the original Ruby snippet. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... |
Preserve the algorithm and functionality while converting the code from Ruby to C++. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... |
Ensure the translated Java code behaves exactly like the original Ruby snippet. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... |
Write the same algorithm in Java as shown in this Ruby implementation. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... |
Convert this Ruby snippet to Python and keep its semantics consistent. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Rewrite the snippet below in Python so it works the same as the original Ruby code. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Translate this program into VB but keep the logic exactly as in Ruby. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Write the same code in VB as shown below in Ruby. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Convert the following code from Ruby to Go, ensuring the logic remains intact. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Generate a Go translation of this Ruby snippet without changing its computational steps. | lines = 5
(0..lines).each do |exp|
seg_size = 3**(lines-exp-1)
chars = (3**exp).times.map{ |n| n.digits(3).any?(1) ? " " : "█"}
puts chars.map{ |c| c * seg_size }.join
end
| package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Write the same algorithm in C as shown in this Scala implementation. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... |
Port the following code from Scala to C with equivalent syntax and logic. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... |
Port the following code from Scala to C# with equivalent syntax and logic. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... |
Write a version of this Scala function in C# with identical behavior. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... |
Rewrite this program in C++ while keeping its functionality equivalent to the Scala version. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... |
Write the same code in C++ as shown below in Scala. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... |
Ensure the translated Java code behaves exactly like the original Scala snippet. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... |
Convert this Scala snippet to Java and keep its semantics consistent. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... |
Rewrite the snippet below in Python so it works the same as the original Scala code. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Translate this program into Python but keep the logic exactly as in Scala. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Translate the given Scala code snippet into VB without altering its behavior. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Preserve the algorithm and functionality while converting the code from Scala to VB. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Port the following code from Scala to Go with equivalent syntax and logic. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Keep all operations the same but rewrite the snippet in Go. |
const val WIDTH = 81
const val HEIGHT = 5
val lines = List(HEIGHT) { CharArray(WIDTH) { '*' } }
fun cantor(start: Int, len: Int, index: Int) {
val seg = len / 3
if (seg == 0) return
for (i in index until HEIGHT) {
for (j in start + seg until start + seg * 2) lines[i][j] = ' '
}
cantor(st... | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... |
Convert this C snippet to Rust and keep its semantics consistent. | #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Produce a language-to-language conversion: from C to Rust, same semantics. | #include <stdio.h>
#define WIDTH 81
#define HEIGHT 5
char lines[HEIGHT][WIDTH];
void init() {
int i, j;
for (i = 0; i < HEIGHT; ++i) {
for (j = 0; j < WIDTH; ++j) lines[i][j] = '*';
}
}
void cantor(int start, int len, int index) {
int i, j, seg = len / 3;
if (seg == 0) return;
for (i... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Write the same algorithm in Rust as shown in this C# implementation. | using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Convert this C# block to Rust, preserving its control flow and logic. | using System;
namespace CantorSet {
class Program {
const int WIDTH = 81;
const int HEIGHT = 5;
private static char[,] lines = new char[HEIGHT, WIDTH];
static Program() {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Port the provided Java code into Rust while preserving the original functionality. | public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Ensure the translated Rust code behaves exactly like the original Go snippet. | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Please provide an equivalent version of this Rust code in Python. | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... | WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Write the same algorithm in VB as shown in this Rust implementation. | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Port the provided Rust code into VB while preserving the original functionality. | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... | Module Module1
Const WIDTH = 81
Const HEIGHT = 5
Dim lines(HEIGHT, WIDTH) As Char
Sub Init()
For i = 0 To HEIGHT - 1
For j = 0 To WIDTH - 1
lines(i, j) = "*"
Next
Next
End Sub
Sub Cantor(start As Integer, len As Integer, index As Integer... |
Keep all operations the same but rewrite the snippet in Rust. | #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Generate an equivalent Rust version of this Java code. | public class App {
private static final int WIDTH = 81;
private static final int HEIGHT = 5;
private static char[][] lines;
static {
lines = new char[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
lines[i][j] = '*';
... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Ensure the translated Rust code behaves exactly like the original Go snippet. | package main
import "fmt"
const (
width = 81
height = 5
)
var lines [height][width]byte
func init() {
for i := 0; i < height; i++ {
for j := 0; j < width; j++ {
lines[i][j] = '*'
}
}
}
func cantor(start, len, index int) {
seg := len / 3
if seg == 0 {
retu... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Write the same algorithm in Python as shown in this Rust implementation. | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... | WIDTH = 81
HEIGHT = 5
lines=[]
def cantor(start, len, index):
seg = len / 3
if seg == 0:
return None
for it in xrange(HEIGHT-index):
i = index + it
for jt in xrange(seg):
j = start + seg + jt
pos = i * WIDTH + j
lines[pos] = ' '
cantor(start, ... |
Change the programming language of this snippet from C++ to Rust without modifying what it does. | #include <iostream>
const int WIDTH = 81;
const int HEIGHT = 5;
char lines[WIDTH*HEIGHT];
void cantor(int start, int len, int index) {
int seg = len / 3;
if (seg == 0) return;
for (int i = index; i < HEIGHT; i++) {
for (int j = start + seg; j < start + seg * 2; j++) {
int pos = i * WIDTH + j;
lines[pos] =... | use convert_base::Convert;
use std::fmt;
struct CantorSet {
cells: Vec<Vec<bool>>,
}
fn number_to_vec(n: usize) -> Vec<u32> {
n.to_string()
.chars()
.rev()
.map(|c| c.to_digit(10).unwrap())
.collect()
}
impl CantorSet {
fn new(lines: usize) -> CantorSet {
... |
Port the following code from Ada to C# with equivalent syntax and logic. | with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) ... | using System;
using System.IO;
class PPMWriter
{
public static void WriteBitmapToPPM(string file, Bitmap bitmap)
{
var writer = new StreamWriter(file);
writer.WriteLine("P6");
writer.WriteLine($"{bitmap.Width} {bitmap.Height}");
writer.WriteLine(... |
Generate a C translation of this Ada snippet without changing its computational steps. | with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) ... | #include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen("first.ppm", "wb");
(void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0]... |
Write a version of this Ada function in C++ with identical behavior. | with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) ... | #include <fstream>
#include <cstdio>
int main() {
constexpr auto dimx = 800u, dimy = 800u;
using namespace std;
ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
ofs << "P6" << endl << dimx << ' ' << dimy << endl << "255" << endl;
for (auto j = 0u; j < dimy; ++j)
for (auto i = ... |
Translate this program into Go but keep the logic exactly as in Ada. | with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) ... | package raster
import (
"fmt"
"io"
"os"
)
func (b *Bitmap) WritePpmTo(w io.Writer) (err error) {
if _, err = fmt.Fprintln(w, "P6"); err != nil {
return
}
for _, c := range b.Comments {
if _, err = fmt.Fprintln(w, c); err != nil {
return
}
}
... |
Port the following code from Ada to Java with equivalent syntax and logic. | with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) ... | import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PPMWriter {
public void bitmapToPPM(File file, BasicBitmapStorage bitmap) throws IOException {
file.delete();
try (var os =... |
Convert this Ada snippet to Python and keep its semantics consistent. | with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) ... |
import io
ppmfileout = io.StringIO('')
def writeppmp3(self, f):
self.writeppm(f, ppmformat='P3')
def writeppm(self, f, ppmformat='P6'):
assert ppmformat in ['P3', 'P6'], 'Format wrong'
magic = ppmformat + '\n'
comment = '
maxval = max(max(max(bit) for bit in row) for row in self.map)
... |
Translate the given Ada code snippet into VB without altering its behavior. | with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) ... | Public Shared Sub SaveRasterBitmapToPpmFile(ByVal rasterBitmap As RasterBitmap, ByVal filepath As String)
Dim header As String = String.Format("P6{0}{1}{2}{3}{0}255{0}", vbLf, rasterBitmap.Width, " "c, rasterBitmap.Height)
Dim bufferSize As Integer = header.Length + (rasterBitmap.Width * rasterBitmap.Height * 3)
... |
Rewrite this program in C while keeping its functionality equivalent to the AutoHotKey version. | cyan := color(0,255,255)
cyanppm := Bitmap(10, 10, cyan)
Bitmap_write_ppm3(cyanppm, "cyan.ppm")
run, cyan.ppm
return
#include bitmap_storage.ahk
Bitmap_write_ppm3(bitmap, filename)
{
file := FileOpen(filename, 0x11)
file.seek(0,0)
file.write("P3`n"
. bitmap.width . " " . bitmap.height . "`n"
. "255`n")
loop... | #include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen("first.ppm", "wb");
(void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0]... |
Change the following AutoHotKey code into C# without altering its purpose. | cyan := color(0,255,255)
cyanppm := Bitmap(10, 10, cyan)
Bitmap_write_ppm3(cyanppm, "cyan.ppm")
run, cyan.ppm
return
#include bitmap_storage.ahk
Bitmap_write_ppm3(bitmap, filename)
{
file := FileOpen(filename, 0x11)
file.seek(0,0)
file.write("P3`n"
. bitmap.width . " " . bitmap.height . "`n"
. "255`n")
loop... | using System;
using System.IO;
class PPMWriter
{
public static void WriteBitmapToPPM(string file, Bitmap bitmap)
{
var writer = new StreamWriter(file);
writer.WriteLine("P6");
writer.WriteLine($"{bitmap.Width} {bitmap.Height}");
writer.WriteLine(... |
Write the same algorithm in C++ as shown in this AutoHotKey implementation. | cyan := color(0,255,255)
cyanppm := Bitmap(10, 10, cyan)
Bitmap_write_ppm3(cyanppm, "cyan.ppm")
run, cyan.ppm
return
#include bitmap_storage.ahk
Bitmap_write_ppm3(bitmap, filename)
{
file := FileOpen(filename, 0x11)
file.seek(0,0)
file.write("P3`n"
. bitmap.width . " " . bitmap.height . "`n"
. "255`n")
loop... | #include <fstream>
int main() {
constexpr auto dimx = 800u, dimy = 800u;
std::ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
ofs << "P6\n" << dimx << ' ' << dimy << "\n255\n";
for (auto j = 0u; j < dimy; ++j)
for (auto i = 0u; i < dimx; ++i)
ofs << static_cast<char>(... |
Transform the following AutoHotKey implementation into Java, maintaining the same output and logic. | cyan := color(0,255,255)
cyanppm := Bitmap(10, 10, cyan)
Bitmap_write_ppm3(cyanppm, "cyan.ppm")
run, cyan.ppm
return
#include bitmap_storage.ahk
Bitmap_write_ppm3(bitmap, filename)
{
file := FileOpen(filename, 0x11)
file.seek(0,0)
file.write("P3`n"
. bitmap.width . " " . bitmap.height . "`n"
. "255`n")
loop... | import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PPMWriter {
public void bitmapToPPM(File file, BasicBitmapStorage bitmap) throws IOException {
file.delete();
try (var os =... |
Ensure the translated Python code behaves exactly like the original AutoHotKey snippet. | cyan := color(0,255,255)
cyanppm := Bitmap(10, 10, cyan)
Bitmap_write_ppm3(cyanppm, "cyan.ppm")
run, cyan.ppm
return
#include bitmap_storage.ahk
Bitmap_write_ppm3(bitmap, filename)
{
file := FileOpen(filename, 0x11)
file.seek(0,0)
file.write("P3`n"
. bitmap.width . " " . bitmap.height . "`n"
. "255`n")
loop... |
import io
ppmfileout = io.StringIO('')
def writeppmp3(self, f):
self.writeppm(f, ppmformat='P3')
def writeppm(self, f, ppmformat='P6'):
assert ppmformat in ['P3', 'P6'], 'Format wrong'
magic = ppmformat + '\n'
comment = '
maxval = max(max(max(bit) for bit in row) for row in self.map)
... |
Port the provided AutoHotKey code into VB while preserving the original functionality. | cyan := color(0,255,255)
cyanppm := Bitmap(10, 10, cyan)
Bitmap_write_ppm3(cyanppm, "cyan.ppm")
run, cyan.ppm
return
#include bitmap_storage.ahk
Bitmap_write_ppm3(bitmap, filename)
{
file := FileOpen(filename, 0x11)
file.seek(0,0)
file.write("P3`n"
. bitmap.width . " " . bitmap.height . "`n"
. "255`n")
loop... | Public Shared Sub SaveRasterBitmapToPpmFile(ByVal rasterBitmap As RasterBitmap, ByVal filepath As String)
Dim header As String = String.Format("P6{0}{1}{2}{3}{0}255{0}", vbLf, rasterBitmap.Width, " "c, rasterBitmap.Height)
Dim bufferSize As Integer = header.Length + (rasterBitmap.Width * rasterBitmap.Height * 3)
... |
Translate this program into Go but keep the logic exactly as in AutoHotKey. | cyan := color(0,255,255)
cyanppm := Bitmap(10, 10, cyan)
Bitmap_write_ppm3(cyanppm, "cyan.ppm")
run, cyan.ppm
return
#include bitmap_storage.ahk
Bitmap_write_ppm3(bitmap, filename)
{
file := FileOpen(filename, 0x11)
file.seek(0,0)
file.write("P3`n"
. bitmap.width . " " . bitmap.height . "`n"
. "255`n")
loop... | package raster
import (
"fmt"
"io"
"os"
)
func (b *Bitmap) WritePpmTo(w io.Writer) (err error) {
if _, err = fmt.Fprintln(w, "P6"); err != nil {
return
}
for _, c := range b.Comments {
if _, err = fmt.Fprintln(w, c); err != nil {
return
}
}
... |
Generate a C translation of this AWK snippet without changing its computational steps. |
BEGIN {
split("255,0,0,255,255,0",R,",");
split("0,255,0,255,255,0",G,",");
split("0,0,255,0,0,0",B,",");
outfile = "P3.ppm";
printf("P3\n2 3\n255\n") >outfile;
for (k=1; k<=length(R); k++) {
printf("%3i %3i %3i\n",R[k],G[k],B[k])>outfile
}
close(outfile);
}
| #include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen("first.ppm", "wb");
(void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0]... |
Change the following AWK code into C# without altering its purpose. |
BEGIN {
split("255,0,0,255,255,0",R,",");
split("0,255,0,255,255,0",G,",");
split("0,0,255,0,0,0",B,",");
outfile = "P3.ppm";
printf("P3\n2 3\n255\n") >outfile;
for (k=1; k<=length(R); k++) {
printf("%3i %3i %3i\n",R[k],G[k],B[k])>outfile
}
close(outfile);
}
| using System;
using System.IO;
class PPMWriter
{
public static void WriteBitmapToPPM(string file, Bitmap bitmap)
{
var writer = new StreamWriter(file);
writer.WriteLine("P6");
writer.WriteLine($"{bitmap.Width} {bitmap.Height}");
writer.WriteLine(... |
Can you help me rewrite this code in C++ instead of AWK, keeping it the same logically? |
BEGIN {
split("255,0,0,255,255,0",R,",");
split("0,255,0,255,255,0",G,",");
split("0,0,255,0,0,0",B,",");
outfile = "P3.ppm";
printf("P3\n2 3\n255\n") >outfile;
for (k=1; k<=length(R); k++) {
printf("%3i %3i %3i\n",R[k],G[k],B[k])>outfile
}
close(outfile);
}
| #include <fstream>
int main() {
constexpr auto dimx = 800u, dimy = 800u;
std::ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
ofs << "P6\n" << dimx << ' ' << dimy << "\n255\n";
for (auto j = 0u; j < dimy; ++j)
for (auto i = 0u; i < dimx; ++i)
ofs << static_cast<char>(... |
Produce a functionally identical Java code for the snippet given in AWK. |
BEGIN {
split("255,0,0,255,255,0",R,",");
split("0,255,0,255,255,0",G,",");
split("0,0,255,0,0,0",B,",");
outfile = "P3.ppm";
printf("P3\n2 3\n255\n") >outfile;
for (k=1; k<=length(R); k++) {
printf("%3i %3i %3i\n",R[k],G[k],B[k])>outfile
}
close(outfile);
}
| import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PPMWriter {
public void bitmapToPPM(File file, BasicBitmapStorage bitmap) throws IOException {
file.delete();
try (var os =... |
Transform the following AWK implementation into Python, maintaining the same output and logic. |
BEGIN {
split("255,0,0,255,255,0",R,",");
split("0,255,0,255,255,0",G,",");
split("0,0,255,0,0,0",B,",");
outfile = "P3.ppm";
printf("P3\n2 3\n255\n") >outfile;
for (k=1; k<=length(R); k++) {
printf("%3i %3i %3i\n",R[k],G[k],B[k])>outfile
}
close(outfile);
}
|
import io
ppmfileout = io.StringIO('')
def writeppmp3(self, f):
self.writeppm(f, ppmformat='P3')
def writeppm(self, f, ppmformat='P6'):
assert ppmformat in ['P3', 'P6'], 'Format wrong'
magic = ppmformat + '\n'
comment = '
maxval = max(max(max(bit) for bit in row) for row in self.map)
... |
Port the provided AWK code into VB while preserving the original functionality. |
BEGIN {
split("255,0,0,255,255,0",R,",");
split("0,255,0,255,255,0",G,",");
split("0,0,255,0,0,0",B,",");
outfile = "P3.ppm";
printf("P3\n2 3\n255\n") >outfile;
for (k=1; k<=length(R); k++) {
printf("%3i %3i %3i\n",R[k],G[k],B[k])>outfile
}
close(outfile);
}
| Public Shared Sub SaveRasterBitmapToPpmFile(ByVal rasterBitmap As RasterBitmap, ByVal filepath As String)
Dim header As String = String.Format("P6{0}{1}{2}{3}{0}255{0}", vbLf, rasterBitmap.Width, " "c, rasterBitmap.Height)
Dim bufferSize As Integer = header.Length + (rasterBitmap.Width * rasterBitmap.Height * 3)
... |
Write the same algorithm in Go as shown in this AWK implementation. |
BEGIN {
split("255,0,0,255,255,0",R,",");
split("0,255,0,255,255,0",G,",");
split("0,0,255,0,0,0",B,",");
outfile = "P3.ppm";
printf("P3\n2 3\n255\n") >outfile;
for (k=1; k<=length(R); k++) {
printf("%3i %3i %3i\n",R[k],G[k],B[k])>outfile
}
close(outfile);
}
| package raster
import (
"fmt"
"io"
"os"
)
func (b *Bitmap) WritePpmTo(w io.Writer) (err error) {
if _, err = fmt.Fprintln(w, "P6"); err != nil {
return
}
for _, c := range b.Comments {
if _, err = fmt.Fprintln(w, c); err != nil {
return
}
}
... |
Write the same code in C as shown below in BBC_Basic. | Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lena
f% = OPENOUT("c:\lena.ppm")
IF f%=0 ERROR 100, "Failed to open output file"
BPUT #f%, "P6"
BPUT #f%, "# Created using BBC BASIC"
BPUT #f%, STR$(Width%) + " " +STR$(Height%... | #include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen("first.ppm", "wb");
(void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0]... |
Maintain the same structure and functionality when rewriting this code in C#. | Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lena
f% = OPENOUT("c:\lena.ppm")
IF f%=0 ERROR 100, "Failed to open output file"
BPUT #f%, "P6"
BPUT #f%, "# Created using BBC BASIC"
BPUT #f%, STR$(Width%) + " " +STR$(Height%... | using System;
using System.IO;
class PPMWriter
{
public static void WriteBitmapToPPM(string file, Bitmap bitmap)
{
var writer = new StreamWriter(file);
writer.WriteLine("P6");
writer.WriteLine($"{bitmap.Width} {bitmap.Height}");
writer.WriteLine(... |
Ensure the translated C++ code behaves exactly like the original BBC_Basic snippet. | Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lena
f% = OPENOUT("c:\lena.ppm")
IF f%=0 ERROR 100, "Failed to open output file"
BPUT #f%, "P6"
BPUT #f%, "# Created using BBC BASIC"
BPUT #f%, STR$(Width%) + " " +STR$(Height%... | #include <fstream>
int main() {
constexpr auto dimx = 800u, dimy = 800u;
std::ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
ofs << "P6\n" << dimx << ' ' << dimy << "\n255\n";
for (auto j = 0u; j < dimy; ++j)
for (auto i = 0u; i < dimx; ++i)
ofs << static_cast<char>(... |
Change the programming language of this snippet from BBC_Basic to Java without modifying what it does. | Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lena
f% = OPENOUT("c:\lena.ppm")
IF f%=0 ERROR 100, "Failed to open output file"
BPUT #f%, "P6"
BPUT #f%, "# Created using BBC BASIC"
BPUT #f%, STR$(Width%) + " " +STR$(Height%... | import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PPMWriter {
public void bitmapToPPM(File file, BasicBitmapStorage bitmap) throws IOException {
file.delete();
try (var os =... |
Transform the following BBC_Basic implementation into Python, maintaining the same output and logic. | Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lena
f% = OPENOUT("c:\lena.ppm")
IF f%=0 ERROR 100, "Failed to open output file"
BPUT #f%, "P6"
BPUT #f%, "# Created using BBC BASIC"
BPUT #f%, STR$(Width%) + " " +STR$(Height%... |
import io
ppmfileout = io.StringIO('')
def writeppmp3(self, f):
self.writeppm(f, ppmformat='P3')
def writeppm(self, f, ppmformat='P6'):
assert ppmformat in ['P3', 'P6'], 'Format wrong'
magic = ppmformat + '\n'
comment = '
maxval = max(max(max(bit) for bit in row) for row in self.map)
... |
Keep all operations the same but rewrite the snippet in VB. | Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lena
f% = OPENOUT("c:\lena.ppm")
IF f%=0 ERROR 100, "Failed to open output file"
BPUT #f%, "P6"
BPUT #f%, "# Created using BBC BASIC"
BPUT #f%, STR$(Width%) + " " +STR$(Height%... | Public Shared Sub SaveRasterBitmapToPpmFile(ByVal rasterBitmap As RasterBitmap, ByVal filepath As String)
Dim header As String = String.Format("P6{0}{1}{2}{3}{0}255{0}", vbLf, rasterBitmap.Width, " "c, rasterBitmap.Height)
Dim bufferSize As Integer = header.Length + (rasterBitmap.Width * rasterBitmap.Height * 3)
... |
Rewrite the snippet below in Go so it works the same as the original BBC_Basic code. | Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lena
f% = OPENOUT("c:\lena.ppm")
IF f%=0 ERROR 100, "Failed to open output file"
BPUT #f%, "P6"
BPUT #f%, "# Created using BBC BASIC"
BPUT #f%, STR$(Width%) + " " +STR$(Height%... | package raster
import (
"fmt"
"io"
"os"
)
func (b *Bitmap) WritePpmTo(w io.Writer) (err error) {
if _, err = fmt.Fprintln(w, "P6"); err != nil {
return
}
for _, c := range b.Comments {
if _, err = fmt.Fprintln(w, c); err != nil {
return
}
}
... |
Convert the following code from Common_Lisp to C, ensuring the logic remains intact. | (defun write-rgb-buffer-to-ppm-file (filename buffer)
(with-open-file (stream filename
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(let* ((dimensions (array-dimensions buffer))
(width (first dimensions))
(height (second dimens... | #include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen("first.ppm", "wb");
(void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0]... |
Translate this program into C# but keep the logic exactly as in Common_Lisp. | (defun write-rgb-buffer-to-ppm-file (filename buffer)
(with-open-file (stream filename
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(let* ((dimensions (array-dimensions buffer))
(width (first dimensions))
(height (second dimens... | using System;
using System.IO;
class PPMWriter
{
public static void WriteBitmapToPPM(string file, Bitmap bitmap)
{
var writer = new StreamWriter(file);
writer.WriteLine("P6");
writer.WriteLine($"{bitmap.Width} {bitmap.Height}");
writer.WriteLine(... |
Rewrite this program in C++ while keeping its functionality equivalent to the Common_Lisp version. | (defun write-rgb-buffer-to-ppm-file (filename buffer)
(with-open-file (stream filename
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(let* ((dimensions (array-dimensions buffer))
(width (first dimensions))
(height (second dimens... | #include <fstream>
int main() {
constexpr auto dimx = 800u, dimy = 800u;
std::ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
ofs << "P6\n" << dimx << ' ' << dimy << "\n255\n";
for (auto j = 0u; j < dimy; ++j)
for (auto i = 0u; i < dimx; ++i)
ofs << static_cast<char>(... |
Convert the following code from Common_Lisp to Java, ensuring the logic remains intact. | (defun write-rgb-buffer-to-ppm-file (filename buffer)
(with-open-file (stream filename
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(let* ((dimensions (array-dimensions buffer))
(width (first dimensions))
(height (second dimens... | import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PPMWriter {
public void bitmapToPPM(File file, BasicBitmapStorage bitmap) throws IOException {
file.delete();
try (var os =... |
Preserve the algorithm and functionality while converting the code from Common_Lisp to Python. | (defun write-rgb-buffer-to-ppm-file (filename buffer)
(with-open-file (stream filename
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(let* ((dimensions (array-dimensions buffer))
(width (first dimensions))
(height (second dimens... |
import io
ppmfileout = io.StringIO('')
def writeppmp3(self, f):
self.writeppm(f, ppmformat='P3')
def writeppm(self, f, ppmformat='P6'):
assert ppmformat in ['P3', 'P6'], 'Format wrong'
magic = ppmformat + '\n'
comment = '
maxval = max(max(max(bit) for bit in row) for row in self.map)
... |
Rewrite the snippet below in VB so it works the same as the original Common_Lisp code. | (defun write-rgb-buffer-to-ppm-file (filename buffer)
(with-open-file (stream filename
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(let* ((dimensions (array-dimensions buffer))
(width (first dimensions))
(height (second dimens... | Public Shared Sub SaveRasterBitmapToPpmFile(ByVal rasterBitmap As RasterBitmap, ByVal filepath As String)
Dim header As String = String.Format("P6{0}{1}{2}{3}{0}255{0}", vbLf, rasterBitmap.Width, " "c, rasterBitmap.Height)
Dim bufferSize As Integer = header.Length + (rasterBitmap.Width * rasterBitmap.Height * 3)
... |
Write the same code in Go as shown below in Common_Lisp. | (defun write-rgb-buffer-to-ppm-file (filename buffer)
(with-open-file (stream filename
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(let* ((dimensions (array-dimensions buffer))
(width (first dimensions))
(height (second dimens... | package raster
import (
"fmt"
"io"
"os"
)
func (b *Bitmap) WritePpmTo(w io.Writer) (err error) {
if _, err = fmt.Fprintln(w, "P6"); err != nil {
return
}
for _, c := range b.Comments {
if _, err = fmt.Fprintln(w, c); err != nil {
return
}
}
... |
Write the same algorithm in C as shown in this Delphi implementation. | program btm2ppm;
uses
System.SysUtils,
System.Classes,
Vcl.Graphics;
type
TBitmapHelper = class helper for TBitmap
public
procedure SaveAsPPM(FileName: TFileName);
end;
procedure TBitmapHelper.SaveAsPPM(FileName: TFileName);
var
i, j, color: Integer;
Header: AnsiString;
ppm: TMemoryStream... | #include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen("first.ppm", "wb");
(void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0]... |
Convert this Delphi snippet to C# and keep its semantics consistent. | program btm2ppm;
uses
System.SysUtils,
System.Classes,
Vcl.Graphics;
type
TBitmapHelper = class helper for TBitmap
public
procedure SaveAsPPM(FileName: TFileName);
end;
procedure TBitmapHelper.SaveAsPPM(FileName: TFileName);
var
i, j, color: Integer;
Header: AnsiString;
ppm: TMemoryStream... | using System;
using System.IO;
class PPMWriter
{
public static void WriteBitmapToPPM(string file, Bitmap bitmap)
{
var writer = new StreamWriter(file);
writer.WriteLine("P6");
writer.WriteLine($"{bitmap.Width} {bitmap.Height}");
writer.WriteLine(... |
Generate an equivalent C++ version of this Delphi code. | program btm2ppm;
uses
System.SysUtils,
System.Classes,
Vcl.Graphics;
type
TBitmapHelper = class helper for TBitmap
public
procedure SaveAsPPM(FileName: TFileName);
end;
procedure TBitmapHelper.SaveAsPPM(FileName: TFileName);
var
i, j, color: Integer;
Header: AnsiString;
ppm: TMemoryStream... | #include <fstream>
int main() {
constexpr auto dimx = 800u, dimy = 800u;
std::ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
ofs << "P6\n" << dimx << ' ' << dimy << "\n255\n";
for (auto j = 0u; j < dimy; ++j)
for (auto i = 0u; i < dimx; ++i)
ofs << static_cast<char>(... |
Convert the following code from Delphi to Java, ensuring the logic remains intact. | program btm2ppm;
uses
System.SysUtils,
System.Classes,
Vcl.Graphics;
type
TBitmapHelper = class helper for TBitmap
public
procedure SaveAsPPM(FileName: TFileName);
end;
procedure TBitmapHelper.SaveAsPPM(FileName: TFileName);
var
i, j, color: Integer;
Header: AnsiString;
ppm: TMemoryStream... | import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PPMWriter {
public void bitmapToPPM(File file, BasicBitmapStorage bitmap) throws IOException {
file.delete();
try (var os =... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.