Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Maintain the same structure and functionality when rewriting this code in VB.
write.csv(df, file = "foo.csv",row.names = FALSE)
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 R to VB, same semantics.
write.csv(df, file = "foo.csv",row.names = FALSE)
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 Go.
write.csv(df, file = "foo.csv",row.names = FALSE)
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...
Change the following R code into Go without altering its purpose.
write.csv(df, file = "foo.csv",row.names = FALSE)
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 Racket snippet without changing its computational steps.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
#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 Racket code snippet into C without altering its behavior.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
#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 code in C# as shown below in Racket.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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 provided Racket code into C# while preserving the original functionality.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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...
Preserve the algorithm and functionality while converting the code from Racket to C++.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
#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 C++ code for the snippet given in Racket.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
#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 Java.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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 Racket snippet to Python and keep its semantics consistent.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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...
Maintain the same structure and functionality when rewriting this code in Python.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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 provided Racket code into VB while preserving the original functionality.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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 Go but keep the logic exactly as in Racket.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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 Racket snippet to Go and keep its semantics consistent.
#lang racket (require (planet neil/csv:1:=7) net/url) (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t)))) (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row) '...
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...
Ensure the translated C code behaves exactly like the original COBOL snippet.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
#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) {...
Maintain the same structure and functionality when rewriting this code in C.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
#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 COBOL code in C#.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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 a C# translation of this COBOL snippet without changing its computational steps.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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...
Preserve the algorithm and functionality while converting the code from COBOL to C++.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
#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 following COBOL code into C++ without altering its purpose.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
#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 = ',' ) ...
Rewrite the snippet below in Java so it works the same as the original COBOL code.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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 programming language of this snippet from COBOL to Java without modifying what it does.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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 programming language of this snippet from COBOL to Python without modifying what it does.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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...
Produce a language-to-language conversion: from COBOL to Python, same semantics.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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 COBOL.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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 COBOL to VB, same semantics.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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
Convert this COBOL block to Go, preserving its control flow and logic.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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...
Change the programming language of this snippet from COBOL to Go without modifying what it does.
IDENTIFICATION DIVISION. PROGRAM-ID. CSV. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 19 December 2021. ************************************************************ ** Program Abstract: ** CSVs are something COBOL does pretty well. ** Th...
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...
Write the same algorithm in C as shown in this REXX implementation.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
#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 REXX code.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
#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 REXX snippet without changing its computational steps.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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...
Change the programming language of this snippet from REXX to C# without modifying what it does.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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 provided REXX code into C++ while preserving the original functionality.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
#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 REXX snippet to C++ and keep its semantics consistent.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
#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 the given REXX code snippet into Java without altering its behavior.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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 the snippet below in Java so it works the same as the original REXX code.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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 this program into Python but keep the logic exactly as in REXX.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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 REXX function in Python with identical behavior.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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 VB translation of this REXX snippet without changing its computational steps.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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 REXX.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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 REXX.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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...
Rewrite the snippet below in Go so it works the same as the original REXX code.
options replace format comments java crossref symbols import org.apache.commons.csv. -- ============================================================================= class RCsv public final properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = String 'SUM, "intege...
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...
Ensure the translated C code behaves exactly like the original Ruby snippet.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
#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) {...
Keep all operations the same but rewrite the snippet in C.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
#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 the snippet below in C# so it works the same as the original Ruby code.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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 Ruby snippet to C# and keep its semantics consistent.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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...
Write the same code in C++ as shown below in Ruby.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
#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 Ruby implementation into C++, maintaining the same output and logic.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
#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 = ',' ) ...
Ensure the translated Java code behaves exactly like the original Ruby snippet.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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 Ruby code into Java while preserving the original functionality.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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 Ruby block to Python, preserving its control flow and logic.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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 programming language of this snippet from Ruby to Python without modifying what it does.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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 Ruby.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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
Convert this Ruby block to Go, preserving its control flow and logic.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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 the following code from Ruby to Go, ensuring the logic remains intact.
require 'csv' ar = CSV.table("test.csv").to_a ar.first << "SUM" ar[1..-1].each{|row| row << row.sum} CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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...
Write the same code in C as shown below in Scala.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
#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 following Scala code into C without altering its purpose.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
#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 Scala to C# without modifying what it does.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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...
Write the same code in C# as shown below in Scala.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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 Scala to C++ with equivalent syntax and logic.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
#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 Scala code.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
#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 Java.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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 Scala code into Java while preserving the original functionality.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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...
Ensure the translated Python code behaves exactly like the original Scala snippet.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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 Scala code snippet into Python without altering its behavior.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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 Scala function in VB with identical behavior.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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
Change the programming language of this snippet from Scala to VB without modifying what it does.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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
Convert this Scala snippet to Go and keep its semantics consistent.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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 the following code from Scala to Go, ensuring the logic remains intact.
import java.io.File fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("example2.csv").writ...
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 Tcl implementation into C, maintaining the same output and logic.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
#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 following Tcl code into C without altering its purpose.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
#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) {...
Keep all operations the same but rewrite the snippet in C#.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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...
Keep all operations the same but rewrite the snippet in C#.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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++.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
#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 Tcl to C++ without modifying what it does.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
#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 = ',' ) ...
Please provide an equivalent version of this Tcl code in Java.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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 a Java translation of this Tcl snippet without changing its computational steps.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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 Tcl code snippet into Python without altering its behavior.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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...
Produce a functionally identical Python code for the snippet given in Tcl.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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 this Tcl snippet to VB and keep its semantics consistent.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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
Please provide an equivalent version of this Tcl code in VB.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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 Tcl code snippet into Go without altering its behavior.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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...
Write the same code in Go as shown below in Tcl.
package require struct::matrix package require csv proc addSumColumn {filename {title "SUM"}} { set m [struct::matrix] set f [open $filename] csv::read2matrix $f $m "," auto close $f set sumcol [$m columns] $m add column $title for {set i 1} {$i < [$m rows]} {incr i} { $m set...
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 an equivalent PHP version of this Rust code.
use std::error::Error; use std::num::ParseIntError; use csv::{Reader, Writer}; fn main() -> Result<(), Box<dyn Error>> { let mut reader = Reader::from_path("data.csv")?; let mut writer = Writer::from_path("output.csv")?; let mut headers = reader.headers()?.clone(); headers.push_field("SUM"); ...
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Ensure the translated PHP code behaves exactly like the original Rust snippet.
use std::error::Error; use std::num::ParseIntError; use csv::{Reader, Writer}; fn main() -> Result<(), Box<dyn Error>> { let mut reader = Reader::from_path("data.csv")?; let mut writer = Writer::from_path("output.csv")?; let mut headers = reader.headers()?.clone(); headers.push_field("SUM"); ...
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Ensure the translated PHP code behaves exactly like the original Ada snippet.
package CSV is type Row(<>) is tagged private; function Line(S: String; Separator: Character := ',') return Row; function Next(R: in out Row) return Boolean; function Item(R: Row) return String; private type Row(Length: Natural) is tagged record Str: String(1 .. Length); ...
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Port the following code from Ada to PHP with equivalent syntax and logic.
package CSV is type Row(<>) is tagged private; function Line(S: String; Separator: Character := ',') return Row; function Next(R: in out Row) return Boolean; function Item(R: Row) return String; private type Row(Length: Natural) is tagged record Str: String(1 .. Length); ...
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Port the provided Arturo code into PHP while preserving the original functionality.
table: read.csv "data.csv" data: [] loop table 'row [ addable: ["SUM"] if row <> first table -> addable: @[to :string sum map row 'x [to :integer x]] 'data ++ @[row ++ addable] ] loop data 'row [ loop row 'column -> prints pad column 6 print "" ]
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Write the same algorithm in PHP as shown in this Arturo implementation.
table: read.csv "data.csv" data: [] loop table 'row [ addable: ["SUM"] if row <> first table -> addable: @[to :string sum map row 'x [to :integer x]] 'data ++ @[row ++ addable] ] loop data 'row [ loop row 'column -> prints pad column 6 print "" ]
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Rewrite the snippet below in PHP so it works the same as the original AutoHotKey code.
Loop, Read, Data.csv { i := A_Index Loop, Parse, A_LoopReadLine, CSV Output .= (i=A_Index && i!=1 ? A_LoopField**2 : A_LoopField) (A_Index=5 ? "`n" : ",") } FileAppend, %Output%, NewData.csv
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Change the following AutoHotKey code into PHP without altering its purpose.
Loop, Read, Data.csv { i := A_Index Loop, Parse, A_LoopReadLine, CSV Output .= (i=A_Index && i!=1 ? A_LoopField**2 : A_LoopField) (A_Index=5 ? "`n" : ",") } FileAppend, %Output%, NewData.csv
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Keep all operations the same but rewrite the snippet in PHP.
BEGIN { FS = OFS = "," } NR==1 { print $0, "SUM" next } { sum = 0 for (i=1; i<=NF; i++) { sum += $i } print $0, sum }
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Generate an equivalent PHP version of this AWK code.
BEGIN { FS = OFS = "," } NR==1 { print $0, "SUM" next } { sum = 0 for (i=1; i<=NF; i++) { sum += $i } print $0, sum }
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Generate a PHP translation of this Clojure snippet without changing its computational steps.
(require '[clojure.data.csv :as csv] '[clojure.java.io :as io]) (defn add-sum-column [coll] (let [titles (first coll) values (rest coll)] (cons (conj titles "SUM") (map #(conj % (reduce + (map read-string %))) values)))) (with-open [in-file (io/reader "test_in.csv")] (doall (let [...
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...
Rewrite the snippet below in PHP so it works the same as the original Clojure code.
(require '[clojure.data.csv :as csv] '[clojure.java.io :as io]) (defn add-sum-column [coll] (let [titles (first coll) values (rest coll)] (cons (conj titles "SUM") (map #(conj % (reduce + (map read-string %))) values)))) (with-open [in-file (io/reader "test_in.csv")] (doall (let [...
<?php $handle = fopen('data_in.csv','r'); $handle_output = fopen('data_out.csv','w'); $row = 0; $arr = array(); while ($line = fgetcsv($handle)) { $arr[] = $line; } $arr[1][0] = 0; // 1,5,9,13,17 => 0,5,9,13,17 $arr[2][1] = 0; // 2,6,10,14,18 => 2,0,10,14,18 foreach ($arr as $line) { if ($row==0) ...