Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Translate the given Common_Lisp code snippet into C without altering its behavior.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Please provide an equivalent version of this Common_Lisp code in C.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Produce a functionally identical C# code for the snippet given in Common_Lisp.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Rewrite the snippet below in C++ so it works the same as the original Common_Lisp code.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Write the same algorithm in C++ as shown in this Common_Lisp implementation.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Change the programming language of this snippet from Common_Lisp to Java without modifying what it does.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Produce a functionally identical Java code for the snippet given in Common_Lisp.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Convert this Common_Lisp block to Python, preserving its control flow and logic.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Preserve the algorithm and functionality while converting the code from Common_Lisp to Python.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Translate the given Common_Lisp code snippet into VB without altering its behavior.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Translate the given Common_Lisp code snippet into VB without altering its behavior.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Write the same code in Go as shown below in Common_Lisp.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Translate this program into Go but keep the logic exactly as in Common_Lisp.
(defun csvfile-to-nested-list (filename delim-char) "Reads the csv to a nested list, where each sublist represents a line." (with-open-file (input filename) (loop :for line := (read-line input nil) :while line :collect (read-from-string (substitute #\SPACE delim-char ...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Produce a language-to-language conversion: from D to C, same semantics.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Please provide an equivalent version of this D code in C.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Generate a C# translation of this D snippet without changing its computational steps.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Produce a functionally identical C# code for the snippet given in D.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Can you help me rewrite this code in C++ instead of D, keeping it the same logically?
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Transform the following D implementation into C++, maintaining the same output and logic.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Translate this program into Java but keep the logic exactly as in D.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Port the provided D code into Java while preserving the original functionality.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Generate an equivalent Python version of this D code.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Preserve the algorithm and functionality while converting the code from D to Python.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Keep all operations the same but rewrite the snippet in VB.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Maintain the same structure and functionality when rewriting this code in VB.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Port the following code from D to Go with equivalent syntax and logic.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Produce a language-to-language conversion: from D to Go, same semantics.
void main() { import std.stdio, std.csv, std.file, std.typecons, std.array, std.algorithm, std.conv, std.range; auto rows = "csv_data_in.csv".File.byLine; auto fout = "csv_data_out.csv".File("w"); fout.writeln(rows.front); fout.writef("%(%(%d,%)\n%)", rows.dropOne .map!(r...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Port the following code from Delphi to C with equivalent syntax and logic.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Rewrite this program in C while keeping its functionality equivalent to the Delphi version.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Translate the given Delphi code snippet into C# without altering its behavior.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Generate an equivalent C# version of this Delphi code.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Generate an equivalent C++ version of this Delphi code.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Preserve the algorithm and functionality while converting the code from Delphi to C++.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Produce a language-to-language conversion: from Delphi to Java, same semantics.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Produce a language-to-language conversion: from Delphi to Java, same semantics.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Keep all operations the same but rewrite the snippet in Python.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Preserve the algorithm and functionality while converting the code from Delphi to Python.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Preserve the algorithm and functionality while converting the code from Delphi to VB.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Translate the given Delphi code snippet into VB without altering its behavior.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Transform the following Delphi implementation into Go, maintaining the same output and logic.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Please provide an equivalent version of this Delphi code in Go.
program CSV_data_manipulation; uses System.SysUtils, System.IoUtils, System.Types; type TStringDynArrayHelper = record helper for TStringDynArray function Sum: Integer; end; function TStringDynArrayHelper.Sum: Integer; var value: string; begin Result := 0; for value in self do Result := R...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Convert this Elixir block to C, preserving its control flow and logic.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Convert the following code from Elixir to C, ensuring the logic remains intact.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Write a version of this Elixir function in C# with identical behavior.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Transform the following Elixir implementation into C#, maintaining the same output and logic.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Maintain the same structure and functionality when rewriting this code in C++.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Maintain the same structure and functionality when rewriting this code in C++.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Write the same code in Java as shown below in Elixir.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Translate the given Elixir code snippet into Java without altering its behavior.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Can you help me rewrite this code in Python instead of Elixir, keeping it the same logically?
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Translate this program into VB but keep the logic exactly as in Elixir.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Generate a VB translation of this Elixir snippet without changing its computational steps.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Generate a Go translation of this Elixir snippet without changing its computational steps.
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Can you help me rewrite this code in Go instead of Elixir, keeping it the same logically?
defmodule Csv do defstruct header: "", data: "", separator: "," def from_file(path) do [header | data] = path |> File.stream! |> Enum.to_list |> Enum.map(&String.trim/1) %Csv{ header: header, data: data } end def sums_of_rows(csv) do Enum.map(csv.data, fn (row) -> sum_of_row(row, csv....
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Generate a C translation of this Erlang snippet without changing its computational steps.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Can you help me rewrite this code in C instead of Erlang, keeping it the same logically?
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Change the programming language of this snippet from Erlang to C# without modifying what it does.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Convert this Erlang snippet to C# and keep its semantics consistent.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Can you help me rewrite this code in C++ instead of Erlang, keeping it the same logically?
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Write the same code in C++ as shown below in Erlang.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Produce a functionally identical Java code for the snippet given in Erlang.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Rewrite this program in Java while keeping its functionality equivalent to the Erlang version.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Write the same code in Python as shown below in Erlang.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Generate a Python translation of this Erlang snippet without changing its computational steps.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Write a version of this Erlang function in VB with identical behavior.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Translate this program into VB but keep the logic exactly as in Erlang.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Write the same code in Go as shown below in Erlang.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Port the following code from Erlang to Go with equivalent syntax and logic.
-module( csv_data ). -export( [change/2, from_binary/1, from_file/1, into_file/2, task/0] ). change( CSV, Changes ) -> lists:foldl( fun change_foldl/2, CSV, Changes ). from_binary( Binary ) -> Lines = binary:split( Binary, <<"\n">>, [global] ), [binary:split(X, <<",">>, [global]) || X <- Lines]. fro...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Transform the following F# implementation into C, maintaining the same output and logic.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Generate an equivalent C version of this F# code.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Preserve the algorithm and functionality while converting the code from F# to C#.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Produce a functionally identical C# code for the snippet given in F#.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Translate the given F# code snippet into C++ without altering its behavior.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Convert this F# snippet to C++ and keep its semantics consistent.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Port the following code from F# to Java with equivalent syntax and logic.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Keep all operations the same but rewrite the snippet in Java.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Convert this F# block to Python, preserving its control flow and logic.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Change the following F# code into Python without altering its purpose.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Ensure the translated VB code behaves exactly like the original F# snippet.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Produce a functionally identical VB code for the snippet given in F#.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Generate an equivalent Go version of this F# code.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Produce a functionally identical Go code for the snippet given in F#.
open System.IO [<EntryPoint>] let main _ = let input = File.ReadAllLines "test_in.csv" let output = input |> Array.mapi (fun i line -> if i = 0 then line + ",SUM" else let sum = Array.sumBy int (line.Split(',')) sprintf "%s,%i" line sum...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Convert this Factor snippet to C and keep its semantics consistent.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Port the following code from Factor to C with equivalent syntax and logic.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Produce a language-to-language conversion: from Factor to C#, same semantics.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Port the following code from Factor to C# with equivalent syntax and logic.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Rewrite this program in C++ while keeping its functionality equivalent to the Factor version.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Generate an equivalent C++ version of this Factor code.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
#include <map> #include <vector> #include <iostream> #include <fstream> #include <utility> #include <functional> #include <string> #include <sstream> #include <algorithm> #include <cctype> class CSV { public: CSV(void) : m_nCols( 0 ), m_nRows( 0 ) {} bool open( const char* filename, char delim = ',' ) ...
Generate an equivalent Java version of this Factor code.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Change the following Factor code into Java without altering its purpose.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
Write the same code in Python as shown below in Factor.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Convert the following code from Factor to Python, ensuring the logic remains intact.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
import fileinput changerow, changecolumn, changevalue = 2, 4, '"Spam"' with fileinput.input('csv_data_manipulation.csv', inplace=True) as f: for line in f: if fileinput.filelineno() == changerow: fields = line.rstrip().split(',') fields[changecolumn-1] = changevalue lin...
Ensure the translated VB code behaves exactly like the original Factor snippet.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Produce a language-to-language conversion: from Factor to VB, same semantics.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
Sub ReadCSV() Workbooks.Open Filename:="L:\a\input.csv" Range("F1").Value = "Sum" Range("F2:F5").Formula = "=SUM(A2:E2)" ActiveWorkbook.SaveAs Filename:="L:\a\output.csv", FileFormat:=xlCSV ActiveWindow.Close End Sub
Preserve the algorithm and functionality while converting the code from Factor to Go.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Translate the given Factor code snippet into Go without altering its behavior.
USING: csv io.encodings.utf8 kernel math.parser sequences ; IN: rosetta-code.csv-manipulation : append-sum ( seq -- seq' ) dup [ string>number ] map-sum number>string suffix ; : csv-sums ( seq -- seq' ) [ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ; "example.csv" utf8 [ file>csv csv-sums ] [ csv>file...
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
Convert this Forth block to C, preserving its control flow and logic.
CHAR , CONSTANT SEPARATOR 3 CONSTANT DECIMALS 1E1 DECIMALS S>D D>F F** FCONSTANT FSCALE : colsum 0E0 OVER SWAP BOUNDS ?DO I C@ SEPARATOR = IF I TUCK OVER - >FLOAT IF F+ THEN ...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Write the same algorithm in C as shown in this Forth implementation.
CHAR , CONSTANT SEPARATOR 3 CONSTANT DECIMALS 1E1 DECIMALS S>D D>F F** FCONSTANT FSCALE : colsum 0E0 OVER SWAP BOUNDS ?DO I C@ SEPARATOR = IF I TUCK OVER - >FLOAT IF F+ THEN ...
#define TITLE "CSV data manipulation" #define URL "http: #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) {...
Convert this Forth snippet to C# and keep its semantics consistent.
CHAR , CONSTANT SEPARATOR 3 CONSTANT DECIMALS 1E1 DECIMALS S>D D>F F** FCONSTANT FSCALE : colsum 0E0 OVER SWAP BOUNDS ?DO I C@ SEPARATOR = IF I TUCK OVER - >FLOAT IF F+ THEN ...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...
Maintain the same structure and functionality when rewriting this code in C#.
CHAR , CONSTANT SEPARATOR 3 CONSTANT DECIMALS 1E1 DECIMALS S>D D>F F** FCONSTANT FSCALE : colsum 0E0 OVER SWAP BOUNDS ?DO I C@ SEPARATOR = IF I TUCK OVER - >FLOAT IF F+ THEN ...
using System.IO; using System.Linq; namespace CSV_data_manipulation { class Program { static void Main() { var input = File.ReadAllLines("test_in.csv"); var output = input.Select((line, i) => { if (i == 0) return line + ",S...