Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Write a version of this REXX function in C with identical behavior.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
#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]...
Ensure the translated C# code behaves exactly like the original REXX snippet.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
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(...
Change the following REXX code into C++ without altering its purpose.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
#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>(...
Preserve the algorithm and functionality while converting the code from REXX to Java.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
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 =...
Translate this program into Python but keep the logic exactly as in REXX.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
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) ...
Change the following REXX code into VB without altering its purpose.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
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 a version of this REXX function in Go with identical behavior.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
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 } } ...
Can you help me rewrite this code in C instead of Ruby, keeping it the same logically?
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
#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 the given Ruby code snippet into C# without altering its behavior.
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
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 a version of this Ruby function in C++ with identical behavior.
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
#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>(...
Write a version of this Ruby function in Java with identical behavior.
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
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 =...
Keep all operations the same but rewrite the snippet in Python.
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
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) ...
Write a version of this Ruby function in VB with identical behavior.
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
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 Ruby code.
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
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 } } ...
Change the programming language of this snippet from Scala to C without modifying what it does.
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
#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]...
Can you help me rewrite this code in C# instead of Scala, keeping it the same logically?
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
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(...
Translate this program into C++ but keep the logic exactly as in Scala.
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
#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>(...
Please provide an equivalent version of this Scala code in Java.
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
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 =...
Translate the given Scala code snippet into Python without altering its behavior.
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
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 Scala code snippet into VB without altering its behavior.
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
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) ...
Transform the following Scala implementation into Go, maintaining the same output and logic.
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
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 } } ...
Ensure the translated C code behaves exactly like the original Tcl snippet.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
#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]...
Rewrite this program in C# while keeping its functionality equivalent to the Tcl version.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
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(...
Change the following Tcl code into C++ without altering its purpose.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
#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>(...
Preserve the algorithm and functionality while converting the code from Tcl to Java.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
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 =...
Maintain the same structure and functionality when rewriting this code in Python.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
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) ...
Write the same code in VB as shown below in Tcl.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
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 Tcl.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
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 } } ...
Translate this program into PHP but keep the logic exactly as in Rust.
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Change the following Ada code into PHP without altering its purpose.
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) ...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Maintain the same structure and functionality when rewriting this code in PHP.
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...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Produce a language-to-language conversion: from AWK to PHP, same semantics.
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); }
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Translate this program into PHP but keep the logic exactly as 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%...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Convert the following code from Common_Lisp to PHP, 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...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Maintain the same structure and functionality when rewriting this code in PHP.
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...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Change the programming language of this snippet from Erlang to PHP without modifying what it does.
-module(ppm). -export([ppm/1, write/2]). -define(WHITESPACE, <<10>>). -define(SPACE, <<32>>). -record(bitmap, { pixels = nil, shape = {0, 0} }). ppm(Bitmap) -> {Width, Height} = Bitmap#bitmap.shape, Pixels = ppm_pixels(Bitmap), Maxval = 255, list_to_binary([ header(), width_and_h...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Convert this Forth snippet to PHP and keep its semantics consistent.
: write-ppm { bmp fid -- } s" P6" fid write-line throw bmp bdim swap 0 <# bl hold #s #> fid write-file throw 0 <# #s #> fid write-line throw s" 255" fid write-line throw bmp bdata bmp bdim * pixels bounds do i 3 fid write-file throw pixel +loop ; s" red....
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Convert the following code from Fortran to PHP, ensuring the logic remains intact.
program main use rgbimage_m implicit none integer :: nx, ny, i, j, k type(rgbimage) :: im nx = 400 ny = 300 call im%init(nx, ny) do i = 1, nx do j = 1, ny call im%set_pixel(i, j, [(nint(rand()*255), k=1,3)]) end do end do call im%write('fig.ppm') end program
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Please provide an equivalent version of this Haskell code in PHP.
module Bitmap.Netpbm(readNetpbm, writeNetpbm) where import Bitmap import Data.Char import System.IO import Control.Monad import Control.Monad.ST import Data.Array.ST nil :: a nil = undefined readNetpbm :: forall c. Color c => FilePath -> IO (Image RealWorld c) readNetpbm path = do let die = fail "readNetpbm: b...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Write the same algorithm in PHP as shown in this J implementation.
require 'files' writeppm=:dyad define header=. 'P6',LF,(":1 0{$x),LF,'255',LF (header,,x{a.) fwrite y )
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Produce a language-to-language conversion: from Julia to PHP, same semantics.
using Images, FileIO h, w = 50, 70 img = zeros(RGB{N0f8}, h, w) img[10:40, 5:35] = colorant"skyblue" for i in 26:50, j in (i-25):40 img[i, j] = colorant"sienna1" end save("data/bitmapWrite.ppm", img) save("data/bitmapWrite.png", img)
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Change the programming language of this snippet from Lua to PHP without modifying what it does.
local array_fill = function(vbegin, vend, value) local t = {} for i=vbegin, vend do t[i] = value end return t end Bitmap = {} Bitmap.__index = Bitmap function Bitmap.new(width, height) local self = {} setmetatable(self, Bitmap) local white = array_fill(0, width, {255, 255, 255}) ...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Port the following code from Mathematica to PHP with equivalent syntax and logic.
Export["file.ppm",image,"PPM"]
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Produce a functionally identical PHP code for the snippet given in MATLAB.
R=[255,0,0;255,255,0]; G=[0,255,0;255,255,0]; B=[0,0,255;0,0,0]; r = R'; r(:); g = R'; g(:); b = R'; b(:); fid=fopen('p6.ppm','w'); fprintf(fid,'P6\n fwrite(fid,[r,g,b]','uint8'); fclose(fid);
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Preserve the algorithm and functionality while converting the code from Nim to PHP.
import bitmap import streams proc writePPM*(img: Image, stream: Stream) = stream.writeLine("P6 ", $img.w, " ", $img.h, " 255") for x, y in img.indices: stream.write(chr(img[x, y].r)) stream.write(chr(img[x, y].g)) stream.write(chr(img[x, y].b)) proc writePPM*(img: Image; filename: string) = ...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Change the following OCaml code into PHP without altering its purpose.
let output_ppm ~oc ~img:(_, r_channel, g_channel, b_channel) = let width = Bigarray.Array2.dim1 r_channel and height = Bigarray.Array2.dim2 r_channel in Printf.fprintf oc "P6\n%d %d\n255\n" width height; for y = 0 to pred height do for x = 0 to pred width do output_char oc (char_of_int r_channel.{x,y}...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Write the same code in PHP as shown below in Perl.
use Imager; $image = Imager->new(xsize => 200, ysize => 200); $image->box(filled => 1, color => red); $image->box(filled => 1, color => black, xmin => 50, ymin => 50, xmax => 150, ymax => 150); $image->write(file => 'bitmap.ppm') or die $image->errstr;
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Keep all operations the same but rewrite the snippet in PHP.
library(pixmap) pixmap::write.pnm write.pnm(theimage, filename)
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Please provide an equivalent version of this Racket code in PHP.
(define (bitmap->ppm bitmap output-port) (define height (send bitmap get-height)) (define width (send bitmap get-width)) (define buffer (make-bytes (* width height 4))) (send bitmap get-argb-pixels 0 0 width height buffer) (parameterize ([current-output-port output-port]) (printf "P3\n~a ~a\n255" widt...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Generate an equivalent PHP version of this REXX code.
green = 00ff00 parse arg oFN width height color . if oFN=='' | oFN=="," then oFN='IMAGE' if width=='' | width=="," then width= 20 if height=='' | height=="," then height= 20 if color=='' | color=="," then color= green oFID= oFN'.PPM' ...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Transform the following Ruby implementation into PHP, maintaining the same output and logic.
class RGBColour def values [@red, @green, @blue] end end class Pixmap def save(filename) File.open(filename, 'w') do |f| f.puts "P6", " f.binmode @height.times do |y| @width.times do |x| f.print @data[x][y].values.pack('C3') end end end end alias_...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Ensure the translated PHP code behaves exactly like the original Scala snippet.
import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.FileOutputStream class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR) fun fill(c: Color) { val g = image.graphics g.color = ...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Rewrite the snippet below in PHP so it works the same as the original Tcl code.
package require Tk proc output_ppm {image filename} { $image write $filename -format ppm } set img [newImage 150 150] fill $img red setPixel $img green 40 40 output_ppm $img filename.ppm set fh [open filename.ppm] puts [gets $fh] ; puts [gets $fh] ; puts [gets $fh] ; binary scan [read $fh 3] c3 pixel foreach co...
class Bitmap { public $data; public $w; public $h; public function __construct($w = 16, $h = 16){ $white = array_fill(0, $w, array(255,255,255)); $this->data = array_fill(0, $h, $white); $this->w = $w; $this->h = $h; } public function fill($x = 0, $y = 0, $w = null, $h = null, $color = arra...
Write a version of this C function in Rust with identical behavior.
#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]...
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
Please provide an equivalent version of this C# code in Rust.
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(...
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
Rewrite this program in Rust while keeping its functionality equivalent to the Java version.
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 =...
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
Preserve the algorithm and functionality while converting the code from Rust to Python.
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
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) ...
Produce a language-to-language conversion: from Rust to VB, same semantics.
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
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) ...
Generate an equivalent Rust version of this C++ code.
#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 = ...
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
Write the same code in Rust as shown below in Go.
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 } } ...
use std::path::Path; use std::io::Write; use std::fs::File; pub struct RGB { r: u8, g: u8, b: u8, } pub struct PPM { height: u32, width: u32, data: Vec<u8>, } impl PPM { pub fn new(height: u32, width: u32) -> PPM { let size = 3 * height * width; let buffer = vec![0; size a...
Convert the following code from Ada to C#, ensuring the logic remains intact.
with Ada.Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; procedure Two_Dimensional_Arrays is type Matrix_Type is array(Positive range <>, Positive range <>) of Float; Dim_1 : Positive; Dim_2 : Positive; begin Ada.Integer_Text_Io.Get(Item => Dim_1); Ada.Integer_Text_Io.Get(Item => Dim_2); ...
class Program { static void Main(string[] args) { Console.WriteLine("Enter two integers. Space delimited please: "); string s = Console.ReadLine(); int[,] myArray=new int[(int)s[0],(int)s[2]]; myArray[0, 0] = 2; Console.WriteLi...
Change the programming language of this snippet from Ada to C without modifying what it does.
with Ada.Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; procedure Two_Dimensional_Arrays is type Matrix_Type is array(Positive range <>, Positive range <>) of Float; Dim_1 : Positive; Dim_2 : Positive; begin Ada.Integer_Text_Io.Get(Item => Dim_1); Ada.Integer_Text_Io.Get(Item => Dim_2); ...
#include <stdio.h> int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf("Enter two integers. Space delimited, please: "); scanf("%d %d",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][use...
Please provide an equivalent version of this Ada code in C++.
with Ada.Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; procedure Two_Dimensional_Arrays is type Matrix_Type is array(Positive range <>, Positive range <>) of Float; Dim_1 : Positive; Dim_2 : Positive; begin Ada.Integer_Text_Io.Get(Item => Dim_1); Ada.Integer_Text_Io.Get(Item => Dim_2); ...
#include <iostream> int main() { int dim1, dim2; std::cin >> dim1 >> dim2; double* array_data = new double[dim1*dim2]; double** array = new double*[dim1]; for (int i = 0; i < dim1; ++i) array[i] = array_data + dim2*i; array[0][0] = 3.5; std::cout << array[0][0] << std::endl; dele...
Rewrite the snippet below in Go so it works the same as the original Ada code.
with Ada.Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; procedure Two_Dimensional_Arrays is type Matrix_Type is array(Positive range <>, Positive range <>) of Float; Dim_1 : Positive; Dim_2 : Positive; begin Ada.Integer_Text_Io.Get(Item => Dim_1); Ada.Integer_Text_Io.Get(Item => Dim_2); ...
package main import "fmt" func main() { var row, col int fmt.Print("enter rows cols: ") fmt.Scan(&row, &col) a := make([][]int, row) for i := range a { a[i] = make([]int, col) } fmt.Println("a[0][0] =", a[0][0]) a[row-1][col-1] = 7 fmt.Printf("a[%d][...
Rewrite the snippet below in Java so it works the same as the original Ada code.
with Ada.Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; procedure Two_Dimensional_Arrays is type Matrix_Type is array(Positive range <>, Positive range <>) of Float; Dim_1 : Positive; Dim_2 : Positive; begin Ada.Integer_Text_Io.Get(Item => Dim_1); Ada.Integer_Text_Io.Get(Item => Dim_2); ...
import java.util.Scanner; public class twoDimArray { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nbr1 = in.nextInt(); int nbr2 = in.nextInt(); double[][] array = new double[nbr1][nbr2]; array[0][0] = 42.0; System....
Produce a language-to-language conversion: from Ada to Python, same semantics.
with Ada.Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; procedure Two_Dimensional_Arrays is type Matrix_Type is array(Positive range <>, Positive range <>) of Float; Dim_1 : Positive; Dim_2 : Positive; begin Ada.Integer_Text_Io.Get(Item => Dim_1); Ada.Integer_Text_Io.Get(Item => Dim_2); ...
width = int(raw_input("Width of myarray: ")) height = int(raw_input("Height of Array: ")) myarray = [[0] * width for i in range(height)] myarray[0][0] = 3.5 print (myarray[0][0])
Generate an equivalent VB version of this Ada code.
with Ada.Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; procedure Two_Dimensional_Arrays is type Matrix_Type is array(Positive range <>, Positive range <>) of Float; Dim_1 : Positive; Dim_2 : Positive; begin Ada.Integer_Text_Io.Get(Item => Dim_1); Ada.Integer_Text_Io.Get(Item => Dim_2); ...
Module Program Sub Main() Console.WriteLine("Enter two space-delimited integers:") Dim input = Console.ReadLine().Split() Dim rows = Integer.Parse(input(0)) Dim cols = Integer.Parse(input(1)) Dim arr(rows - 1, cols - 1) As Integer arr(0, 0) = 2 Cons...
Rewrite the snippet below in C so it works the same as the original Arturo code.
width: to :integer input "give me the array's width: " height: to :integer input "give me the array's height: " arr: array.of: @[width height] 0 x: random 0 dec width y: random 0 dec height arr\[x]\[y]: 123 print ["item at [" x "," y "] =" arr\[x]\[y]]
#include <stdio.h> int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf("Enter two integers. Space delimited, please: "); scanf("%d %d",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][use...
Please provide an equivalent version of this Arturo code in C#.
width: to :integer input "give me the array's width: " height: to :integer input "give me the array's height: " arr: array.of: @[width height] 0 x: random 0 dec width y: random 0 dec height arr\[x]\[y]: 123 print ["item at [" x "," y "] =" arr\[x]\[y]]
class Program { static void Main(string[] args) { Console.WriteLine("Enter two integers. Space delimited please: "); string s = Console.ReadLine(); int[,] myArray=new int[(int)s[0],(int)s[2]]; myArray[0, 0] = 2; Console.WriteLi...
Preserve the algorithm and functionality while converting the code from Arturo to C++.
width: to :integer input "give me the array's width: " height: to :integer input "give me the array's height: " arr: array.of: @[width height] 0 x: random 0 dec width y: random 0 dec height arr\[x]\[y]: 123 print ["item at [" x "," y "] =" arr\[x]\[y]]
#include <iostream> int main() { int dim1, dim2; std::cin >> dim1 >> dim2; double* array_data = new double[dim1*dim2]; double** array = new double*[dim1]; for (int i = 0; i < dim1; ++i) array[i] = array_data + dim2*i; array[0][0] = 3.5; std::cout << array[0][0] << std::endl; dele...
Ensure the translated Java code behaves exactly like the original Arturo snippet.
width: to :integer input "give me the array's width: " height: to :integer input "give me the array's height: " arr: array.of: @[width height] 0 x: random 0 dec width y: random 0 dec height arr\[x]\[y]: 123 print ["item at [" x "," y "] =" arr\[x]\[y]]
import java.util.Scanner; public class twoDimArray { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nbr1 = in.nextInt(); int nbr2 = in.nextInt(); double[][] array = new double[nbr1][nbr2]; array[0][0] = 42.0; System....
Maintain the same structure and functionality when rewriting this code in Python.
width: to :integer input "give me the array's width: " height: to :integer input "give me the array's height: " arr: array.of: @[width height] 0 x: random 0 dec width y: random 0 dec height arr\[x]\[y]: 123 print ["item at [" x "," y "] =" arr\[x]\[y]]
width = int(raw_input("Width of myarray: ")) height = int(raw_input("Height of Array: ")) myarray = [[0] * width for i in range(height)] myarray[0][0] = 3.5 print (myarray[0][0])
Generate an equivalent VB version of this Arturo code.
width: to :integer input "give me the array's width: " height: to :integer input "give me the array's height: " arr: array.of: @[width height] 0 x: random 0 dec width y: random 0 dec height arr\[x]\[y]: 123 print ["item at [" x "," y "] =" arr\[x]\[y]]
Module Program Sub Main() Console.WriteLine("Enter two space-delimited integers:") Dim input = Console.ReadLine().Split() Dim rows = Integer.Parse(input(0)) Dim cols = Integer.Parse(input(1)) Dim arr(rows - 1, cols - 1) As Integer arr(0, 0) = 2 Cons...
Rewrite this program in Go while keeping its functionality equivalent to the Arturo version.
width: to :integer input "give me the array's width: " height: to :integer input "give me the array's height: " arr: array.of: @[width height] 0 x: random 0 dec width y: random 0 dec height arr\[x]\[y]: 123 print ["item at [" x "," y "] =" arr\[x]\[y]]
package main import "fmt" func main() { var row, col int fmt.Print("enter rows cols: ") fmt.Scan(&row, &col) a := make([][]int, row) for i := range a { a[i] = make([]int, col) } fmt.Println("a[0][0] =", a[0][0]) a[row-1][col-1] = 7 fmt.Printf("a[%d][...
Ensure the translated C code behaves exactly like the original AutoHotKey snippet.
Array := [] InputBox, data,, Enter two integers separated by a Space:`n(ex. 5 7) StringSplit, i, data, %A_Space% Array[i1,i2] := "that element" MsgBox, % "Array[" i1 "," i2 "] = " Array[i1,i2]
#include <stdio.h> int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf("Enter two integers. Space delimited, please: "); scanf("%d %d",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][use...
Keep all operations the same but rewrite the snippet in C#.
Array := [] InputBox, data,, Enter two integers separated by a Space:`n(ex. 5 7) StringSplit, i, data, %A_Space% Array[i1,i2] := "that element" MsgBox, % "Array[" i1 "," i2 "] = " Array[i1,i2]
class Program { static void Main(string[] args) { Console.WriteLine("Enter two integers. Space delimited please: "); string s = Console.ReadLine(); int[,] myArray=new int[(int)s[0],(int)s[2]]; myArray[0, 0] = 2; Console.WriteLi...
Port the provided AutoHotKey code into C++ while preserving the original functionality.
Array := [] InputBox, data,, Enter two integers separated by a Space:`n(ex. 5 7) StringSplit, i, data, %A_Space% Array[i1,i2] := "that element" MsgBox, % "Array[" i1 "," i2 "] = " Array[i1,i2]
#include <iostream> int main() { int dim1, dim2; std::cin >> dim1 >> dim2; double* array_data = new double[dim1*dim2]; double** array = new double*[dim1]; for (int i = 0; i < dim1; ++i) array[i] = array_data + dim2*i; array[0][0] = 3.5; std::cout << array[0][0] << std::endl; dele...
Generate an equivalent Java version of this AutoHotKey code.
Array := [] InputBox, data,, Enter two integers separated by a Space:`n(ex. 5 7) StringSplit, i, data, %A_Space% Array[i1,i2] := "that element" MsgBox, % "Array[" i1 "," i2 "] = " Array[i1,i2]
import java.util.Scanner; public class twoDimArray { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nbr1 = in.nextInt(); int nbr2 = in.nextInt(); double[][] array = new double[nbr1][nbr2]; array[0][0] = 42.0; System....
Translate the given AutoHotKey code snippet into Python without altering its behavior.
Array := [] InputBox, data,, Enter two integers separated by a Space:`n(ex. 5 7) StringSplit, i, data, %A_Space% Array[i1,i2] := "that element" MsgBox, % "Array[" i1 "," i2 "] = " Array[i1,i2]
width = int(raw_input("Width of myarray: ")) height = int(raw_input("Height of Array: ")) myarray = [[0] * width for i in range(height)] myarray[0][0] = 3.5 print (myarray[0][0])
Port the following code from AutoHotKey to VB with equivalent syntax and logic.
Array := [] InputBox, data,, Enter two integers separated by a Space:`n(ex. 5 7) StringSplit, i, data, %A_Space% Array[i1,i2] := "that element" MsgBox, % "Array[" i1 "," i2 "] = " Array[i1,i2]
Module Program Sub Main() Console.WriteLine("Enter two space-delimited integers:") Dim input = Console.ReadLine().Split() Dim rows = Integer.Parse(input(0)) Dim cols = Integer.Parse(input(1)) Dim arr(rows - 1, cols - 1) As Integer arr(0, 0) = 2 Cons...
Generate a Go translation of this AutoHotKey snippet without changing its computational steps.
Array := [] InputBox, data,, Enter two integers separated by a Space:`n(ex. 5 7) StringSplit, i, data, %A_Space% Array[i1,i2] := "that element" MsgBox, % "Array[" i1 "," i2 "] = " Array[i1,i2]
package main import "fmt" func main() { var row, col int fmt.Print("enter rows cols: ") fmt.Scan(&row, &col) a := make([][]int, row) for i := range a { a[i] = make([]int, col) } fmt.Println("a[0][0] =", a[0][0]) a[row-1][col-1] = 7 fmt.Printf("a[%d][...
Can you help me rewrite this code in C instead of AWK, keeping it the same logically?
/[0-9]+ [0-9]+/ { for(i=0; i < $1; i++) { for(j=0; j < $2; j++) { arr[i, j] = i*j } } for (comb in arr) { split(comb, idx, SUBSEP) print idx[1] "," idx[2] "->" arr[idx[1], idx[2]] } }
#include <stdio.h> int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf("Enter two integers. Space delimited, please: "); scanf("%d %d",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][use...
Produce a functionally identical C# code for the snippet given in AWK.
/[0-9]+ [0-9]+/ { for(i=0; i < $1; i++) { for(j=0; j < $2; j++) { arr[i, j] = i*j } } for (comb in arr) { split(comb, idx, SUBSEP) print idx[1] "," idx[2] "->" arr[idx[1], idx[2]] } }
class Program { static void Main(string[] args) { Console.WriteLine("Enter two integers. Space delimited please: "); string s = Console.ReadLine(); int[,] myArray=new int[(int)s[0],(int)s[2]]; myArray[0, 0] = 2; Console.WriteLi...
Convert this AWK block to C++, preserving its control flow and logic.
/[0-9]+ [0-9]+/ { for(i=0; i < $1; i++) { for(j=0; j < $2; j++) { arr[i, j] = i*j } } for (comb in arr) { split(comb, idx, SUBSEP) print idx[1] "," idx[2] "->" arr[idx[1], idx[2]] } }
#include <iostream> int main() { int dim1, dim2; std::cin >> dim1 >> dim2; double* array_data = new double[dim1*dim2]; double** array = new double*[dim1]; for (int i = 0; i < dim1; ++i) array[i] = array_data + dim2*i; array[0][0] = 3.5; std::cout << array[0][0] << std::endl; dele...
Generate a Java translation of this AWK snippet without changing its computational steps.
/[0-9]+ [0-9]+/ { for(i=0; i < $1; i++) { for(j=0; j < $2; j++) { arr[i, j] = i*j } } for (comb in arr) { split(comb, idx, SUBSEP) print idx[1] "," idx[2] "->" arr[idx[1], idx[2]] } }
import java.util.Scanner; public class twoDimArray { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nbr1 = in.nextInt(); int nbr2 = in.nextInt(); double[][] array = new double[nbr1][nbr2]; array[0][0] = 42.0; System....
Produce a functionally identical Python code for the snippet given in AWK.
/[0-9]+ [0-9]+/ { for(i=0; i < $1; i++) { for(j=0; j < $2; j++) { arr[i, j] = i*j } } for (comb in arr) { split(comb, idx, SUBSEP) print idx[1] "," idx[2] "->" arr[idx[1], idx[2]] } }
width = int(raw_input("Width of myarray: ")) height = int(raw_input("Height of Array: ")) myarray = [[0] * width for i in range(height)] myarray[0][0] = 3.5 print (myarray[0][0])
Change the following AWK code into VB without altering its purpose.
/[0-9]+ [0-9]+/ { for(i=0; i < $1; i++) { for(j=0; j < $2; j++) { arr[i, j] = i*j } } for (comb in arr) { split(comb, idx, SUBSEP) print idx[1] "," idx[2] "->" arr[idx[1], idx[2]] } }
Module Program Sub Main() Console.WriteLine("Enter two space-delimited integers:") Dim input = Console.ReadLine().Split() Dim rows = Integer.Parse(input(0)) Dim cols = Integer.Parse(input(1)) Dim arr(rows - 1, cols - 1) As Integer arr(0, 0) = 2 Cons...
Preserve the algorithm and functionality while converting the code from AWK to Go.
/[0-9]+ [0-9]+/ { for(i=0; i < $1; i++) { for(j=0; j < $2; j++) { arr[i, j] = i*j } } for (comb in arr) { split(comb, idx, SUBSEP) print idx[1] "," idx[2] "->" arr[idx[1], idx[2]] } }
package main import "fmt" func main() { var row, col int fmt.Print("enter rows cols: ") fmt.Scan(&row, &col) a := make([][]int, row) for i := range a { a[i] = make([]int, col) } fmt.Println("a[0][0] =", a[0][0]) a[row-1][col-1] = 7 fmt.Printf("a[%d][...
Write the same algorithm in C as shown in this BBC_Basic implementation.
INPUT "Enter array dimensions separated by a comma: " a%, b% DIM array(a%, b%) array(1, 1) = PI PRINT array(1, 1)
#include <stdio.h> int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf("Enter two integers. Space delimited, please: "); scanf("%d %d",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][use...
Write the same code in C# as shown below in BBC_Basic.
INPUT "Enter array dimensions separated by a comma: " a%, b% DIM array(a%, b%) array(1, 1) = PI PRINT array(1, 1)
class Program { static void Main(string[] args) { Console.WriteLine("Enter two integers. Space delimited please: "); string s = Console.ReadLine(); int[,] myArray=new int[(int)s[0],(int)s[2]]; myArray[0, 0] = 2; Console.WriteLi...
Please provide an equivalent version of this BBC_Basic code in C++.
INPUT "Enter array dimensions separated by a comma: " a%, b% DIM array(a%, b%) array(1, 1) = PI PRINT array(1, 1)
#include <iostream> int main() { int dim1, dim2; std::cin >> dim1 >> dim2; double* array_data = new double[dim1*dim2]; double** array = new double*[dim1]; for (int i = 0; i < dim1; ++i) array[i] = array_data + dim2*i; array[0][0] = 3.5; std::cout << array[0][0] << std::endl; dele...
Generate a Java translation of this BBC_Basic snippet without changing its computational steps.
INPUT "Enter array dimensions separated by a comma: " a%, b% DIM array(a%, b%) array(1, 1) = PI PRINT array(1, 1)
import java.util.Scanner; public class twoDimArray { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nbr1 = in.nextInt(); int nbr2 = in.nextInt(); double[][] array = new double[nbr1][nbr2]; array[0][0] = 42.0; System....
Preserve the algorithm and functionality while converting the code from BBC_Basic to Python.
INPUT "Enter array dimensions separated by a comma: " a%, b% DIM array(a%, b%) array(1, 1) = PI PRINT array(1, 1)
width = int(raw_input("Width of myarray: ")) height = int(raw_input("Height of Array: ")) myarray = [[0] * width for i in range(height)] myarray[0][0] = 3.5 print (myarray[0][0])
Write the same algorithm in VB as shown in this BBC_Basic implementation.
INPUT "Enter array dimensions separated by a comma: " a%, b% DIM array(a%, b%) array(1, 1) = PI PRINT array(1, 1)
Module Program Sub Main() Console.WriteLine("Enter two space-delimited integers:") Dim input = Console.ReadLine().Split() Dim rows = Integer.Parse(input(0)) Dim cols = Integer.Parse(input(1)) Dim arr(rows - 1, cols - 1) As Integer arr(0, 0) = 2 Cons...
Convert this BBC_Basic block to Go, preserving its control flow and logic.
INPUT "Enter array dimensions separated by a comma: " a%, b% DIM array(a%, b%) array(1, 1) = PI PRINT array(1, 1)
package main import "fmt" func main() { var row, col int fmt.Print("enter rows cols: ") fmt.Scan(&row, &col) a := make([][]int, row) for i := range a { a[i] = make([]int, col) } fmt.Println("a[0][0] =", a[0][0]) a[row-1][col-1] = 7 fmt.Printf("a[%d][...
Convert this Clojure block to C, preserving its control flow and logic.
(let [rows (Integer/parseInt (read-line)) cols (Integer/parseInt (read-line)) a (to-array-2d (repeat rows (repeat cols nil)))] (aset a 0 0 12) (println "Element at 0,0:" (aget a 0 0)))
#include <stdio.h> int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf("Enter two integers. Space delimited, please: "); scanf("%d %d",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][use...
Port the provided Clojure code into C# while preserving the original functionality.
(let [rows (Integer/parseInt (read-line)) cols (Integer/parseInt (read-line)) a (to-array-2d (repeat rows (repeat cols nil)))] (aset a 0 0 12) (println "Element at 0,0:" (aget a 0 0)))
class Program { static void Main(string[] args) { Console.WriteLine("Enter two integers. Space delimited please: "); string s = Console.ReadLine(); int[,] myArray=new int[(int)s[0],(int)s[2]]; myArray[0, 0] = 2; Console.WriteLi...
Please provide an equivalent version of this Clojure code in C++.
(let [rows (Integer/parseInt (read-line)) cols (Integer/parseInt (read-line)) a (to-array-2d (repeat rows (repeat cols nil)))] (aset a 0 0 12) (println "Element at 0,0:" (aget a 0 0)))
#include <iostream> int main() { int dim1, dim2; std::cin >> dim1 >> dim2; double* array_data = new double[dim1*dim2]; double** array = new double*[dim1]; for (int i = 0; i < dim1; ++i) array[i] = array_data + dim2*i; array[0][0] = 3.5; std::cout << array[0][0] << std::endl; dele...
Translate this program into Java but keep the logic exactly as in Clojure.
(let [rows (Integer/parseInt (read-line)) cols (Integer/parseInt (read-line)) a (to-array-2d (repeat rows (repeat cols nil)))] (aset a 0 0 12) (println "Element at 0,0:" (aget a 0 0)))
import java.util.Scanner; public class twoDimArray { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nbr1 = in.nextInt(); int nbr2 = in.nextInt(); double[][] array = new double[nbr1][nbr2]; array[0][0] = 42.0; System....
Convert this Clojure block to Python, preserving its control flow and logic.
(let [rows (Integer/parseInt (read-line)) cols (Integer/parseInt (read-line)) a (to-array-2d (repeat rows (repeat cols nil)))] (aset a 0 0 12) (println "Element at 0,0:" (aget a 0 0)))
width = int(raw_input("Width of myarray: ")) height = int(raw_input("Height of Array: ")) myarray = [[0] * width for i in range(height)] myarray[0][0] = 3.5 print (myarray[0][0])